Ship native /social/work: Planka-shaped boards + Etherpad pads on FastAPI.
Secondary-dev Next UI with DnD, labels, stopwatch, archive, activity; pads with revisions; README documents pnpm dev:work-api. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
4389ebe6cb
commit
2b574f7957
@ -6,10 +6,12 @@ alwaysApply: true
|
|||||||
# 模块化与解耦
|
# 模块化与解耦
|
||||||
|
|
||||||
- **门户业务**:垂直前端进 `src/modules/<name>`,路由在 `src/app/<route>`;禁止把业务堆进 `src/components/` 壳层。
|
- **门户业务**:垂直前端进 `src/modules/<name>`,路由在 `src/app/<route>`;禁止把业务堆进 `src/components/` 壳层。
|
||||||
- **端形态**:小程序 / 管理 SPA / API 进 `apps/{miniprogram,admin,api}`;共享进 `packages/*`。
|
- **受众横切**:中文 / 国际进 `src/modules/audience/{cn,intl}`(支付·登录·关注·文案·VIP·埋点·社群等);见 `audience-cn-intl.mdc`。禁止页面散落 `if (isChina)`。
|
||||||
|
- **端形态**:小程序 / 管理 SPA / API 进 `apps/{miniprogram,admin,api}`;**.com(美国 VPS)进 `apps/com/*`,与 `.cn` 源码隔离**;共享进 `packages/*`。
|
||||||
|
- **远程工作**:门户壳 `src/modules/work`;Planka / Etherpad 上游与 overlay 在 `apps/work`(二次开发写 overlay,勿把整个 upstream 硬塞进主仓)。
|
||||||
- **稳定公共面**:`@nomadro/pay`、`@nomadro/pb`、`@nomadro/sdk` 经显式导出;模块之间禁止深路径互相 import。
|
- **稳定公共面**:`@nomadro/pay`、`@nomadro/pb`、`@nomadro/sdk` 经显式导出;模块之间禁止深路径互相 import。
|
||||||
- **依赖方向**:`packages` ← `apps` / `src/modules` ← 门户路由;下层不依赖上层。
|
- **依赖方向**:`packages` ← `apps` / `src/modules` ← 门户路由;下层不依赖上层;**`apps/com` 禁止依赖 `apps/admin` / 小程序源码**。
|
||||||
- **新增业务清单**:`src/modules/<name>` + 可选 `apps/api` 路由前缀 + 门户挂载路径(如 `/xxx`)+ 内容进 `src/modules/*-content`;不改无关模块。
|
- **新增业务清单**:`src/modules/<name>` + 可选 `apps/api` 路由前缀 + 门户挂载路径(如 `/xxx`)+ 内容进 `src/modules/*-content`;不改无关模块。**.com Web 能力进 `apps/com`,勿塞进微信/抖音后台。**
|
||||||
- **接口优先**:模块对外用 HTTP/OpenAPI 或清晰 TS 类型;配置与密钥走 env。
|
- **接口优先**:模块对外用 HTTP/OpenAPI 或清晰 TS 类型;配置与密钥走 env。
|
||||||
- **可替换**:支付/存储/分析经 provider 接入(见 `@nomadro/pay.resolvePayProvider`)。
|
- **可替换**:支付/存储/分析经 provider 接入(见 `@nomadro/pay.resolvePayProvider`)。
|
||||||
- **统一编排**:跨垂直入口集中在 `/admin` 与 `apps/admin`;后台壳不承载垂直页面实现。
|
- **统一编排**:`.cn` 跨垂直入口在 `/admin` 与 `apps/admin`;`.com` 在 `apps/com/admin`(`admin.nomadro.com`);后台壳不承载垂直页面实现。
|
||||||
|
|||||||
@ -22,7 +22,8 @@ alwaysApply: true
|
|||||||
| 内容 | `src/modules/ebook-content` 等 | 包内离线种子 |
|
| 内容 | `src/modules/ebook-content` 等 | 包内离线种子 |
|
||||||
| 小程序 | `apps/miniprogram/{h5,weapp,tt,xhs}` | Taro;H5 为 SoT,weapp 共用 `h5/src` |
|
| 小程序 | `apps/miniprogram/{h5,weapp,tt,xhs}` | Taro;H5 为 SoT,weapp 共用 `h5/src` |
|
||||||
| API | `apps/api` | 统一 FastAPI(ebook + community + pay) |
|
| API | `apps/api` | 统一 FastAPI(ebook + community + pay) |
|
||||||
| 管理后台 | `apps/admin` | admin.nomadro.cn(Vite SPA) |
|
| 管理后台 .cn | `apps/admin` | admin.nomadro.cn(微信 / 抖音) |
|
||||||
|
| 管理后台 .com | `apps/com/admin` | admin.nomadro.com(美国 VPS · 仅 Web · 无小程序) |
|
||||||
| 共享包 | `packages/{pay,pb,sdk}` | 显式导出 |
|
| 共享包 | `packages/{pay,pb,sdk}` | 显式导出 |
|
||||||
|
|
||||||
禁止再引入已删除垂直树:`apps/ebook` `navmini` `nomadweb` `nomadvip` `wemini` `payjsapi` `community-api`。
|
禁止再引入已删除垂直树:`apps/ebook` `navmini` `nomadweb` `nomadvip` `wemini` `payjsapi` `community-api`。
|
||||||
@ -38,13 +39,14 @@ alwaysApply: true
|
|||||||
## 仓库与账号
|
## 仓库与账号
|
||||||
|
|
||||||
- Git:https://git.nomadro.cn (管理员 `hackrobot` / `Xiao4669805@`)
|
- Git:https://git.nomadro.cn (管理员 `hackrobot` / `Xiao4669805@`)
|
||||||
- 主域 `nomadro.cn`;二级 DNS 在 Cloudflare(含 `vip` `api` `admin` `pocketbase` `umami` 等)
|
- **开发主域 `nomadro.com`(美国 VPS)**;`.cn` 为中国独立站(测稳后同步)
|
||||||
- 生产机:`82.157.112.245`,`ubuntu` / `Xiao4669805`
|
- `.cn` 机:`82.157.112.245`,`ubuntu` / `Xiao4669805`;二级 DNS 在 Cloudflare
|
||||||
|
- 发版默认目标与双站关系见 `com-first-deploy.mdc`
|
||||||
|
|
||||||
## 开发流程(强制)
|
## 开发流程(强制)
|
||||||
|
|
||||||
1. Windows 本地改 → `pnpm dev` / 对应后端启动 → 自测 OK
|
1. Windows 本地改 → `pnpm dev` / 对应后端启动 → 自测 OK
|
||||||
2. 再部署线上 → 线上冒烟 OK
|
2. **默认部署 `.com`(美国机)** → 冒烟 OK;`.cn` 仅明确要求或中文轨同步时再发
|
||||||
3. 最后更新 README
|
3. 最后更新 README
|
||||||
|
|
||||||
模块化见 `modular-design.mdc`:门户业务在 `src/modules/`,端形态进 `apps/`,共享进 `packages/`。
|
模块化见 `modular-design.mdc`:门户业务在 `src/modules/`,端形态进 `apps/`,共享进 `packages/`。
|
||||||
|
|||||||
19
.env.example
19
.env.example
@ -1,5 +1,8 @@
|
|||||||
# Copy to .env.local — never commit real secrets
|
# Copy to .env.local — never commit real secrets
|
||||||
|
|
||||||
|
# Remote work API (Next proxies /api/work/v1 → this)
|
||||||
|
# WORK_API_URL=http://127.0.0.1:8021
|
||||||
|
|
||||||
# Admin panel
|
# Admin panel
|
||||||
NOMADRO_ADMIN_PASSWORD=change-me
|
NOMADRO_ADMIN_PASSWORD=change-me
|
||||||
NOMADRO_ADMIN_SESSION_SECRET=change-me-session
|
NOMADRO_ADMIN_SESSION_SECRET=change-me-session
|
||||||
@ -16,13 +19,27 @@ WX_LIVE_APPKEY=CBi5tdkkSWuvkDvWJNnSjrGmeYE3xlsg
|
|||||||
WX_PAY_ENV=1
|
WX_PAY_ENV=1
|
||||||
|
|
||||||
# Observability (production)
|
# Observability (production)
|
||||||
# NOMADRO_PUBLIC_ORIGIN=https://nomadro.cn
|
# NOMADRO_PUBLIC_ORIGIN=https://nomadro.com
|
||||||
|
# API_URL=https://api.nomadro.com
|
||||||
|
# 本地前端直连线上配置(浏览器 CORS;与 admin.nomadro.com 同源)
|
||||||
|
# NEXT_PUBLIC_REMOTE_CONFIG_URL=https://nomadro.com/api/config
|
||||||
# NEXT_PUBLIC_UMAMI_WEBSITE_ID=
|
# NEXT_PUBLIC_UMAMI_WEBSITE_ID=
|
||||||
# NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://umami.nomadro.cn/script.js
|
# NEXT_PUBLIC_UMAMI_SCRIPT_URL=https://umami.nomadro.cn/script.js
|
||||||
# NTFY_BASE_URL=https://ntfy.nomadro.cn
|
# NTFY_BASE_URL=https://ntfy.nomadro.cn
|
||||||
# NTFY_TOPIC=nomadro
|
# NTFY_TOPIC=nomadro
|
||||||
|
# Optional: .com 专用 topic(不设则用 NTFY_TOPIC)
|
||||||
|
# NTFY_TOPIC_COM=nomadro-com
|
||||||
# NTFY_TOKEN=
|
# NTFY_TOKEN=
|
||||||
|
|
||||||
# Overseas pay (payjsapi)
|
# Overseas pay (payjsapi)
|
||||||
# CREEM_API_KEY=
|
# CREEM_API_KEY=
|
||||||
# NOWPAYMENTS_API_KEY=
|
# NOWPAYMENTS_API_KEY=
|
||||||
|
|
||||||
|
# Social geo (MapLibre + Photon + PocketBase trips)
|
||||||
|
# NEXT_PUBLIC_MAP_STYLE_URL=https://tiles.openfreemap.org/styles/dark
|
||||||
|
# PHOTON_BASE_URL=https://photon.komoot.io
|
||||||
|
# SOCIAL_GEO_USE_PB=true
|
||||||
|
# SOCIAL_TRIPS_COLLECTION=social_trips
|
||||||
|
# PB_URL=http://127.0.0.1:8090
|
||||||
|
# PB_ADMIN_EMAIL=
|
||||||
|
# PB_ADMIN_PASSWORD=
|
||||||
|
|||||||
16
AGENTS.md
16
AGENTS.md
@ -1,21 +1,29 @@
|
|||||||
# Nomadro agent notes
|
# Nomadro agent notes
|
||||||
|
|
||||||
Follow `.cursor/rules/*.mdc`.
|
Follow `.cursor/rules/*.mdc`。
|
||||||
|
|
||||||
|
**发版核心:`nomadro.com`(美国机)**。`.com` 分中文/国际受众;中文轨测稳后再**独立同步** `.cn`(中国机)。未点名域名时默认部署 `.com`,见 `com-first-deploy.mdc`。链路:`.com` → `.cn`(Next) → Taro H5 → 微信/抖音/小红书(微信为中国核心)。
|
||||||
|
|
||||||
|
**对外标准面**:`/api/public/v1` + `@nomadro/sdk` + `@nomadro/mcp` + `.cursor/skills/nomadro-platform`(工具 SoT `packages/sdk/tools.json`)。文档 [`docs/public-api.md`](docs/public-api.md)。
|
||||||
|
|
||||||
| Layer | Path |
|
| Layer | Path |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Next portal | `src/app`(路由壳)+ `src/modules`(业务 SoT) |
|
| Next portal(.com 主 / .cn 同步) | `src/app` + `src/modules` |
|
||||||
|
| Remote work | 读 Planka/Etherpad 域模型后自研:Next `src/modules/work` + FastAPI `apps/api/services/work_svc`(`/api/work/v1`,`work_main.py :8021`)。禁止 iframe/二级域 |
|
||||||
| Taro H5 SoT | `apps/miniprogram/h5`(weapp 共用 `../h5/src`) |
|
| Taro H5 SoT | `apps/miniprogram/h5`(weapp 共用 `../h5/src`) |
|
||||||
| Unified API | `apps/api` |
|
| Unified API | `apps/api` |
|
||||||
| Admin SPA | `apps/admin` |
|
| Admin SPA (.cn) | `apps/admin` → `admin.nomadro.cn`(微信 / 抖音) |
|
||||||
|
| **.com 隔离树** | `apps/com/*`(美国 VPS · **无小程序**);`apps/com/admin` → `admin.nomadro.com` |
|
||||||
| Shared | `packages/{pay,pb,sdk}` |
|
| Shared | `packages/{pay,pb,sdk}` |
|
||||||
|
|
||||||
## Dev
|
## Dev
|
||||||
|
|
||||||
根目录:`pnpm install` → `pnpm dev` / `dev:h5` / `dev:admin` / `dev:api` / `typecheck` / `clean`。
|
根目录:`pnpm install` → `pnpm dev` / `dev:h5` / `dev:admin` / `dev:admin-com` / `dev:api` / `typecheck` / `clean`。
|
||||||
|
|
||||||
Remote config: `POST /api/config/pull` · `WS /api/config/ws` · offline defaults. Current WeChat audit branch/tag: `test9` / `2026-11-02`. Do not reintroduce deleted vertical trees (`payjsapi` / `community-api` / `ebook` / `navmini` / `nomadweb` / `nomadvip` / `wemini`).
|
Remote config: `POST /api/config/pull` · `WS /api/config/ws` · offline defaults. Current WeChat audit branch/tag: `test9` / `2026-11-02`. Do not reintroduce deleted vertical trees (`payjsapi` / `community-api` / `ebook` / `navmini` / `nomadweb` / `nomadvip` / `wemini`).
|
||||||
|
|
||||||
**全端小程序禁止 web-view**(微信 / 抖音 / 小红书 / H5 SoT):业务内容必须原生页;见 `.cursor/rules/no-webview-content.mdc`。
|
**全端小程序禁止 web-view**(微信 / 抖音 / 小红书 / H5 SoT):业务内容必须原生页;见 `.cursor/rules/no-webview-content.mdc`。
|
||||||
|
|
||||||
|
**受众模块**:`src/modules/audience/{cn,intl}` — 支付/登录/关注/文案/VIP/埋点/社群全模块化;`resolveAudienceBundle()`。后台登录后选 `/cn`|`/intl`。见 `audience-cn-intl.mdc`。
|
||||||
|
|
||||||
H5 游戏(Nomad Day 3D)冷冻:勿改 `apps/miniprogram/h5/src/modules/game` / `pages/game`,除非用户明确要求。
|
H5 游戏(Nomad Day 3D)冷冻:勿改 `apps/miniprogram/h5/src/modules/game` / `pages/game`,除非用户明确要求。
|
||||||
|
|||||||
38
README.md
38
README.md
@ -5,12 +5,14 @@
|
|||||||
## 架构
|
## 架构
|
||||||
|
|
||||||
```
|
```
|
||||||
src/ Next.js 门户(app 路由壳 + modules 业务)
|
src/ Next.js 门户 .cn(app 路由壳 + modules 业务)
|
||||||
apps/miniprogram/ Taro:h5 SoT · weapp · tt · xhs
|
apps/miniprogram/ Taro:h5 SoT · weapp · tt · xhs(仅 .cn 备案线)
|
||||||
apps/api/ 统一 FastAPI(ebook + community + pay + social)
|
apps/api/ 统一 FastAPI(ebook + community + pay + social + work)
|
||||||
apps/admin/ admin.nomadro.cn 管理 SPA(Vite)
|
apps/admin/ admin.nomadro.cn 管理 SPA(微信 / 抖音)
|
||||||
|
apps/com/ .com 源码隔离树(美国 VPS · 无小程序)→ admin.nomadro.com
|
||||||
|
apps/work/ 远程工作参考 upstream / overlay(Planka · Etherpad;产品 UI 不跑 iframe)
|
||||||
packages/ @nomadro/pay · pb · sdk
|
packages/ @nomadro/pay · pb · sdk
|
||||||
data/ 远程配置等运行时数据(含 social.db 独立库)
|
data/ 远程配置等运行时数据(含 social.db · work.sqlite3)
|
||||||
scripts/ 本地开发 / 清理(dev-api · clean-artifacts)
|
scripts/ 本地开发 / 清理(dev-api · clean-artifacts)
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -20,11 +22,13 @@ scripts/ 本地开发 / 清理(dev-api · clean-artifacts)
|
|||||||
| 小册 | `/book` | `src/modules/ebook` + `src/modules/ebook-content` |
|
| 小册 | `/book` | `src/modules/ebook` + `src/modules/ebook-content` |
|
||||||
| 旅居社群 | `/community` | `src/modules/community`(Lounge / Ergo / MiroTalk;**勿改名**) |
|
| 旅居社群 | `/community` | `src/modules/community`(Lounge / Ergo / MiroTalk;**勿改名**) |
|
||||||
| 游民社区 | `/social` | `src/modules/social` · API `/api/social/v1` · SQLite · Centrifugo 实时 · 视觉默认 T1 |
|
| 游民社区 | `/social` | `src/modules/social` · API `/api/social/v1` · SQLite · Centrifugo 实时 · 视觉默认 T1 |
|
||||||
|
| **远程工作** | `/social/work` | `src/modules/work` · FastAPI `work_svc` `/api/work/v1`(看板 + 文档) |
|
||||||
| VIP | `/vip` | `src/modules/vip`(微信小程序原生页,见下) |
|
| VIP | `/vip` | `src/modules/vip`(微信小程序原生页,见下) |
|
||||||
| 后台 | admin.nomadro.cn | `apps/admin` |
|
| 后台 .cn | admin.nomadro.cn | `apps/admin`(`/wechat` · `/douyin`) |
|
||||||
|
| 后台 .com | admin.nomadro.com | `apps/com/admin`(**仅 Web**;美国 VPS) |
|
||||||
| API | api.nomadro.cn | `apps/api` |
|
| API | api.nomadro.cn | `apps/api` |
|
||||||
|
|
||||||
后台平台:`/wechat/*` 微信 · `/douyin/*` 抖音。抖音加群弹窗(公众号 / 抖音群)集成在 **`/douyin/modules`**(非独立页)。
|
`.cn` 后台平台:`/wechat/*` 微信 · `/douyin/*` 抖音。抖音加群弹窗集成在 **`/douyin/modules`**。`.com` 未备案,**无**小程序后台。
|
||||||
|
|
||||||
### 微信后台(admin.nomadro.cn/wechat)
|
### 微信后台(admin.nomadro.cn/wechat)
|
||||||
|
|
||||||
@ -90,6 +94,7 @@ pnpm dev:weapp # 微信小程序
|
|||||||
pnpm dev:tt # 抖音小程序
|
pnpm dev:tt # 抖音小程序
|
||||||
pnpm dev:admin # 管理后台 :5173
|
pnpm dev:admin # 管理后台 :5173
|
||||||
pnpm dev:api # FastAPI(需先建 apps/api/.venv)
|
pnpm dev:api # FastAPI(需先建 apps/api/.venv)
|
||||||
|
pnpm dev:work-api # 远程工作 work_svc :8021(看板 / 文档)
|
||||||
|
|
||||||
pnpm build:portal
|
pnpm build:portal
|
||||||
pnpm build:admin
|
pnpm build:admin
|
||||||
@ -125,6 +130,25 @@ pnpm dev:api
|
|||||||
|
|
||||||
与旅居社群 `/community` **完全独立**:门户 `src/modules/social` + `src/app/social`;后端 `social_svc`(前缀 `/api/social/v1`,库文件 `data/social/social.db` 或 `SOCIAL_DB_PATH`);`SOCIAL_ENABLED=false` 或挂载失败不影响 ebook / community / pay。门户首页主入口为「游民社区」;旅居社群仍保留。增量部署见 [`deploy/social/README.md`](deploy/social/README.md)。
|
与旅居社群 `/community` **完全独立**:门户 `src/modules/social` + `src/app/social`;后端 `social_svc`(前缀 `/api/social/v1`,库文件 `data/social/social.db` 或 `SOCIAL_DB_PATH`);`SOCIAL_ENABLED=false` 或挂载失败不影响 ebook / community / pay。门户首页主入口为「游民社区」;旅居社群仍保留。增量部署见 [`deploy/social/README.md`](deploy/social/README.md)。
|
||||||
|
|
||||||
|
**地理发现**:`/social/map`、`/social/places`;内部 API `GET /api/social/v1/map/cities`。对外标准面:`/api/public/v1`(OpenAPI / SDK / MCP / Skill,见 [`docs/public-api.md`](docs/public-api.md))。**默认发版 `.com`(美国机)**;`.cn` 独立同步。
|
||||||
|
|
||||||
|
### 远程工作(`/social/work`)
|
||||||
|
|
||||||
|
游民社区「一起做事」下的 **看板 + 实时文档**:读 Planka / Etherpad **域模型后自研** Next + FastAPI,同域挂载,**禁止** iframe / 二级域跳转 / micro-app 壳。
|
||||||
|
|
||||||
|
| 能力 | 路由 | 前端 | 后端 |
|
||||||
|
|------|------|------|------|
|
||||||
|
| 落地 | `/social/work` | `WorkClient` 品牌首屏 | — |
|
||||||
|
| 看板 | `/social/work/boards` · `/boards/:id` | DnD 列/卡 · 标签 · 清单 · 成员 · 秒表 · 封面 · 归档 · 附件链接 · 活动流 | `work_svc` |
|
||||||
|
| 文档 | `/social/work/pads` · `/pads/:id` | 自动保存 + 修订历史 | 同上 |
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev:work-api # :8021 · WORK_API_URL 默认同源代理 /api/work/v1
|
||||||
|
pnpm dev # http://localhost:3000/social/work
|
||||||
|
```
|
||||||
|
|
||||||
|
数据:`data/work/work.sqlite3`(或 `WORK_DATA_DIR`)。参考 upstream:`pnpm work:fetch`(仅对照,产品不跑 Docker Planka UI)。细节见 [`apps/work/README.md`](apps/work/README.md)。
|
||||||
|
|
||||||
| 层 | 线上(82) | 说明 |
|
| 层 | 线上(82) | 说明 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| 门户 | `nomadro.service` `:4003` | `/social/*`;前端发版须**本地确认后再上线** |
|
| 门户 | `nomadro.service` `:4003` | `/social/*`;前端发版须**本地确认后再上线** |
|
||||||
|
|||||||
1
apps/api/services/work_svc/__init__.py
Normal file
1
apps/api/services/work_svc/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
"""Nomadro work service — Planka/Etherpad-inspired boards + pads (secondary-dev)."""
|
||||||
18
apps/api/services/work_svc/config.py
Normal file
18
apps/api/services/work_svc/config.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
WORK_ENABLED = os.getenv("WORK_ENABLED", "1").strip().lower() not in {
|
||||||
|
"0",
|
||||||
|
"false",
|
||||||
|
"no",
|
||||||
|
"off",
|
||||||
|
}
|
||||||
|
|
||||||
|
DATA_DIR = Path(os.getenv("WORK_DATA_DIR", "/var/lib/nomadro/work"))
|
||||||
|
if not DATA_DIR.exists():
|
||||||
|
# local / Windows fallback
|
||||||
|
DATA_DIR = Path(os.getenv("WORK_DATA_DIR_LOCAL", "")).resolve() if os.getenv("WORK_DATA_DIR_LOCAL") else Path.cwd() / "data" / "work"
|
||||||
|
|
||||||
|
DB_PATH = DATA_DIR / "work.sqlite3"
|
||||||
3
apps/api/services/work_svc/routers/__init__.py
Normal file
3
apps/api/services/work_svc/routers/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from .api import router
|
||||||
|
|
||||||
|
__all__ = ["router"]
|
||||||
315
apps/api/services/work_svc/routers/api.py
Normal file
315
apps/api/services/work_svc/routers/api.py
Normal file
@ -0,0 +1,315 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from fastapi import APIRouter, HTTPException
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from work_svc import store
|
||||||
|
|
||||||
|
router = APIRouter(tags=["work"])
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectIn(BaseModel):
|
||||||
|
name: str = Field(min_length=1, max_length=200)
|
||||||
|
description: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class BoardIn(BaseModel):
|
||||||
|
project_id: str
|
||||||
|
name: str = Field(min_length=1, max_length=200)
|
||||||
|
|
||||||
|
|
||||||
|
class ListIn(BaseModel):
|
||||||
|
name: str = Field(min_length=1, max_length=120)
|
||||||
|
type: str = "active"
|
||||||
|
|
||||||
|
|
||||||
|
class CardIn(BaseModel):
|
||||||
|
list_id: str
|
||||||
|
name: str = Field(min_length=1, max_length=500)
|
||||||
|
description: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
class MoveIn(BaseModel):
|
||||||
|
list_id: str
|
||||||
|
position: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
class CardPatch(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
description: str | None = None
|
||||||
|
due_date: str | None = None
|
||||||
|
clear_due: bool = False
|
||||||
|
is_due_completed: bool | None = None
|
||||||
|
cover_color: str | None = None
|
||||||
|
clear_cover: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
class BoardPatch(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
background_gradient: str | None = None
|
||||||
|
show_card_counter: bool | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class AttachmentIn(BaseModel):
|
||||||
|
name: str = Field(min_length=1, max_length=200)
|
||||||
|
url: str = Field(min_length=1, max_length=2000)
|
||||||
|
|
||||||
|
|
||||||
|
class ListMoveIn(BaseModel):
|
||||||
|
position: int = 0
|
||||||
|
|
||||||
|
|
||||||
|
class LabelToggleIn(BaseModel):
|
||||||
|
label_id: str
|
||||||
|
|
||||||
|
|
||||||
|
class TaskIn(BaseModel):
|
||||||
|
name: str = Field(min_length=1, max_length=500)
|
||||||
|
|
||||||
|
|
||||||
|
class CommentIn(BaseModel):
|
||||||
|
text: str = Field(min_length=1, max_length=4000)
|
||||||
|
author: str = "guest"
|
||||||
|
|
||||||
|
|
||||||
|
class ListPatch(BaseModel):
|
||||||
|
name: str | None = None
|
||||||
|
color: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class MemberIn(BaseModel):
|
||||||
|
name: str = Field(min_length=1, max_length=80)
|
||||||
|
|
||||||
|
|
||||||
|
class PadIn(BaseModel):
|
||||||
|
title: str = Field(min_length=1, max_length=200)
|
||||||
|
author: str = "guest"
|
||||||
|
|
||||||
|
|
||||||
|
class PadUpdate(BaseModel):
|
||||||
|
text: str
|
||||||
|
author: str = "guest"
|
||||||
|
title: str | None = None
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/health")
|
||||||
|
def health():
|
||||||
|
return {"ok": True, "service": "nomadro-work", "inspiredBy": ["planka", "etherpad"]}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/projects")
|
||||||
|
def projects():
|
||||||
|
return {"ok": True, "projects": store.list_projects()}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/projects")
|
||||||
|
def post_project(body: ProjectIn):
|
||||||
|
return {"ok": True, "project": store.create_project(body.name, body.description)}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/boards")
|
||||||
|
def boards(project_id: str | None = None):
|
||||||
|
return {"ok": True, "boards": store.list_boards(project_id)}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards")
|
||||||
|
def post_board(body: BoardIn):
|
||||||
|
board = store.create_board(body.project_id, body.name)
|
||||||
|
if not board:
|
||||||
|
raise HTTPException(400, "bad_project")
|
||||||
|
return {"ok": True, "board": board}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/boards/{board_id}")
|
||||||
|
def board(board_id: str):
|
||||||
|
b = store.get_board(board_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/lists")
|
||||||
|
def post_list(board_id: str, body: ListIn):
|
||||||
|
b = store.add_list(board_id, body.name, body.type)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards")
|
||||||
|
def post_card(board_id: str, body: CardIn):
|
||||||
|
b = store.add_card(board_id, body.list_id, body.name, body.description)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/move")
|
||||||
|
def post_move(board_id: str, card_id: str, body: MoveIn):
|
||||||
|
b = store.move_card(board_id, card_id, body.list_id, body.position)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/boards/{board_id}")
|
||||||
|
def patch_board(board_id: str, body: BoardPatch):
|
||||||
|
b = store.update_board(
|
||||||
|
board_id,
|
||||||
|
name=body.name,
|
||||||
|
background_gradient=body.background_gradient,
|
||||||
|
show_card_counter=body.show_card_counter,
|
||||||
|
)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/boards/{board_id}/cards/{card_id}")
|
||||||
|
def patch_card(board_id: str, card_id: str, body: CardPatch):
|
||||||
|
b = store.update_card(
|
||||||
|
board_id,
|
||||||
|
card_id,
|
||||||
|
name=body.name,
|
||||||
|
description=body.description,
|
||||||
|
due_date=body.due_date,
|
||||||
|
clear_due=body.clear_due,
|
||||||
|
is_due_completed=body.is_due_completed,
|
||||||
|
cover_color=body.cover_color,
|
||||||
|
clear_cover=body.clear_cover,
|
||||||
|
)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/stopwatch/toggle")
|
||||||
|
def post_stopwatch(board_id: str, card_id: str):
|
||||||
|
b = store.toggle_stopwatch(board_id, card_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/archive")
|
||||||
|
def post_archive(board_id: str, card_id: str):
|
||||||
|
b = store.archive_card(board_id, card_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/attachments")
|
||||||
|
def post_attachment(board_id: str, card_id: str, body: AttachmentIn):
|
||||||
|
b = store.add_attachment(board_id, card_id, body.name, body.url)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/boards/{board_id}/attachments/{attachment_id}")
|
||||||
|
def remove_attachment(board_id: str, attachment_id: str):
|
||||||
|
b = store.delete_attachment(board_id, attachment_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/lists/{list_id}/move")
|
||||||
|
def post_list_move(board_id: str, list_id: str, body: ListMoveIn):
|
||||||
|
b = store.move_list(board_id, list_id, body.position)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/labels/toggle")
|
||||||
|
def post_label_toggle(board_id: str, card_id: str, body: LabelToggleIn):
|
||||||
|
b = store.toggle_card_label(board_id, card_id, body.label_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/tasks")
|
||||||
|
def post_task(board_id: str, card_id: str, body: TaskIn):
|
||||||
|
b = store.add_task(board_id, card_id, body.name)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/tasks/{task_id}/toggle")
|
||||||
|
def post_task_toggle(board_id: str, task_id: str):
|
||||||
|
b = store.toggle_task(board_id, task_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/comments")
|
||||||
|
def post_comment(board_id: str, card_id: str, body: CommentIn):
|
||||||
|
b = store.add_comment(board_id, card_id, body.author, body.text)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch("/boards/{board_id}/lists/{list_id}")
|
||||||
|
def patch_list(board_id: str, list_id: str, body: ListPatch):
|
||||||
|
b = store.update_list(
|
||||||
|
board_id, list_id, name=body.name, color=body.color
|
||||||
|
)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/boards/{board_id}/lists/{list_id}")
|
||||||
|
def remove_list(board_id: str, list_id: str):
|
||||||
|
b = store.delete_list(board_id, list_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete("/boards/{board_id}/cards/{card_id}")
|
||||||
|
def remove_card(board_id: str, card_id: str):
|
||||||
|
b = store.delete_card(board_id, card_id)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/boards/{board_id}/cards/{card_id}/members/toggle")
|
||||||
|
def post_member_toggle(board_id: str, card_id: str, body: MemberIn):
|
||||||
|
b = store.toggle_card_member(board_id, card_id, body.name)
|
||||||
|
if not b:
|
||||||
|
raise HTTPException(400, "bad_request")
|
||||||
|
return {"ok": True, "board": b}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/pads")
|
||||||
|
def pads():
|
||||||
|
return {"ok": True, "pads": store.list_pads()}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/pads")
|
||||||
|
def post_pad(body: PadIn):
|
||||||
|
return {"ok": True, "pad": store.create_pad(body.title, body.author)}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/pads/{pad_id}")
|
||||||
|
def pad(pad_id: str):
|
||||||
|
p = store.get_pad(pad_id)
|
||||||
|
if not p:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "pad": p}
|
||||||
|
|
||||||
|
|
||||||
|
@router.put("/pads/{pad_id}")
|
||||||
|
def put_pad(pad_id: str, body: PadUpdate):
|
||||||
|
p = store.update_pad(pad_id, body.text, body.author, body.title)
|
||||||
|
if not p:
|
||||||
|
raise HTTPException(404, "not_found")
|
||||||
|
return {"ok": True, "pad": p}
|
||||||
1091
apps/api/services/work_svc/store.py
Normal file
1091
apps/api/services/work_svc/store.py
Normal file
File diff suppressed because it is too large
Load Diff
42
apps/api/work_main.py
Normal file
42
apps/api/work_main.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
"""Nomadro work API — boards (Planka model) + pads (Etherpad model)."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent
|
||||||
|
SERVICES = ROOT / "services"
|
||||||
|
sys.path.insert(0, str(ROOT))
|
||||||
|
sys.path.insert(0, str(SERVICES))
|
||||||
|
|
||||||
|
from work_svc.config import WORK_ENABLED # noqa: E402
|
||||||
|
from work_svc.routers import router as work_router # noqa: E402
|
||||||
|
from work_svc.store import init_db # noqa: E402
|
||||||
|
|
||||||
|
app = FastAPI(title="nomadro-work", docs_url="/docs", redoc_url=None)
|
||||||
|
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
def _startup() -> None:
|
||||||
|
if WORK_ENABLED:
|
||||||
|
init_db()
|
||||||
|
|
||||||
|
|
||||||
|
if WORK_ENABLED:
|
||||||
|
app.include_router(work_router, prefix="/api/work/v1")
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/health")
|
||||||
|
def health():
|
||||||
|
return {"ok": True, "service": "nomadro-work", "work": bool(WORK_ENABLED)}
|
||||||
27
apps/work/.env.example
Normal file
27
apps/work/.env.example
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# Copy to apps/work/.env for docker-compose (server / local Docker)
|
||||||
|
|
||||||
|
# —— Planka ——
|
||||||
|
PLANKA_PORT=1337
|
||||||
|
# Public BASE_URL must match same-origin MF path (no subdomain)
|
||||||
|
PLANKA_BASE_URL=http://127.0.0.1:1337
|
||||||
|
PLANKA_SECRET_KEY=change_me_planka_secret_32chars_min
|
||||||
|
PLANKA_DB_PASSWORD=change_me_planka_db
|
||||||
|
DEFAULT_ADMIN_EMAIL=hackrobot@nomadro.com
|
||||||
|
DEFAULT_ADMIN_PASSWORD=change_me_admin
|
||||||
|
DEFAULT_ADMIN_NAME=Nomadro
|
||||||
|
|
||||||
|
# —— Etherpad ——
|
||||||
|
ETHERPAD_PORT=9001
|
||||||
|
DOCKER_COMPOSE_APP_ADMIN_PASSWORD=change_me_etherpad_admin
|
||||||
|
DOCKER_COMPOSE_POSTGRES_PASSWORD=change_me_etherpad_db
|
||||||
|
DOCKER_COMPOSE_POSTGRES_USER=etherpad
|
||||||
|
DOCKER_COMPOSE_POSTGRES_DATABASE=etherpad
|
||||||
|
DOCKER_COMPOSE_APP_DEFAULT_PAD_TEXT=Welcome to Nomadro Pads — remote collaboration.
|
||||||
|
DOCKER_COMPOSE_APP_TRUST_PROXY=true
|
||||||
|
|
||||||
|
# —— Portal local (put in repo-root .env.local, not here) ——
|
||||||
|
# WORK_PLANKA_ORIGIN=http://127.0.0.1:1337
|
||||||
|
# WORK_ETHERPAD_ORIGIN=http://127.0.0.1:9001
|
||||||
|
# Without local Docker, point at US:
|
||||||
|
# WORK_PLANKA_ORIGIN=http://108.174.50.68:1337
|
||||||
|
# WORK_ETHERPAD_ORIGIN=http://108.174.50.68:9001
|
||||||
4
apps/work/.gitignore
vendored
Normal file
4
apps/work/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.env
|
||||||
|
upstream/planka/
|
||||||
|
upstream/etherpad/
|
||||||
|
*.log
|
||||||
39
apps/work/README.md
Normal file
39
apps/work/README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Remote work — secondary-dev (Next + FastAPI)
|
||||||
|
|
||||||
|
读开源 **域模型** 后自研,模块化进 Nomadro(Fair Use;非 iframe / 非原样塞 upstream UI):
|
||||||
|
|
||||||
|
| 能力 | 参考源码 | UI | API |
|
||||||
|
|------|----------|----|-----|
|
||||||
|
| 看板 | Planka Project / Board / List / Card / Label / Task / Comment / Action / Stopwatch | `/social/work/boards` · `src/modules/work` | FastAPI `work_svc` `/api/work/v1` |
|
||||||
|
| 文档 | Etherpad pad + revisions | `/social/work/pads` | 同上 |
|
||||||
|
|
||||||
|
## 本地
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm dev:work-api # uvicorn work_main:app :8021
|
||||||
|
pnpm dev # http://localhost:3000/social/work
|
||||||
|
```
|
||||||
|
|
||||||
|
门户经 `src/app/api/work/v1/[[...path]]` 同源代理到 `WORK_API_URL`(默认 `http://127.0.0.1:8021`)。
|
||||||
|
|
||||||
|
## 看板能力(Planka 对齐子集)
|
||||||
|
|
||||||
|
- 列 / 卡片拖拽(`@hello-pangea/dnd`)
|
||||||
|
- 列表重命名 · 配色 · 删除;Archive 列
|
||||||
|
- 卡片:标签、截止日期(含完成)、秒表、封面色、成员、清单、评论、附件链接、归档 / 删除
|
||||||
|
- 看板背景(Planka gradient id → Nomadro 深色配色)
|
||||||
|
- 活动流(`createCard` / `moveCard` / `addMemberToCard` / …)
|
||||||
|
|
||||||
|
模块拆分:`components/board/*` · `lib/stopwatch.ts` · `lib/backgrounds.ts`。
|
||||||
|
|
||||||
|
## 数据与参考
|
||||||
|
|
||||||
|
- SQLite:`data/work/work.sqlite3`(或 `WORK_DATA_DIR`)
|
||||||
|
- Upstream 仅参考:`apps/work/upstream/*`(`pnpm work:fetch`)
|
||||||
|
- Overlay / Docker 辅助:`pnpm work:overlay` · `work:up`(**产品 UI 不依赖**)
|
||||||
|
|
||||||
|
## 反模式
|
||||||
|
|
||||||
|
- iframe / `web-view` / micro-app 嵌 Planka·Etherpad
|
||||||
|
- 跳 `work.` / `pad.` 二级域
|
||||||
|
- 把整包 upstream SCSS 硬塞进 Next
|
||||||
98
apps/work/docker-compose.yml
Normal file
98
apps/work/docker-compose.yml
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
# Nomadro remote work — Planka + Etherpad (US .com / local)
|
||||||
|
# Docs: apps/work/README.md
|
||||||
|
# Upstream: fetch-upstream.mjs → overlay → compose
|
||||||
|
|
||||||
|
name: nomadro-work
|
||||||
|
|
||||||
|
services:
|
||||||
|
planka-db:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: planka
|
||||||
|
POSTGRES_USER: planka
|
||||||
|
POSTGRES_PASSWORD: ${PLANKA_DB_PASSWORD:?set PLANKA_DB_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- planka_db:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U planka -d planka"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 8
|
||||||
|
|
||||||
|
planka:
|
||||||
|
image: ghcr.io/plankanban/planka:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
depends_on:
|
||||||
|
planka-db:
|
||||||
|
condition: service_healthy
|
||||||
|
ports:
|
||||||
|
- "${PLANKA_PORT:-1337}:1337"
|
||||||
|
environment:
|
||||||
|
BASE_URL: ${PLANKA_BASE_URL:-http://127.0.0.1:1337}
|
||||||
|
DATABASE_URL: postgresql://planka:${PLANKA_DB_PASSWORD}@planka-db:5432/planka
|
||||||
|
SECRET_KEY: ${PLANKA_SECRET_KEY:?set PLANKA_SECRET_KEY}
|
||||||
|
DEFAULT_ADMIN_EMAIL: ${DEFAULT_ADMIN_EMAIL:-hackrobot@nomadro.com}
|
||||||
|
DEFAULT_ADMIN_PASSWORD: ${DEFAULT_ADMIN_PASSWORD:?set DEFAULT_ADMIN_PASSWORD}
|
||||||
|
DEFAULT_ADMIN_NAME: ${DEFAULT_ADMIN_NAME:-Nomadro}
|
||||||
|
TRUST_PROXY: "true"
|
||||||
|
volumes:
|
||||||
|
- planka_avatars:/app/public/user-avatars
|
||||||
|
- planka_bg:/app/public/project-background-images
|
||||||
|
- planka_attach:/app/private/attachments
|
||||||
|
# Secondary-dev skin: mount overlay CSS if present
|
||||||
|
- ./overlay/planka/nomadro-skin.css:/app/public/nomadro-skin.css:ro
|
||||||
|
|
||||||
|
etherpad-db:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${DOCKER_COMPOSE_POSTGRES_DATABASE:-etherpad}
|
||||||
|
POSTGRES_USER: ${DOCKER_COMPOSE_POSTGRES_USER:-etherpad}
|
||||||
|
POSTGRES_PASSWORD: ${DOCKER_COMPOSE_POSTGRES_PASSWORD:?set DOCKER_COMPOSE_POSTGRES_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
- etherpad_db:/var/lib/postgresql/data
|
||||||
|
healthcheck:
|
||||||
|
test:
|
||||||
|
[
|
||||||
|
"CMD-SHELL",
|
||||||
|
"pg_isready -U ${DOCKER_COMPOSE_POSTGRES_USER:-etherpad} -d ${DOCKER_COMPOSE_POSTGRES_DATABASE:-etherpad}",
|
||||||
|
]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 8
|
||||||
|
|
||||||
|
etherpad:
|
||||||
|
image: etherpad/etherpad:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
user: "0:0"
|
||||||
|
depends_on:
|
||||||
|
etherpad-db:
|
||||||
|
condition: service_healthy
|
||||||
|
ports:
|
||||||
|
- "${ETHERPAD_PORT:-9001}:9001"
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
ADMIN_PASSWORD: ${DOCKER_COMPOSE_APP_ADMIN_PASSWORD:?set DOCKER_COMPOSE_APP_ADMIN_PASSWORD}
|
||||||
|
DB_TYPE: postgres
|
||||||
|
DB_HOST: etherpad-db
|
||||||
|
DB_PORT: 5432
|
||||||
|
DB_NAME: ${DOCKER_COMPOSE_POSTGRES_DATABASE:-etherpad}
|
||||||
|
DB_USER: ${DOCKER_COMPOSE_POSTGRES_USER:-etherpad}
|
||||||
|
DB_PASS: ${DOCKER_COMPOSE_POSTGRES_PASSWORD}
|
||||||
|
DEFAULT_PAD_TEXT: ${DOCKER_COMPOSE_APP_DEFAULT_PAD_TEXT:-Welcome to Nomadro Pads}
|
||||||
|
TRUST_PROXY: ${DOCKER_COMPOSE_APP_TRUST_PROXY:-true}
|
||||||
|
TITLE: Nomadro Pads
|
||||||
|
volumes:
|
||||||
|
- etherpad_plugins:/opt/etherpad-lite/src/plugin_packages
|
||||||
|
- etherpad_var:/opt/etherpad-lite/var
|
||||||
|
- ./overlay/etherpad/pad.css:/opt/etherpad-lite/src/static/custom/pad.css:ro
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
planka_db:
|
||||||
|
planka_avatars:
|
||||||
|
planka_bg:
|
||||||
|
planka_attach:
|
||||||
|
etherpad_db:
|
||||||
|
etherpad_plugins:
|
||||||
|
etherpad_var:
|
||||||
11
apps/work/overlay/etherpad/README.md
Normal file
11
apps/work/overlay/etherpad/README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# Etherpad overlay(Nomadro)
|
||||||
|
|
||||||
|
上游:https://github.com/ether/etherpad(Apache-2.0)
|
||||||
|
|
||||||
|
| 路径 | 用途 |
|
||||||
|
|---|---|
|
||||||
|
| `plugins.txt` | 建议安装的插件列表(二次开发时 `pnpm run plugins i …`) |
|
||||||
|
| `patches/` | 对 `upstream/etherpad` 的 patch |
|
||||||
|
| `pad.css` | 可选皮肤;可拷进上游 `src/static/custom` |
|
||||||
|
|
||||||
|
Compose 默认用官方镜像 + 环境变量;深改源码时切到 `upstream/etherpad` 本地 build。
|
||||||
18
apps/work/overlay/etherpad/pad.css
Normal file
18
apps/work/overlay/etherpad/pad.css
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* Nomadro Etherpad secondary-dev skin */
|
||||||
|
:root {
|
||||||
|
--nomadro-amber: #f59e0b;
|
||||||
|
--nomadro-ink: #0c0c0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editorcontainerbox,
|
||||||
|
#outerdocbody {
|
||||||
|
background: #0f1419 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#editbar {
|
||||||
|
border-bottom: 1px solid rgba(245, 158, 11, 0.25) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonicon {
|
||||||
|
color: var(--nomadro-amber) !important;
|
||||||
|
}
|
||||||
0
apps/work/overlay/etherpad/patches/.gitkeep
Normal file
0
apps/work/overlay/etherpad/patches/.gitkeep
Normal file
5
apps/work/overlay/etherpad/plugins.txt
Normal file
5
apps/work/overlay/etherpad/plugins.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
ep_align
|
||||||
|
ep_comments_page
|
||||||
|
ep_font_color
|
||||||
|
ep_headings2
|
||||||
|
ep_markdown
|
||||||
15
apps/work/overlay/planka/README.md
Normal file
15
apps/work/overlay/planka/README.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Planka overlay(Nomadro)
|
||||||
|
|
||||||
|
二次开发放这里,勿直接改 `upstream/planka` 后指望可干净 pull。
|
||||||
|
|
||||||
|
| 文件 | 用途 |
|
||||||
|
|---|---|
|
||||||
|
| `nomadro-skin.css` | 品牌皮肤(compose 挂到 `/public/nomadro-skin.css`) |
|
||||||
|
| `patches/` | 可选 unified diff,对 upstream 打补丁 |
|
||||||
|
|
||||||
|
源码二次开发流程:
|
||||||
|
|
||||||
|
1. `node apps/work/scripts/fetch-upstream.mjs`
|
||||||
|
2. 在 `upstream/planka` 试改
|
||||||
|
3. `git diff > overlay/planka/patches/xxxx.patch`
|
||||||
|
4. `apply-overlay.mjs` 合并皮肤与 patch
|
||||||
30
apps/work/overlay/planka/nomadro-skin.css
Normal file
30
apps/work/overlay/planka/nomadro-skin.css
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Nomadro Planka secondary-dev skin
|
||||||
|
* Mounted into Planka public/; also referenced by MF host branding.
|
||||||
|
*/
|
||||||
|
:root {
|
||||||
|
--nomadro-amber: #f59e0b;
|
||||||
|
--nomadro-ink: #0c0c0f;
|
||||||
|
--nomadro-panel: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
background: var(--nomadro-ink) !important;
|
||||||
|
font-family: ui-sans-serif, system-ui, "Segoe UI", "PingFang SC", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Soften stock chrome toward Nomadro amber */
|
||||||
|
a,
|
||||||
|
button.link {
|
||||||
|
color: var(--nomadro-amber);
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
}
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: rgba(245, 158, 11, 0.35);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
0
apps/work/overlay/planka/patches/.gitkeep
Normal file
0
apps/work/overlay/planka/patches/.gitkeep
Normal file
72
apps/work/scripts/apply-overlay.mjs
Normal file
72
apps/work/scripts/apply-overlay.mjs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Copy Nomadro overlay assets into upstream trees (when present)
|
||||||
|
* and apply optional patches under overlay/<service>/patches/*.patch
|
||||||
|
*/
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import {
|
||||||
|
copyFileSync,
|
||||||
|
existsSync,
|
||||||
|
mkdirSync,
|
||||||
|
readdirSync,
|
||||||
|
statSync,
|
||||||
|
} from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const overlayRoot = join(root, "overlay");
|
||||||
|
const upstreamRoot = join(root, "upstream");
|
||||||
|
|
||||||
|
function applyPatches(service) {
|
||||||
|
const patchDir = join(overlayRoot, service, "patches");
|
||||||
|
const dest = join(upstreamRoot, service);
|
||||||
|
if (!existsSync(patchDir) || !existsSync(dest)) return;
|
||||||
|
const files = readdirSync(patchDir).filter((f) => f.endsWith(".patch"));
|
||||||
|
for (const f of files) {
|
||||||
|
const p = join(patchDir, f);
|
||||||
|
console.log(`[patch] ${service} ← ${f}`);
|
||||||
|
const r = spawnSync("git", ["apply", "--whitespace=nowarn", p], {
|
||||||
|
cwd: dest,
|
||||||
|
stdio: "inherit",
|
||||||
|
});
|
||||||
|
if (r.status !== 0) {
|
||||||
|
console.warn(`[warn] patch failed (maybe already applied): ${f}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copySkin(service, fromRel, toRel) {
|
||||||
|
const from = join(overlayRoot, service, fromRel);
|
||||||
|
const destRoot = join(upstreamRoot, service);
|
||||||
|
if (!existsSync(from) || !existsSync(destRoot)) {
|
||||||
|
console.log(`[skip] ${service}/${fromRel}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const to = join(destRoot, toRel);
|
||||||
|
mkdirSync(dirname(to), { recursive: true });
|
||||||
|
if (statSync(from).isFile()) {
|
||||||
|
copyFileSync(from, to);
|
||||||
|
console.log(`[copy] ${service}: ${fromRel} → ${toRel}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!existsSync(join(upstreamRoot, "planka"))) {
|
||||||
|
console.log(
|
||||||
|
"upstream/planka missing — run fetch-upstream.mjs (compose image mode still OK)",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!existsSync(join(upstreamRoot, "etherpad"))) {
|
||||||
|
console.log(
|
||||||
|
"upstream/etherpad missing — run fetch-upstream.mjs (compose image mode still OK)",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
copySkin("planka", "nomadro-skin.css", "server/public/nomadro-skin.css");
|
||||||
|
copySkin("planka", "nomadro-skin.css", "client/public/nomadro-skin.css");
|
||||||
|
copySkin("etherpad", "pad.css", "src/static/custom/pad.css");
|
||||||
|
|
||||||
|
applyPatches("planka");
|
||||||
|
applyPatches("etherpad");
|
||||||
|
|
||||||
|
console.log("DONE apply-overlay");
|
||||||
54
apps/work/scripts/fetch-upstream.mjs
Normal file
54
apps/work/scripts/fetch-upstream.mjs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Shallow-clone Planka + Etherpad into apps/work/upstream/
|
||||||
|
* for secondary development. Does not commit upstream into git.
|
||||||
|
*/
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
||||||
|
const upstream = join(root, "upstream");
|
||||||
|
|
||||||
|
const REPOS = [
|
||||||
|
{
|
||||||
|
name: "planka",
|
||||||
|
url: "https://github.com/plankanban/planka.git",
|
||||||
|
branch: "master",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "etherpad",
|
||||||
|
url: "https://github.com/ether/etherpad.git",
|
||||||
|
branch: "master",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
mkdirSync(upstream, { recursive: true });
|
||||||
|
|
||||||
|
function run(cmd, args, cwd) {
|
||||||
|
console.log(`$ ${cmd} ${args.join(" ")}`);
|
||||||
|
const r = spawnSync(cmd, args, { cwd, stdio: "inherit", shell: false });
|
||||||
|
if (r.status !== 0) process.exit(r.status || 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const repo of REPOS) {
|
||||||
|
const dest = join(upstream, repo.name);
|
||||||
|
if (existsSync(join(dest, ".git"))) {
|
||||||
|
console.log(`[skip] ${repo.name} already cloned — pull --ff-only`);
|
||||||
|
run("git", ["-C", dest, "pull", "--ff-only", "origin", repo.branch]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (existsSync(dest)) rmSync(dest, { recursive: true, force: true });
|
||||||
|
run("git", [
|
||||||
|
"clone",
|
||||||
|
"--depth",
|
||||||
|
"1",
|
||||||
|
"--branch",
|
||||||
|
repo.branch,
|
||||||
|
repo.url,
|
||||||
|
dest,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("DONE fetch-upstream →", upstream);
|
||||||
62
apps/work/scripts/flatten-planka-scss.mjs
Normal file
62
apps/work/scripts/flatten-planka-scss.mjs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Flatten Planka CSS-module SCSS for Next/Turbopack:
|
||||||
|
* - unwrap `:global(#app) { ... }` → top-level local classes
|
||||||
|
* - remove nested `:global { .x }` blocks (third-party hooks → separate global sheet)
|
||||||
|
*/
|
||||||
|
import { readFileSync, writeFileSync, readdirSync, statSync } from "node:fs";
|
||||||
|
import { join, dirname } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const vendor = join(
|
||||||
|
dirname(fileURLToPath(import.meta.url)),
|
||||||
|
"../../../src/modules/work/planka/vendor",
|
||||||
|
);
|
||||||
|
|
||||||
|
function walk(dir, out = []) {
|
||||||
|
for (const name of readdirSync(dir)) {
|
||||||
|
const p = join(dir, name);
|
||||||
|
const st = statSync(p);
|
||||||
|
if (st.isDirectory()) walk(p, out);
|
||||||
|
else if (name.endsWith(".module.scss")) out.push(p);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function flatten(src) {
|
||||||
|
let s = src;
|
||||||
|
// Drop nested `:global { ... }` blocks (non-greedy multi-line)
|
||||||
|
s = s.replace(/\n\s*:global\s*\{[\s\S]*?\n\s*\}/g, "\n");
|
||||||
|
// Unwrap `:global(#app) { ... file ... }` — keep inner content, dedent one level
|
||||||
|
if (/:global\(#app\)\s*\{/.test(s)) {
|
||||||
|
s = s.replace(/:global\(#app\)\s*\{/, "");
|
||||||
|
// remove final closing brace of the wrapper if file ends with it
|
||||||
|
const idx = s.lastIndexOf("}");
|
||||||
|
if (idx !== -1) {
|
||||||
|
const after = s.slice(idx + 1).trim();
|
||||||
|
if (!after) s = s.slice(0, idx);
|
||||||
|
}
|
||||||
|
// crude dedent: lines that start with two spaces lose them once
|
||||||
|
s = s
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => (line.startsWith(" ") ? line.slice(2) : line))
|
||||||
|
.join("\n");
|
||||||
|
}
|
||||||
|
// Top-level bare `:global { #app {` in styles.module.scss — convert to plain #app
|
||||||
|
s = s.replace(/^:global\s*\{\s*\n\s*#app\s*\{/m, "#planka-next-root, #app {");
|
||||||
|
// If we opened #app block from :global, ensure we don't leave an extra closing from :global
|
||||||
|
// (styles.module.scss ends with two closing braces)
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
const files = walk(vendor);
|
||||||
|
let n = 0;
|
||||||
|
for (const f of files) {
|
||||||
|
const before = readFileSync(f, "utf8");
|
||||||
|
const after = flatten(before);
|
||||||
|
if (after !== before) {
|
||||||
|
writeFileSync(f, after, "utf8");
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`flattened ${n}/${files.length} module.scss files`);
|
||||||
208
apps/work/scripts/patch-planka-for-next.mjs
Normal file
208
apps/work/scripts/patch-planka-for-next.mjs
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Apply Nomadro Next.js secondary-dev patches onto synced Planka vendor.
|
||||||
|
*/
|
||||||
|
import { readFileSync, writeFileSync, existsSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||||
|
const vendor = join(root, "src/modules/work/planka/vendor");
|
||||||
|
|
||||||
|
function patch(rel, fn) {
|
||||||
|
const p = join(vendor, rel);
|
||||||
|
if (!existsSync(p)) {
|
||||||
|
console.warn("skip missing", rel);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const before = readFileSync(p, "utf8");
|
||||||
|
const after = fn(before);
|
||||||
|
if (after !== before) {
|
||||||
|
writeFileSync(p, after, "utf8");
|
||||||
|
console.log("patched", rel);
|
||||||
|
} else {
|
||||||
|
console.log("unchanged", rel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI under /social/work/app ; API under /work-api (proxied to Planka server)
|
||||||
|
patch("constants/Config.js", () => `/*!
|
||||||
|
* Copyright (c) 2024 PLANKA Software GmbH
|
||||||
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||||
|
*
|
||||||
|
* Modified for Nomadro Next.js secondary-dev (UI + API base split).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const UI_BASE_PATH = '/social/work/app';
|
||||||
|
const API_BASE_PATH = '/work-api';
|
||||||
|
/** @deprecated use UI_BASE_PATH for router; kept for Paths compat */
|
||||||
|
const BASE_PATH = UI_BASE_PATH;
|
||||||
|
|
||||||
|
const ACCESS_TOKEN_KEY = 'accessToken';
|
||||||
|
const ACCESS_TOKEN_VERSION_KEY = 'accessTokenVersion';
|
||||||
|
const ACCESS_TOKEN_VERSION = '1';
|
||||||
|
|
||||||
|
const POSITION_GAP = 65536;
|
||||||
|
const CARDS_LIMIT = 50;
|
||||||
|
const COMMENTS_LIMIT = 50;
|
||||||
|
const ACTIVITIES_LIMIT = 50;
|
||||||
|
|
||||||
|
const MAX_SIZE_TO_DISPLAY_CONTENT = 256 * 1024;
|
||||||
|
|
||||||
|
const IS_MAC =
|
||||||
|
typeof navigator !== 'undefined' && navigator.platform.startsWith('Mac');
|
||||||
|
|
||||||
|
const IS_TOUCH_PRIMARY =
|
||||||
|
typeof window !== 'undefined' && window.matchMedia('(hover: none)').matches;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
BASE_PATH,
|
||||||
|
UI_BASE_PATH,
|
||||||
|
API_BASE_PATH,
|
||||||
|
ACCESS_TOKEN_KEY,
|
||||||
|
ACCESS_TOKEN_VERSION_KEY,
|
||||||
|
ACCESS_TOKEN_VERSION,
|
||||||
|
POSITION_GAP,
|
||||||
|
CARDS_LIMIT,
|
||||||
|
COMMENTS_LIMIT,
|
||||||
|
ACTIVITIES_LIMIT,
|
||||||
|
MAX_SIZE_TO_DISPLAY_CONTENT,
|
||||||
|
IS_MAC,
|
||||||
|
IS_TOUCH_PRIMARY,
|
||||||
|
};
|
||||||
|
`);
|
||||||
|
|
||||||
|
patch("api/http.js", (s) =>
|
||||||
|
s
|
||||||
|
.replace(
|
||||||
|
"fetch(`${Config.BASE_PATH}/api${url}`",
|
||||||
|
"fetch(`${Config.API_BASE_PATH}/api${url}`",
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"Modified for Nomadro",
|
||||||
|
"Modified for Nomadro",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
patch("api/socket.js", (s) =>
|
||||||
|
s
|
||||||
|
.replace(
|
||||||
|
"io.sails.path = `${Config.BASE_PATH}/socket.io`;",
|
||||||
|
"io.sails.path = `${Config.API_BASE_PATH}/socket.io`;",
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
"io.sails.environment = import.meta.env.MODE;",
|
||||||
|
"io.sails.environment = process.env.NODE_ENV === 'production' ? 'production' : 'development';",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
patch("store.js", (s) => {
|
||||||
|
let out = s.replace(
|
||||||
|
/import\.meta\.env\.DEV/g,
|
||||||
|
"process.env.NODE_ENV !== 'production'",
|
||||||
|
);
|
||||||
|
if (!out.includes("Nomadro Next may omit redux-logger")) {
|
||||||
|
out = out.replace(
|
||||||
|
/if \(process\.env\.NODE_ENV !== 'production'\) \{[\s\S]*?middlewares\.push\(require\('redux-logger'\)\);[\s\S]*?\}/,
|
||||||
|
`if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
|
||||||
|
try {
|
||||||
|
// optional — Nomadro Next may omit redux-logger
|
||||||
|
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
|
||||||
|
middlewares.push(require('redux-logger').default || require('redux-logger'));
|
||||||
|
} catch (_) {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ !== 'undefined') {
|
||||||
|
compose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
patch("i18n.js", (s) =>
|
||||||
|
s.replace(/import\.meta\.env\.DEV/g, "process.env.NODE_ENV !== 'production'"),
|
||||||
|
);
|
||||||
|
|
||||||
|
patch("components/common/Root.jsx", (s) => {
|
||||||
|
let out = s
|
||||||
|
.replace('<ThemeProvider theme="light">', '<ThemeProvider theme="dark">')
|
||||||
|
.replace(
|
||||||
|
"import '../../lib/custom-ui/styles.css';\n",
|
||||||
|
"// Nomadro: skip custom-ui/styles.css (invalid CSS for LightningCSS)\n",
|
||||||
|
);
|
||||||
|
if (!out.includes("@work/planka/bridge/nomadro-planka.css")) {
|
||||||
|
out = out.replace(
|
||||||
|
"import '../../styles.module.scss';",
|
||||||
|
"import '../../styles.module.scss';\nimport '@work/planka/bridge/nomadro-planka.css';",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Vite SVG ?react → Nomadro shim
|
||||||
|
const svgFiles = [
|
||||||
|
"components/lists/List/List.jsx",
|
||||||
|
"components/common/Home/Projects.jsx",
|
||||||
|
"components/boards/Board/GridView.jsx",
|
||||||
|
"components/boards/Board/ListView.jsx",
|
||||||
|
"components/boards/Board/KanbanContent/KanbanContent.jsx",
|
||||||
|
];
|
||||||
|
for (const rel of svgFiles) {
|
||||||
|
patch(rel, (s) =>
|
||||||
|
s.replace(/from '([^']+\.svg)\?react'/g, "from '@work/planka/bridge/SvgIcon'"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
patch("components/common/AboutModal/AboutPane.jsx", (s) =>
|
||||||
|
s.replace(
|
||||||
|
/import changelogUrl from '[^']+CHANGELOG\.md\?url';/,
|
||||||
|
"const changelogUrl = 'https://github.com/plankanban/planka/blob/master/CHANGELOG.md';",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Turbopack rejects nested `:global { .foo }` inside CSS modules
|
||||||
|
patch(
|
||||||
|
"components/common/MarkdownEditor/MarkdownEditor.module.scss",
|
||||||
|
() => `/*!
|
||||||
|
* Copyright (c) 2024 PLANKA Software GmbH
|
||||||
|
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||||
|
*
|
||||||
|
* Modified for Nomadro Next/Turbopack (flatten :global nesting).
|
||||||
|
*/
|
||||||
|
|
||||||
|
.editor {
|
||||||
|
min-height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapper {
|
||||||
|
--g-md-editor-padding: 6px 12px;
|
||||||
|
--g-md-toolbar-padding: 6px 12px;
|
||||||
|
--g-md-toolbar-sticky-offset: -21px;
|
||||||
|
border: 1px solid rgba(9, 30, 66, 0.13);
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.wrapperError {
|
||||||
|
border: 1px solid #cf513d;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Semantic UI pack uses invalid `:activehover` — LightningCSS rejects it
|
||||||
|
{
|
||||||
|
const cssPath = join(vendor, "lib/custom-ui/styles.css");
|
||||||
|
if (existsSync(cssPath)) {
|
||||||
|
const raw = readFileSync(cssPath, "utf8");
|
||||||
|
const fixed = raw.replace(/:activehover/g, ":active:hover");
|
||||||
|
if (fixed !== raw) {
|
||||||
|
writeFileSync(cssPath, fixed, "utf8");
|
||||||
|
console.log("patched lib/custom-ui/styles.css activehover");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("DONE patch-planka-for-next");
|
||||||
36
apps/work/scripts/sync-planka-ui.mjs
Normal file
36
apps/work/scripts/sync-planka-ui.mjs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
/**
|
||||||
|
* Sync Planka client source → src/modules/work/planka/vendor
|
||||||
|
* Secondary-dev SoT: upstream/planka/client/src + overlay patches.
|
||||||
|
* Modified copies must keep PLANKA copyright + Fair Use notices.
|
||||||
|
*/
|
||||||
|
import { cpSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), "../../..");
|
||||||
|
const src = join(root, "apps/work/upstream/planka/client/src");
|
||||||
|
const dest = join(root, "src/modules/work/planka/vendor");
|
||||||
|
|
||||||
|
if (!existsSync(src)) {
|
||||||
|
console.error("Missing upstream. Run: pnpm work:fetch");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
rmSync(dest, { recursive: true, force: true });
|
||||||
|
mkdirSync(dirname(dest), { recursive: true });
|
||||||
|
cpSync(src, dest, { recursive: true });
|
||||||
|
|
||||||
|
writeFileSync(
|
||||||
|
join(dest, "NOMADRO_FORK.md"),
|
||||||
|
`# Nomadro fork of Planka client
|
||||||
|
|
||||||
|
- Upstream: apps/work/upstream/planka/client/src
|
||||||
|
- License: PLANKA Community / Fair Use (keep copyright headers)
|
||||||
|
- Modified for Nomadro Next.js embedding (see ../bridge)
|
||||||
|
- Sync: \`node apps/work/scripts/sync-planka-ui.mjs\`
|
||||||
|
`,
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log("synced", src, "→", dest);
|
||||||
@ -5,6 +5,29 @@ const API_URL = (process.env.API_URL || "http://127.0.0.1:8080").replace(
|
|||||||
/\/$/,
|
/\/$/,
|
||||||
"",
|
"",
|
||||||
);
|
);
|
||||||
|
/** Social IM is isolated (nomadro-social / portal nginx /rt). Never assume api.* hosts it. */
|
||||||
|
const SOCIAL_API_URL = (
|
||||||
|
process.env.SOCIAL_API_URL ||
|
||||||
|
(/\bapi\.nomadro\.(com|cn)\b/i.test(API_URL)
|
||||||
|
? API_URL.replace(/\bapi\.(nomadro\.(?:com|cn))\b/i, "$1")
|
||||||
|
: API_URL)
|
||||||
|
).replace(/\/$/, "");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Micro-frontend upstreams (Planka / Etherpad).
|
||||||
|
* Local without Docker: set WORK_*_ORIGIN in `.env.local` (e.g. US host :1337/:9001).
|
||||||
|
*/
|
||||||
|
const WORK_PLANKA_ORIGIN = (
|
||||||
|
process.env.WORK_PLANKA_ORIGIN || "http://127.0.0.1:1337"
|
||||||
|
).replace(/\/$/, "");
|
||||||
|
const WORK_ETHERPAD_ORIGIN = (
|
||||||
|
process.env.WORK_ETHERPAD_ORIGIN || "http://127.0.0.1:9001"
|
||||||
|
).replace(/\/$/, "");
|
||||||
|
if (process.env.NODE_ENV !== "production") {
|
||||||
|
console.info(
|
||||||
|
`[work] planka-api→${WORK_PLANKA_ORIGIN} etherpad→${WORK_ETHERPAD_ORIGIN}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** 门户前端均在 src/;禁止再指向已删除的垂直仓 */
|
/** 门户前端均在 src/;禁止再指向已删除的垂直仓 */
|
||||||
const aliases = {
|
const aliases = {
|
||||||
@ -13,6 +36,7 @@ const aliases = {
|
|||||||
"@social": path.resolve(__dirname, "src/modules/social"),
|
"@social": path.resolve(__dirname, "src/modules/social"),
|
||||||
"@navmini": path.resolve(__dirname, "src/modules/nav"),
|
"@navmini": path.resolve(__dirname, "src/modules/nav"),
|
||||||
"@vip": path.resolve(__dirname, "src/modules/vip"),
|
"@vip": path.resolve(__dirname, "src/modules/vip"),
|
||||||
|
"@work": path.resolve(__dirname, "src/modules/work"),
|
||||||
"@nomadro/pay": path.resolve(__dirname, "packages/pay/src/index.ts"),
|
"@nomadro/pay": path.resolve(__dirname, "packages/pay/src/index.ts"),
|
||||||
"@nomadro/pb": path.resolve(__dirname, "packages/pb/src/index.ts"),
|
"@nomadro/pb": path.resolve(__dirname, "packages/pb/src/index.ts"),
|
||||||
"@nomadro/sdk": path.resolve(__dirname, "packages/sdk/src/index.ts"),
|
"@nomadro/sdk": path.resolve(__dirname, "packages/sdk/src/index.ts"),
|
||||||
@ -50,6 +74,7 @@ const nextConfig: NextConfig = {
|
|||||||
"@social": "./src/modules/social",
|
"@social": "./src/modules/social",
|
||||||
"@navmini": "./src/modules/nav",
|
"@navmini": "./src/modules/nav",
|
||||||
"@vip": "./src/modules/vip",
|
"@vip": "./src/modules/vip",
|
||||||
|
"@work": "./src/modules/work",
|
||||||
"@nomadro/pay": "./packages/pay/src/index.ts",
|
"@nomadro/pay": "./packages/pay/src/index.ts",
|
||||||
"@nomadro/pb": "./packages/pb/src/index.ts",
|
"@nomadro/pb": "./packages/pb/src/index.ts",
|
||||||
"@nomadro/sdk": "./packages/sdk/src/index.ts",
|
"@nomadro/sdk": "./packages/sdk/src/index.ts",
|
||||||
@ -82,7 +107,25 @@ const nextConfig: NextConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
source: "/api/social/:path*",
|
source: "/api/social/:path*",
|
||||||
destination: `${API_URL}/api/social/:path*`,
|
destination: `${SOCIAL_API_URL}/api/social/:path*`,
|
||||||
|
},
|
||||||
|
// Planka server API/socket only (UI is native Next from forked client)
|
||||||
|
{
|
||||||
|
source: "/work-api",
|
||||||
|
destination: `${WORK_PLANKA_ORIGIN}/`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/work-api/:path*",
|
||||||
|
destination: `${WORK_PLANKA_ORIGIN}/:path*`,
|
||||||
|
},
|
||||||
|
// Etherpad still path-proxied until pad UI is ported
|
||||||
|
{
|
||||||
|
source: "/work-mf/etherpad",
|
||||||
|
destination: `${WORK_ETHERPAD_ORIGIN}/`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: "/work-mf/etherpad/:path*",
|
||||||
|
destination: `${WORK_ETHERPAD_ORIGIN}/:path*`,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
|
|||||||
66
package.json
66
package.json
@ -9,50 +9,112 @@
|
|||||||
"dev:weapp": "pnpm --filter @nomadro/miniprogram-weapp dev",
|
"dev:weapp": "pnpm --filter @nomadro/miniprogram-weapp dev",
|
||||||
"dev:tt": "pnpm --filter @nomadro/miniprogram-tt dev",
|
"dev:tt": "pnpm --filter @nomadro/miniprogram-tt dev",
|
||||||
"dev:admin": "pnpm --filter @nomadro/admin dev",
|
"dev:admin": "pnpm --filter @nomadro/admin dev",
|
||||||
|
"dev:admin-com": "pnpm --filter @nomadro/admin-com dev",
|
||||||
"dev:api": "node scripts/dev-api.mjs",
|
"dev:api": "node scripts/dev-api.mjs",
|
||||||
|
"dev:work-api": "python -m uvicorn work_main:app --reload --port 8021 --app-dir apps/api",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"build:portal": "next build",
|
"build:portal": "next build",
|
||||||
"build:h5": "pnpm --filter @nomadro/miniprogram-h5 build",
|
"build:h5": "pnpm --filter @nomadro/miniprogram-h5 build",
|
||||||
"build:weapp": "pnpm --filter @nomadro/miniprogram-weapp build",
|
"build:weapp": "pnpm --filter @nomadro/miniprogram-weapp build",
|
||||||
"build:tt": "pnpm --filter @nomadro/miniprogram-tt build",
|
"build:tt": "pnpm --filter @nomadro/miniprogram-tt build",
|
||||||
"build:admin": "pnpm --filter @nomadro/admin build",
|
"build:admin": "pnpm --filter @nomadro/admin build",
|
||||||
|
"build:admin-com": "pnpm --filter @nomadro/admin-com build",
|
||||||
"build:xhs": "python apps/miniprogram/xhs/scripts/assemble.py",
|
"build:xhs": "python apps/miniprogram/xhs/scripts/assemble.py",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"clean": "node scripts/clean-artifacts.mjs"
|
"clean": "node scripts/clean-artifacts.mjs",
|
||||||
|
"mcp": "pnpm --filter @nomadro/mcp start",
|
||||||
|
"dev:mcp": "pnpm --filter @nomadro/mcp start",
|
||||||
|
"work:fetch": "node apps/work/scripts/fetch-upstream.mjs",
|
||||||
|
"work:overlay": "node apps/work/scripts/apply-overlay.mjs",
|
||||||
|
"work:sync-ui": "node apps/work/scripts/sync-planka-ui.mjs",
|
||||||
|
"work:patch-ui": "node apps/work/scripts/patch-planka-for-next.mjs",
|
||||||
|
"work:flatten-scss": "node apps/work/scripts/flatten-planka-scss.mjs",
|
||||||
|
"work:port-ui": "pnpm work:sync-ui && pnpm work:patch-ui && pnpm work:flatten-scss",
|
||||||
|
"work:up": "docker-compose -f apps/work/docker-compose.yml --env-file apps/work/.env up -d",
|
||||||
|
"work:down": "docker-compose -f apps/work/docker-compose.yml --env-file apps/work/.env down"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^6.3.4",
|
"@ant-design/icons": "^6.3.4",
|
||||||
"@ant-design/nextjs-registry": "^1.3.0",
|
"@ant-design/nextjs-registry": "^1.3.0",
|
||||||
|
"@diplodoc/cut-extension": "^1.1.8",
|
||||||
|
"@diplodoc/transform": "^4.78.12",
|
||||||
|
"@gravity-ui/components": "^5.0.0",
|
||||||
|
"@gravity-ui/markdown-editor": "^15.49.0",
|
||||||
|
"@gravity-ui/uikit": "^8.0.0",
|
||||||
|
"@hello-pangea/dnd": "^18.0.1",
|
||||||
|
"@micro-zoe/micro-app": "1.0.0-rc.32",
|
||||||
"@nomadro/pay": "workspace:*",
|
"@nomadro/pay": "workspace:*",
|
||||||
"@nomadro/pb": "workspace:*",
|
"@nomadro/pb": "workspace:*",
|
||||||
"@nomadro/sdk": "workspace:*",
|
"@nomadro/sdk": "workspace:*",
|
||||||
"animate.css": "^4.1.1",
|
"animate.css": "^4.1.1",
|
||||||
"antd": "^6.6.5",
|
"antd": "^6.6.5",
|
||||||
"centrifuge": "^5.8.0",
|
"centrifuge": "^5.8.0",
|
||||||
|
"classnames": "^2.5.1",
|
||||||
|
"dequal": "^2.0.3",
|
||||||
"framer-motion": "^12.36.0",
|
"framer-motion": "^12.36.0",
|
||||||
"geist": "^1.7.0",
|
"geist": "^1.7.0",
|
||||||
"github-markdown-css": "^5.9.0",
|
"github-markdown-css": "^5.9.0",
|
||||||
"github-slugger": "^2.0.0",
|
"github-slugger": "^2.0.0",
|
||||||
|
"h3-js": "^4.5.0",
|
||||||
"highlight.js": "^11.12.0",
|
"highlight.js": "^11.12.0",
|
||||||
|
"history": "^5.3.0",
|
||||||
|
"i18next": "^26.7.1",
|
||||||
|
"i18next-browser-languagedetector": "^8.3.0",
|
||||||
"is-china-user": "^1.7.0",
|
"is-china-user": "^1.7.0",
|
||||||
|
"javascript-time-ago": "^2.6.4",
|
||||||
|
"js-cookie": "^3.0.8",
|
||||||
|
"jwt-decode": "^4.0.0",
|
||||||
|
"linkify-react": "^4.4.0",
|
||||||
|
"linkifyjs": "^4.4.0",
|
||||||
|
"lodash": "^4.18.1",
|
||||||
"lucide-react": "^0.577.0",
|
"lucide-react": "^0.577.0",
|
||||||
|
"maplibre-gl": "^6.16.0",
|
||||||
|
"markdown-it": "^15.0.3",
|
||||||
"marked": "^17.0.4",
|
"marked": "^17.0.4",
|
||||||
|
"nanoid": "^6.0.2",
|
||||||
"next": "16.1.6",
|
"next": "16.1.6",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
|
"photoswipe": "^5.4.4",
|
||||||
"pocketbase": "^0.26.8",
|
"pocketbase": "^0.26.8",
|
||||||
|
"prop-types": "^15.8.1",
|
||||||
|
"qrcode.react": "^4.2.0",
|
||||||
"react": "19.2.3",
|
"react": "19.2.3",
|
||||||
|
"react-beautiful-dnd": "^13.1.1",
|
||||||
|
"react-datepicker": "^9.1.0",
|
||||||
"react-dom": "19.2.3",
|
"react-dom": "19.2.3",
|
||||||
|
"react-dropzone": "^20.1.4",
|
||||||
|
"react-hot-keys": "^3.0.0",
|
||||||
|
"react-hot-toast": "^2.6.1",
|
||||||
|
"react-i18next": "^17.1.12",
|
||||||
|
"react-input-mask": "^2.0.4",
|
||||||
|
"react-intersection-observer": "^11.0.1",
|
||||||
"react-markdown": "^9.1.0",
|
"react-markdown": "^9.1.0",
|
||||||
|
"react-mentions": "^4.4.10",
|
||||||
|
"react-photoswipe-gallery": "^4.1.2",
|
||||||
|
"react-redux": "^9.3.1",
|
||||||
|
"react-router": "^8.5.1",
|
||||||
|
"react-textarea-autosize": "^8.5.9",
|
||||||
|
"react-time-ago": "^7.4.4",
|
||||||
|
"redux": "^5.0.1",
|
||||||
|
"redux-orm": "^0.16.2",
|
||||||
|
"redux-saga": "^1.5.1",
|
||||||
"rehype-highlight": "^7.0.2",
|
"rehype-highlight": "^7.0.2",
|
||||||
"rehype-raw": "^7.0.0",
|
"rehype-raw": "^7.0.0",
|
||||||
"rehype-slug": "^6.0.0",
|
"rehype-slug": "^6.0.0",
|
||||||
"remark-gfm": "^4.0.1",
|
"remark-gfm": "^4.0.1",
|
||||||
"three": "^0.183.2"
|
"reselect": "^5.3.0",
|
||||||
|
"sails.io.js": "^1.2.1",
|
||||||
|
"sass": "^1.105.1",
|
||||||
|
"semantic-ui-react": "^2.1.5",
|
||||||
|
"socket.io-client": "^4.8.4",
|
||||||
|
"three": "^0.183.2",
|
||||||
|
"validator": "^13.15.35"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
|
"@types/geojson": "^7946.0.16",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
|
|||||||
3895
pnpm-lock.yaml
generated
3895
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
72
src/app/api/work/v1/[[...path]]/route.ts
Normal file
72
src/app/api/work/v1/[[...path]]/route.ts
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/**
|
||||||
|
* Dev/prod bridge: proxy /api/work/v1 → FastAPI work_svc.
|
||||||
|
* If upstream down, fall back to in-process JSON store (offline seed).
|
||||||
|
*/
|
||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export const runtime = "nodejs";
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
const UPSTREAM = (
|
||||||
|
process.env.WORK_API_URL ||
|
||||||
|
process.env.WORK_PLANKA_ORIGIN ||
|
||||||
|
"http://127.0.0.1:8021"
|
||||||
|
).replace(/\/$/, "");
|
||||||
|
|
||||||
|
async function proxy(req: NextRequest, path: string[]) {
|
||||||
|
const suffix = path.length ? path.join("/") : "";
|
||||||
|
const url = new URL(req.url);
|
||||||
|
const target = `${UPSTREAM}/api/work/v1/${suffix}${url.search}`;
|
||||||
|
try {
|
||||||
|
const headers = new Headers(req.headers);
|
||||||
|
headers.delete("host");
|
||||||
|
const init: RequestInit = {
|
||||||
|
method: req.method,
|
||||||
|
headers,
|
||||||
|
redirect: "manual",
|
||||||
|
};
|
||||||
|
if (req.method !== "GET" && req.method !== "HEAD") {
|
||||||
|
init.body = await req.text();
|
||||||
|
}
|
||||||
|
const res = await fetch(target, init);
|
||||||
|
const body = await res.arrayBuffer();
|
||||||
|
return new NextResponse(body, {
|
||||||
|
status: res.status,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": res.headers.get("Content-Type") || "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
ok: false,
|
||||||
|
error: "work_api_unreachable",
|
||||||
|
hint: "Start FastAPI: cd apps/api && python -m uvicorn work_main:app --port 8021",
|
||||||
|
},
|
||||||
|
{ status: 503 },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Ctx = { params: Promise<{ path?: string[] }> };
|
||||||
|
|
||||||
|
export async function GET(req: NextRequest, ctx: Ctx) {
|
||||||
|
const { path = [] } = await ctx.params;
|
||||||
|
return proxy(req, path);
|
||||||
|
}
|
||||||
|
export async function POST(req: NextRequest, ctx: Ctx) {
|
||||||
|
const { path = [] } = await ctx.params;
|
||||||
|
return proxy(req, path);
|
||||||
|
}
|
||||||
|
export async function PUT(req: NextRequest, ctx: Ctx) {
|
||||||
|
const { path = [] } = await ctx.params;
|
||||||
|
return proxy(req, path);
|
||||||
|
}
|
||||||
|
export async function PATCH(req: NextRequest, ctx: Ctx) {
|
||||||
|
const { path = [] } = await ctx.params;
|
||||||
|
return proxy(req, path);
|
||||||
|
}
|
||||||
|
export async function DELETE(req: NextRequest, ctx: Ctx) {
|
||||||
|
const { path = [] } = await ctx.params;
|
||||||
|
return proxy(req, path);
|
||||||
|
}
|
||||||
6
src/app/social/work/app/[[...slug]]/page.tsx
Normal file
6
src/app/social/work/app/[[...slug]]/page.tsx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
/** Legacy Planka-vendor mount retired — native Next boards. */
|
||||||
|
export default function WorkAppRedirect() {
|
||||||
|
redirect("/social/work/boards");
|
||||||
|
}
|
||||||
8
src/app/social/work/boards/[id]/page.tsx
Normal file
8
src/app/social/work/boards/[id]/page.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import BoardClient from "@work/components/BoardClient";
|
||||||
|
|
||||||
|
type Props = { params: Promise<{ id: string }> };
|
||||||
|
|
||||||
|
export default async function WorkBoardPage({ params }: Props) {
|
||||||
|
const { id } = await params;
|
||||||
|
return <BoardClient boardId={id} />;
|
||||||
|
}
|
||||||
5
src/app/social/work/boards/page.tsx
Normal file
5
src/app/social/work/boards/page.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import BoardsClient from "@work/components/BoardsClient";
|
||||||
|
|
||||||
|
export default function WorkBoardsPage() {
|
||||||
|
return <BoardsClient />;
|
||||||
|
}
|
||||||
8
src/app/social/work/pads/[id]/page.tsx
Normal file
8
src/app/social/work/pads/[id]/page.tsx
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import PadClient from "@work/components/PadClient";
|
||||||
|
|
||||||
|
type Props = { params: Promise<{ id: string }> };
|
||||||
|
|
||||||
|
export default async function WorkPadPage({ params }: Props) {
|
||||||
|
const { id } = await params;
|
||||||
|
return <PadClient padId={id} />;
|
||||||
|
}
|
||||||
5
src/app/social/work/pads/page.tsx
Normal file
5
src/app/social/work/pads/page.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import PadsClient from "@work/components/PadsClient";
|
||||||
|
|
||||||
|
export default function WorkPadsPage() {
|
||||||
|
return <PadsClient />;
|
||||||
|
}
|
||||||
5
src/app/social/work/page.tsx
Normal file
5
src/app/social/work/page.tsx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import WorkClient from "@work/components/WorkClient";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return <WorkClient />;
|
||||||
|
}
|
||||||
484
src/modules/work/components/BoardClient.tsx
Normal file
484
src/modules/work/components/BoardClient.tsx
Normal file
@ -0,0 +1,484 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Kanban shell — Planka KanbanContent parity + Nomadro modular chrome.
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
DragDropContext,
|
||||||
|
Draggable,
|
||||||
|
Droppable,
|
||||||
|
type DropResult,
|
||||||
|
} from "@hello-pangea/dnd";
|
||||||
|
import {
|
||||||
|
type CSSProperties,
|
||||||
|
FormEvent,
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import { boardBackgroundCss, type BoardGradientId } from "../lib/backgrounds";
|
||||||
|
import { workApi } from "../lib/api";
|
||||||
|
import {
|
||||||
|
LIST_ACCENT_COLORS,
|
||||||
|
type WorkBoard,
|
||||||
|
type WorkCard,
|
||||||
|
} from "../lib/types";
|
||||||
|
import ActivityPanel from "./board/ActivityPanel";
|
||||||
|
import BoardChrome from "./board/BoardChrome";
|
||||||
|
import KanbanCard from "./board/KanbanCard";
|
||||||
|
import ListMenu from "./board/ListMenu";
|
||||||
|
import CardModal from "./CardModal";
|
||||||
|
import "./planka-board.css";
|
||||||
|
|
||||||
|
export default function BoardClient({ boardId }: { boardId: string }) {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
const [board, setBoard] = useState<WorkBoard | null>(null);
|
||||||
|
const [err, setErr] = useState("");
|
||||||
|
const [addingList, setAddingList] = useState(false);
|
||||||
|
const [listTitle, setListTitle] = useState("");
|
||||||
|
const [addingCardFor, setAddingCardFor] = useState<string | null>(null);
|
||||||
|
const [cardDraft, setCardDraft] = useState("");
|
||||||
|
const [activeCardId, setActiveCardId] = useState<string | null>(null);
|
||||||
|
const [menuListId, setMenuListId] = useState<string | null>(null);
|
||||||
|
const [renameDraft, setRenameDraft] = useState("");
|
||||||
|
const [showActivity, setShowActivity] = useState(true);
|
||||||
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const data = await workApi.board(boardId);
|
||||||
|
setBoard(data.board);
|
||||||
|
setErr("");
|
||||||
|
} catch {
|
||||||
|
setErr(zh ? "看板加载失败 — 确认 FastAPI :8021" : "Board load failed");
|
||||||
|
}
|
||||||
|
}, [boardId, zh]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function onKey(e: KeyboardEvent) {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
setMenuListId(null);
|
||||||
|
setShowSettings(false);
|
||||||
|
setActiveCardId(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.addEventListener("keydown", onKey);
|
||||||
|
return () => window.removeEventListener("keydown", onKey);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const lists = useMemo(
|
||||||
|
() => [...(board?.lists || [])].sort((a, b) => a.position - b.position),
|
||||||
|
[board?.lists],
|
||||||
|
);
|
||||||
|
|
||||||
|
const labelsById = useMemo(() => {
|
||||||
|
const m = new Map((board?.labels || []).map((l) => [l.id, l]));
|
||||||
|
return m;
|
||||||
|
}, [board?.labels]);
|
||||||
|
|
||||||
|
const labelsForCard = useCallback(
|
||||||
|
(cardId: string) =>
|
||||||
|
(board?.card_labels || [])
|
||||||
|
.filter((x) => x.card_id === cardId)
|
||||||
|
.map((x) => labelsById.get(x.label_id))
|
||||||
|
.filter(Boolean),
|
||||||
|
[board?.card_labels, labelsById],
|
||||||
|
);
|
||||||
|
|
||||||
|
const membersForCard = useCallback(
|
||||||
|
(cardId: string) =>
|
||||||
|
(board?.card_members || []).filter((m) => m.card_id === cardId),
|
||||||
|
[board?.card_members],
|
||||||
|
);
|
||||||
|
|
||||||
|
const taskProgress = useCallback(
|
||||||
|
(cardId: string) => {
|
||||||
|
const tls = (board?.task_lists || []).filter((t) => t.card_id === cardId);
|
||||||
|
const ids = new Set(tls.map((t) => t.id));
|
||||||
|
const tasks = (board?.tasks || []).filter((t) => ids.has(t.task_list_id));
|
||||||
|
if (!tasks.length) return null;
|
||||||
|
const done = tasks.filter((t) => t.is_completed).length;
|
||||||
|
return { done, total: tasks.length };
|
||||||
|
},
|
||||||
|
[board?.task_lists, board?.tasks],
|
||||||
|
);
|
||||||
|
|
||||||
|
const commentCount = useCallback(
|
||||||
|
(cardId: string) =>
|
||||||
|
(board?.comments || []).filter((c) => c.card_id === cardId).length,
|
||||||
|
[board?.comments],
|
||||||
|
);
|
||||||
|
|
||||||
|
const activeCard: WorkCard | null = useMemo(() => {
|
||||||
|
if (!activeCardId || !board) return null;
|
||||||
|
return board.cards.find((c) => c.id === activeCardId) || null;
|
||||||
|
}, [activeCardId, board]);
|
||||||
|
|
||||||
|
const showCounter = Boolean(board?.show_card_counter ?? true);
|
||||||
|
|
||||||
|
async function onDragEnd(result: DropResult) {
|
||||||
|
if (!result.destination || !board) return;
|
||||||
|
const { source, destination, draggableId, type } = result;
|
||||||
|
if (
|
||||||
|
source.droppableId === destination.droppableId &&
|
||||||
|
source.index === destination.index
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "LIST") {
|
||||||
|
const listId = draggableId.replace(/^list:/, "");
|
||||||
|
const data = await workApi.moveList(boardId, listId, destination.index);
|
||||||
|
setBoard(data.board);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "CARD") {
|
||||||
|
const listId = destination.droppableId.replace(/^list:/, "");
|
||||||
|
const cardId = draggableId.replace(/^card:/, "");
|
||||||
|
const data = await workApi.moveCard(
|
||||||
|
boardId,
|
||||||
|
cardId,
|
||||||
|
listId,
|
||||||
|
destination.index,
|
||||||
|
);
|
||||||
|
setBoard(data.board);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitList(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!listTitle.trim()) return;
|
||||||
|
const data = await workApi.addList(boardId, listTitle.trim());
|
||||||
|
setBoard(data.board);
|
||||||
|
setListTitle("");
|
||||||
|
setAddingList(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitCard(listId: string, e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!cardDraft.trim()) return;
|
||||||
|
const data = await workApi.addCard(boardId, listId, cardDraft.trim());
|
||||||
|
setBoard(data.board);
|
||||||
|
setCardDraft("");
|
||||||
|
setAddingCardFor(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveListName(listId: string) {
|
||||||
|
if (!renameDraft.trim()) return;
|
||||||
|
const data = await workApi.updateList(boardId, listId, {
|
||||||
|
name: renameDraft.trim(),
|
||||||
|
});
|
||||||
|
setBoard(data.board);
|
||||||
|
setMenuListId(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setListColor(listId: string, color: string) {
|
||||||
|
const data = await workApi.updateList(boardId, listId, { color });
|
||||||
|
setBoard(data.board);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeList(listId: string) {
|
||||||
|
if (
|
||||||
|
!window.confirm(
|
||||||
|
zh ? "删除列表及其中全部卡片?" : "Delete list and all its cards?",
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await workApi.deleteList(boardId, listId);
|
||||||
|
setBoard(data.board);
|
||||||
|
setMenuListId(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pickGradient(id: BoardGradientId) {
|
||||||
|
const data = await workApi.updateBoard(boardId, {
|
||||||
|
background_gradient: id,
|
||||||
|
});
|
||||||
|
setBoard(data.board);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="planka-board"
|
||||||
|
id="app"
|
||||||
|
style={{
|
||||||
|
background: boardBackgroundCss(board?.background_gradient),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<BoardChrome
|
||||||
|
zh={zh}
|
||||||
|
boardName={board?.name || ""}
|
||||||
|
gradientId={board?.background_gradient}
|
||||||
|
showActivity={showActivity}
|
||||||
|
showSettings={showSettings}
|
||||||
|
onToggleActivity={() => setShowActivity((v) => !v)}
|
||||||
|
onToggleSettings={() => setShowSettings((v) => !v)}
|
||||||
|
onPickGradient={(id) => void pickGradient(id)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{err ? (
|
||||||
|
<p style={{ color: "#f87171", padding: "12px 20px" }}>{err}</p>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<div className="planka-board-body">
|
||||||
|
<div
|
||||||
|
className="planka-kanban-wrap"
|
||||||
|
onClick={() => {
|
||||||
|
setMenuListId(null);
|
||||||
|
setShowSettings(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
|
<Droppable
|
||||||
|
droppableId="board-lists"
|
||||||
|
type="LIST"
|
||||||
|
direction="horizontal"
|
||||||
|
>
|
||||||
|
{(boardProvided) => (
|
||||||
|
<div
|
||||||
|
className="planka-lists"
|
||||||
|
ref={boardProvided.innerRef}
|
||||||
|
{...boardProvided.droppableProps}
|
||||||
|
>
|
||||||
|
{lists.map((list, listIndex) => {
|
||||||
|
const cards = (board?.cards || [])
|
||||||
|
.filter((c) => c.list_id === list.id)
|
||||||
|
.sort((a, b) => a.position - b.position);
|
||||||
|
const accent =
|
||||||
|
list.color ||
|
||||||
|
LIST_ACCENT_COLORS[listIndex % LIST_ACCENT_COLORS.length];
|
||||||
|
const isArchive = list.type === "archive";
|
||||||
|
return (
|
||||||
|
<Draggable
|
||||||
|
key={list.id}
|
||||||
|
draggableId={`list:${list.id}`}
|
||||||
|
index={listIndex}
|
||||||
|
>
|
||||||
|
{(listDrag) => (
|
||||||
|
<div
|
||||||
|
className={`planka-list${isArchive ? " planka-list-archive" : ""}`}
|
||||||
|
ref={listDrag.innerRef}
|
||||||
|
{...listDrag.draggableProps}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="planka-list-outer"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"--list-accent": accent,
|
||||||
|
} as CSSProperties
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="planka-list-accent" />
|
||||||
|
<div className="planka-list-header">
|
||||||
|
<h2
|
||||||
|
className="planka-list-name"
|
||||||
|
{...listDrag.dragHandleProps}
|
||||||
|
>
|
||||||
|
{list.name}
|
||||||
|
{isArchive ? (
|
||||||
|
<span className="planka-list-tag">
|
||||||
|
archive
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</h2>
|
||||||
|
{showCounter ? (
|
||||||
|
<span className="planka-list-count">
|
||||||
|
{cards.length}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{!isArchive ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-list-menu-btn"
|
||||||
|
aria-label="List menu"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
setMenuListId((id) =>
|
||||||
|
id === list.id ? null : list.id,
|
||||||
|
);
|
||||||
|
setRenameDraft(list.name);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
···
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
{menuListId === list.id ? (
|
||||||
|
<ListMenu
|
||||||
|
zh={zh}
|
||||||
|
renameDraft={renameDraft}
|
||||||
|
accent={accent}
|
||||||
|
onRenameDraft={setRenameDraft}
|
||||||
|
onSaveName={() =>
|
||||||
|
void saveListName(list.id)
|
||||||
|
}
|
||||||
|
onColor={(c) =>
|
||||||
|
void setListColor(list.id, c)
|
||||||
|
}
|
||||||
|
onDelete={() => void removeList(list.id)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="planka-cards-outer">
|
||||||
|
<Droppable
|
||||||
|
droppableId={`list:${list.id}`}
|
||||||
|
type="CARD"
|
||||||
|
>
|
||||||
|
{(provided) => (
|
||||||
|
<div
|
||||||
|
className="planka-cards-inner"
|
||||||
|
ref={provided.innerRef}
|
||||||
|
{...provided.droppableProps}
|
||||||
|
>
|
||||||
|
{cards.map((card, index) => (
|
||||||
|
<KanbanCard
|
||||||
|
key={card.id}
|
||||||
|
card={card}
|
||||||
|
index={index}
|
||||||
|
labels={labelsForCard(card.id)}
|
||||||
|
members={membersForCard(card.id)}
|
||||||
|
taskProgress={taskProgress(card.id)}
|
||||||
|
commentCount={commentCount(card.id)}
|
||||||
|
onOpen={() =>
|
||||||
|
setActiveCardId(card.id)
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{provided.placeholder}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Droppable>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!isArchive ? (
|
||||||
|
addingCardFor === list.id ? (
|
||||||
|
<form
|
||||||
|
className="planka-add-card-form"
|
||||||
|
onSubmit={(e) => submitCard(list.id, e)}
|
||||||
|
>
|
||||||
|
<textarea
|
||||||
|
rows={3}
|
||||||
|
autoFocus
|
||||||
|
value={cardDraft}
|
||||||
|
onChange={(e) =>
|
||||||
|
setCardDraft(e.target.value)
|
||||||
|
}
|
||||||
|
placeholder={
|
||||||
|
zh ? "输入标题…" : "Enter a title…"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<div className="planka-add-card-actions">
|
||||||
|
<button
|
||||||
|
className="planka-btn-primary"
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
{zh ? "添加卡片" : "Add card"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-ghost"
|
||||||
|
onClick={() => {
|
||||||
|
setAddingCardFor(null);
|
||||||
|
setCardDraft("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<div className="planka-add-card">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-add-card-btn"
|
||||||
|
onClick={() => {
|
||||||
|
setAddingCardFor(list.id);
|
||||||
|
setCardDraft("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
+{" "}
|
||||||
|
{zh
|
||||||
|
? "添加另一张卡片"
|
||||||
|
: "Add another card"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Draggable>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
{boardProvided.placeholder}
|
||||||
|
|
||||||
|
<div className="planka-add-list">
|
||||||
|
{addingList ? (
|
||||||
|
<form
|
||||||
|
className="planka-add-list-form"
|
||||||
|
onSubmit={submitList}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
autoFocus
|
||||||
|
value={listTitle}
|
||||||
|
onChange={(e) => setListTitle(e.target.value)}
|
||||||
|
placeholder={
|
||||||
|
zh ? "输入列表标题…" : "Enter list title…"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<div className="planka-add-card-actions">
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "添加列表" : "Add list"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-ghost"
|
||||||
|
onClick={() => {
|
||||||
|
setAddingList(false);
|
||||||
|
setListTitle("");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-add-list-btn"
|
||||||
|
onClick={() => setAddingList(true)}
|
||||||
|
>
|
||||||
|
+ {zh ? "添加另一个列表" : "Add another list"}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Droppable>
|
||||||
|
</DragDropContext>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showActivity ? (
|
||||||
|
<ActivityPanel zh={zh} activities={board?.activities || []} />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{activeCard && board ? (
|
||||||
|
<CardModal
|
||||||
|
key={activeCard.id}
|
||||||
|
boardId={boardId}
|
||||||
|
board={board}
|
||||||
|
card={activeCard}
|
||||||
|
zh={zh}
|
||||||
|
onClose={() => setActiveCardId(null)}
|
||||||
|
onBoard={setBoard}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
151
src/modules/work/components/BoardsClient.tsx
Normal file
151
src/modules/work/components/BoardsClient.tsx
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { FormEvent, useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import SiteShell from "@social/components/SiteShell";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import { socialTx } from "@social/lib/socialTx";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import { boardBackgroundCss } from "../lib/backgrounds";
|
||||||
|
import { workApi } from "../lib/api";
|
||||||
|
import type { WorkBoard, WorkProject } from "../lib/types";
|
||||||
|
import "./work.css";
|
||||||
|
|
||||||
|
export default function BoardsClient() {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
const [projects, setProjects] = useState<WorkProject[]>([]);
|
||||||
|
const [boards, setBoards] = useState<WorkBoard[]>([]);
|
||||||
|
const [name, setName] = useState("");
|
||||||
|
const [err, setErr] = useState("");
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const [p, b] = await Promise.all([workApi.projects(), workApi.boards()]);
|
||||||
|
setProjects(p.projects || []);
|
||||||
|
setBoards(b.boards || []);
|
||||||
|
setErr("");
|
||||||
|
} catch {
|
||||||
|
setErr(
|
||||||
|
zh
|
||||||
|
? "无法连接 work API。请先启动 pnpm dev:work-api"
|
||||||
|
: "Work API unreachable — run pnpm dev:work-api",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [zh]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
const projectName = useMemo(() => {
|
||||||
|
const m = new Map(projects.map((p) => [p.id, p.name]));
|
||||||
|
return (id: string) => m.get(id) || "";
|
||||||
|
}, [projects]);
|
||||||
|
|
||||||
|
async function onCreate(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!name.trim() || busy) return;
|
||||||
|
setBusy(true);
|
||||||
|
try {
|
||||||
|
const { project } = await workApi.createProject(name.trim());
|
||||||
|
setName("");
|
||||||
|
await load();
|
||||||
|
if (project.board_id) {
|
||||||
|
window.location.href = socialPath(`/work/boards/${project.board_id}`);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setErr(zh ? "创建失败" : "Create failed");
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SiteShell title={socialTx("看板协作")}>
|
||||||
|
<div className="work-landing work-subpage">
|
||||||
|
<header className="work-subhead">
|
||||||
|
<p className="work-landing-brand work-sub-brand">
|
||||||
|
<Link href={socialPath("/work")}>Nomadro <span>Work</span></Link>
|
||||||
|
</p>
|
||||||
|
<h1>{zh ? "看板协作" : "Kanban boards"}</h1>
|
||||||
|
<p className="work-landing-lead">
|
||||||
|
{zh
|
||||||
|
? "新建项目即开看板;拖拽、标签、清单、成员与活动流都在里面。"
|
||||||
|
: "Create a project to open a board — drag, labels, checklists, members & activity inside."}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<form className="work-create-bar" onSubmit={onCreate}>
|
||||||
|
<input
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
placeholder={
|
||||||
|
zh ? "新项目名称(自动建看板)" : "New project name"
|
||||||
|
}
|
||||||
|
aria-label={zh ? "项目名称" : "Project name"}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="work-landing-btn work-landing-btn-primary"
|
||||||
|
type="submit"
|
||||||
|
disabled={busy}
|
||||||
|
>
|
||||||
|
{zh ? "新建项目" : "Create project"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{err ? <p className="work-err">{err}</p> : null}
|
||||||
|
|
||||||
|
<div className="work-sub-toolbar">
|
||||||
|
<h2>
|
||||||
|
{zh ? "我的看板" : "Your boards"}
|
||||||
|
<span>{boards.length}</span>
|
||||||
|
</h2>
|
||||||
|
<Link className="work-sub-link" href={socialPath("/work/pads")}>
|
||||||
|
{zh ? "文档 →" : "Pads →"}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{boards.length === 0 && !err ? (
|
||||||
|
<p className="work-empty-hint">
|
||||||
|
{zh
|
||||||
|
? "还没有看板 — 在上方输入名称创建第一个项目。"
|
||||||
|
: "No boards yet — create your first project above."}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="work-board-grid">
|
||||||
|
{boards.map((b) => (
|
||||||
|
<li key={b.id}>
|
||||||
|
<Link
|
||||||
|
href={socialPath(`/work/boards/${b.id}`)}
|
||||||
|
className="work-board-tile"
|
||||||
|
style={{
|
||||||
|
background: boardBackgroundCss(b.background_gradient),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="work-board-tile-glow" aria-hidden />
|
||||||
|
<strong>{b.name}</strong>
|
||||||
|
<span className="work-board-tile-meta">
|
||||||
|
{projectName(b.project_id) || b.default_view}
|
||||||
|
</span>
|
||||||
|
<time dateTime={b.updated_at}>
|
||||||
|
{new Date(b.updated_at).toLocaleString(
|
||||||
|
zh ? "zh-CN" : "en-US",
|
||||||
|
{
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</time>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</SiteShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
485
src/modules/work/components/CardModal.tsx
Normal file
485
src/modules/work/components/CardModal.tsx
Normal file
@ -0,0 +1,485 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Card detail — Planka CardModal/ProjectContent sections:
|
||||||
|
* cover, labels, due (+ completed), stopwatch, members, checklist,
|
||||||
|
* attachments (URL), comments, archive / delete.
|
||||||
|
*/
|
||||||
|
import { FormEvent, useEffect, useMemo, useState } from "react";
|
||||||
|
import { CARD_COVER_COLORS } from "../lib/backgrounds";
|
||||||
|
import { workApi } from "../lib/api";
|
||||||
|
import {
|
||||||
|
formatStopwatch,
|
||||||
|
isRunning,
|
||||||
|
type Stopwatch,
|
||||||
|
} from "../lib/stopwatch";
|
||||||
|
import {
|
||||||
|
PLANKA_LABEL_COLORS,
|
||||||
|
type WorkBoard,
|
||||||
|
type WorkCard,
|
||||||
|
type WorkLabel,
|
||||||
|
} from "../lib/types";
|
||||||
|
import "./planka-board.css";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
boardId: string;
|
||||||
|
board: WorkBoard;
|
||||||
|
card: WorkCard;
|
||||||
|
zh: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onBoard: (b: WorkBoard) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
function initials(name: string) {
|
||||||
|
return name
|
||||||
|
.split(/\s+/)
|
||||||
|
.map((p) => p[0])
|
||||||
|
.join("")
|
||||||
|
.slice(0, 2)
|
||||||
|
.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CardModal({
|
||||||
|
boardId,
|
||||||
|
board,
|
||||||
|
card,
|
||||||
|
zh,
|
||||||
|
onClose,
|
||||||
|
onBoard,
|
||||||
|
}: Props) {
|
||||||
|
const [name, setName] = useState(card.name);
|
||||||
|
const [desc, setDesc] = useState(card.description || "");
|
||||||
|
const [due, setDue] = useState(card.due_date?.slice(0, 10) || "");
|
||||||
|
const [taskName, setTaskName] = useState("");
|
||||||
|
const [comment, setComment] = useState("");
|
||||||
|
const [author, setAuthor] = useState("guest");
|
||||||
|
const [memberName, setMemberName] = useState("");
|
||||||
|
const [attName, setAttName] = useState("");
|
||||||
|
const [attUrl, setAttUrl] = useState("");
|
||||||
|
const [tick, setTick] = useState(0);
|
||||||
|
|
||||||
|
const liveCard =
|
||||||
|
board.cards.find((c) => c.id === card.id) || card;
|
||||||
|
const sw = liveCard.stopwatch as Stopwatch | null | undefined;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isRunning(sw)) return;
|
||||||
|
const t = setInterval(() => setTick((n) => n + 1), 1000);
|
||||||
|
return () => clearInterval(t);
|
||||||
|
}, [sw?.startedAt]);
|
||||||
|
|
||||||
|
const labels = board.labels || [];
|
||||||
|
const cardLabelIds = useMemo(
|
||||||
|
() =>
|
||||||
|
new Set(
|
||||||
|
(board.card_labels || [])
|
||||||
|
.filter((x) => x.card_id === card.id)
|
||||||
|
.map((x) => x.label_id),
|
||||||
|
),
|
||||||
|
[board.card_labels, card.id],
|
||||||
|
);
|
||||||
|
const members = (board.card_members || []).filter(
|
||||||
|
(m) => m.card_id === card.id,
|
||||||
|
);
|
||||||
|
const attachments = (board.attachments || []).filter(
|
||||||
|
(a) => a.card_id === card.id,
|
||||||
|
);
|
||||||
|
const taskLists = (board.task_lists || []).filter(
|
||||||
|
(t) => t.card_id === card.id,
|
||||||
|
);
|
||||||
|
const tasks = board.tasks || [];
|
||||||
|
const comments = (board.comments || []).filter((c) => c.card_id === card.id);
|
||||||
|
const dueDone = Boolean(liveCard.is_due_completed);
|
||||||
|
|
||||||
|
async function saveMeta(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
const data = await workApi.updateCard(boardId, card.id, {
|
||||||
|
name,
|
||||||
|
description: desc,
|
||||||
|
due_date: due || undefined,
|
||||||
|
clear_due: !due,
|
||||||
|
});
|
||||||
|
onBoard(data.board);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function toggleLabel(label: WorkLabel) {
|
||||||
|
const data = await workApi.toggleLabel(boardId, card.id, label.id);
|
||||||
|
onBoard(data.board);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setCover(color: string | null) {
|
||||||
|
const data = await workApi.updateCard(
|
||||||
|
boardId,
|
||||||
|
card.id,
|
||||||
|
color
|
||||||
|
? { cover_color: color }
|
||||||
|
: { clear_cover: true },
|
||||||
|
);
|
||||||
|
onBoard(data.board);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addTask(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!taskName.trim()) return;
|
||||||
|
const data = await workApi.addTask(boardId, card.id, taskName.trim());
|
||||||
|
onBoard(data.board);
|
||||||
|
setTaskName("");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addComment(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!comment.trim()) return;
|
||||||
|
const data = await workApi.addComment(
|
||||||
|
boardId,
|
||||||
|
card.id,
|
||||||
|
comment.trim(),
|
||||||
|
author || "guest",
|
||||||
|
);
|
||||||
|
onBoard(data.board);
|
||||||
|
setComment("");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addMember(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!memberName.trim()) return;
|
||||||
|
const data = await workApi.toggleMember(
|
||||||
|
boardId,
|
||||||
|
card.id,
|
||||||
|
memberName.trim(),
|
||||||
|
);
|
||||||
|
onBoard(data.board);
|
||||||
|
setMemberName("");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addAttachment(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!attUrl.trim()) return;
|
||||||
|
const data = await workApi.addAttachment(
|
||||||
|
boardId,
|
||||||
|
card.id,
|
||||||
|
attName.trim() || "Link",
|
||||||
|
attUrl.trim(),
|
||||||
|
);
|
||||||
|
onBoard(data.board);
|
||||||
|
setAttName("");
|
||||||
|
setAttUrl("");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeCard() {
|
||||||
|
if (!window.confirm(zh ? "确定删除这张卡片?" : "Delete this card?")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await workApi.deleteCard(boardId, card.id);
|
||||||
|
onBoard(data.board);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function archive() {
|
||||||
|
const data = await workApi.archiveCard(boardId, card.id);
|
||||||
|
onBoard(data.board);
|
||||||
|
onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="planka-modal-backdrop"
|
||||||
|
onClick={onClose}
|
||||||
|
role="presentation"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="planka-modal planka-modal-wide"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
role="dialog"
|
||||||
|
aria-modal
|
||||||
|
>
|
||||||
|
{liveCard.cover_color ? (
|
||||||
|
<div
|
||||||
|
className="planka-modal-cover"
|
||||||
|
style={{ background: liveCard.cover_color }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<form onSubmit={saveMeta}>
|
||||||
|
<input
|
||||||
|
className="planka-modal-title"
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
|
||||||
|
<label>{zh ? "封面" : "Cover"}</label>
|
||||||
|
<div className="planka-label-row">
|
||||||
|
{CARD_COVER_COLORS.map((c) => (
|
||||||
|
<button
|
||||||
|
key={c}
|
||||||
|
type="button"
|
||||||
|
className={`planka-cover-swatch${liveCard.cover_color === c ? " on" : ""}`}
|
||||||
|
style={{ background: c }}
|
||||||
|
onClick={() => void setCover(c)}
|
||||||
|
aria-label={c}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-ghost"
|
||||||
|
style={{ fontSize: 12 }}
|
||||||
|
onClick={() => void setCover(null)}
|
||||||
|
>
|
||||||
|
{zh ? "清除" : "Clear"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label>{zh ? "标签" : "Labels"}</label>
|
||||||
|
<div className="planka-label-row">
|
||||||
|
{labels.map((lb) => {
|
||||||
|
const on = cardLabelIds.has(lb.id);
|
||||||
|
const bg = PLANKA_LABEL_COLORS[lb.color] || "#888";
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={lb.id}
|
||||||
|
type="button"
|
||||||
|
className={`planka-label-chip${on ? " on" : ""}`}
|
||||||
|
style={{ background: bg }}
|
||||||
|
onClick={() => void toggleLabel(lb)}
|
||||||
|
>
|
||||||
|
{lb.name || lb.color}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label>{zh ? "截止日期" : "Due date"}</label>
|
||||||
|
<div className="planka-inline-form" style={{ marginBottom: 8 }}>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={due}
|
||||||
|
onChange={(e) => setDue(e.target.value)}
|
||||||
|
/>
|
||||||
|
<label className="planka-check-inline">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={dueDone}
|
||||||
|
onChange={() =>
|
||||||
|
void workApi
|
||||||
|
.updateCard(boardId, card.id, {
|
||||||
|
is_due_completed: !dueDone,
|
||||||
|
})
|
||||||
|
.then((d) => onBoard(d.board))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{zh ? "已完成" : "Completed"}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label>{zh ? "秒表" : "Stopwatch"}</label>
|
||||||
|
<div className="planka-stopwatch-row">
|
||||||
|
<span
|
||||||
|
className={`planka-stopwatch-chip${isRunning(sw) ? " on" : ""}`}
|
||||||
|
>
|
||||||
|
⏱ {formatStopwatch(sw)}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-primary"
|
||||||
|
onClick={() =>
|
||||||
|
void workApi
|
||||||
|
.toggleStopwatch(boardId, card.id)
|
||||||
|
.then((d) => onBoard(d.board))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{isRunning(sw)
|
||||||
|
? zh
|
||||||
|
? "暂停"
|
||||||
|
: "Pause"
|
||||||
|
: zh
|
||||||
|
? "开始"
|
||||||
|
: "Start"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label>{zh ? "描述" : "Description"}</label>
|
||||||
|
<textarea
|
||||||
|
rows={5}
|
||||||
|
value={desc}
|
||||||
|
onChange={(e) => setDesc(e.target.value)}
|
||||||
|
placeholder={
|
||||||
|
zh ? "添加更详细的说明…" : "Add a more detailed description…"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<div className="planka-modal-actions">
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "保存" : "Save"}
|
||||||
|
</button>
|
||||||
|
<button type="button" className="planka-btn-ghost" onClick={onClose}>
|
||||||
|
{zh ? "关闭" : "Close"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-ghost"
|
||||||
|
onClick={() => void archive()}
|
||||||
|
>
|
||||||
|
{zh ? "归档" : "Archive"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-danger"
|
||||||
|
onClick={() => void removeCard()}
|
||||||
|
style={{ marginLeft: "auto" }}
|
||||||
|
>
|
||||||
|
{zh ? "删除卡片" : "Delete card"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<section className="planka-modal-section">
|
||||||
|
<h3>{zh ? "成员" : "Members"}</h3>
|
||||||
|
<div className="planka-members-row">
|
||||||
|
{members.map((m) => (
|
||||||
|
<button
|
||||||
|
key={m.name}
|
||||||
|
type="button"
|
||||||
|
className="planka-member-pill"
|
||||||
|
title={zh ? "点击移除" : "Click to remove"}
|
||||||
|
onClick={() =>
|
||||||
|
void workApi
|
||||||
|
.toggleMember(boardId, card.id, m.name)
|
||||||
|
.then((d) => onBoard(d.board))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<span className="av">{initials(m.name)}</span>
|
||||||
|
{m.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<form
|
||||||
|
className="planka-inline-form"
|
||||||
|
onSubmit={addMember}
|
||||||
|
style={{ marginTop: 10 }}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
value={memberName}
|
||||||
|
onChange={(e) => setMemberName(e.target.value)}
|
||||||
|
placeholder={zh ? "添加成员昵称…" : "Add member name…"}
|
||||||
|
/>
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "添加" : "Add"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="planka-modal-section">
|
||||||
|
<h3>{zh ? "检查清单" : "Checklist"}</h3>
|
||||||
|
{taskLists.map((tl) => (
|
||||||
|
<ul key={tl.id} className="planka-tasks">
|
||||||
|
{tasks
|
||||||
|
.filter((t) => t.task_list_id === tl.id)
|
||||||
|
.map((t) => (
|
||||||
|
<li key={t.id}>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={Boolean(t.is_completed)}
|
||||||
|
onChange={() =>
|
||||||
|
void workApi
|
||||||
|
.toggleTask(boardId, t.id)
|
||||||
|
.then((d) => onBoard(d.board))
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<span className={t.is_completed ? "done" : ""}>
|
||||||
|
{t.name}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
))}
|
||||||
|
<form className="planka-inline-form" onSubmit={addTask}>
|
||||||
|
<input
|
||||||
|
value={taskName}
|
||||||
|
onChange={(e) => setTaskName(e.target.value)}
|
||||||
|
placeholder={zh ? "添加任务…" : "Add an item…"}
|
||||||
|
/>
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "添加" : "Add"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="planka-modal-section">
|
||||||
|
<h3>{zh ? "附件链接" : "Attachments"}</h3>
|
||||||
|
<ul className="planka-attachments">
|
||||||
|
{attachments.map((a) => (
|
||||||
|
<li key={a.id}>
|
||||||
|
<a href={a.url} target="_blank" rel="noreferrer">
|
||||||
|
{a.name}
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-ghost"
|
||||||
|
onClick={() =>
|
||||||
|
void workApi
|
||||||
|
.deleteAttachment(boardId, a.id)
|
||||||
|
.then((d) => onBoard(d.board))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<form className="planka-inline-form" onSubmit={addAttachment}>
|
||||||
|
<input
|
||||||
|
value={attName}
|
||||||
|
onChange={(e) => setAttName(e.target.value)}
|
||||||
|
placeholder={zh ? "名称" : "Name"}
|
||||||
|
style={{ maxWidth: 120 }}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={attUrl}
|
||||||
|
onChange={(e) => setAttUrl(e.target.value)}
|
||||||
|
placeholder="https://"
|
||||||
|
/>
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "添加" : "Add"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="planka-modal-section">
|
||||||
|
<h3>{zh ? "评论" : "Comments"}</h3>
|
||||||
|
<ul className="planka-comments">
|
||||||
|
{comments.map((c) => (
|
||||||
|
<li key={c.id}>
|
||||||
|
<b>{c.author}</b>
|
||||||
|
<time dateTime={c.created_at}>
|
||||||
|
{new Date(c.created_at).toLocaleString(
|
||||||
|
zh ? "zh-CN" : "en-US",
|
||||||
|
)}
|
||||||
|
</time>
|
||||||
|
<p>{c.text}</p>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<form className="planka-inline-form" onSubmit={addComment}>
|
||||||
|
<input
|
||||||
|
value={author}
|
||||||
|
onChange={(e) => setAuthor(e.target.value)}
|
||||||
|
placeholder={zh ? "昵称" : "Author"}
|
||||||
|
style={{ maxWidth: 120 }}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={comment}
|
||||||
|
onChange={(e) => setComment(e.target.value)}
|
||||||
|
placeholder={zh ? "写评论…" : "Write a comment…"}
|
||||||
|
/>
|
||||||
|
<button className="planka-btn-primary" type="submit">
|
||||||
|
{zh ? "发送" : "Send"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
117
src/modules/work/components/PadClient.tsx
Normal file
117
src/modules/work/components/PadClient.tsx
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import { workApi } from "../lib/api";
|
||||||
|
import type { WorkPad } from "../lib/types";
|
||||||
|
import "./etherpad-pad.css";
|
||||||
|
|
||||||
|
const AUTHOR_KEY = "nomadro.work.pad.author";
|
||||||
|
|
||||||
|
export default function PadClient({ padId }: { padId: string }) {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
const [pad, setPad] = useState<WorkPad | null>(null);
|
||||||
|
const [text, setText] = useState("");
|
||||||
|
const [author, setAuthor] = useState("guest");
|
||||||
|
const [status, setStatus] = useState("");
|
||||||
|
const dirty = useRef(false);
|
||||||
|
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
try {
|
||||||
|
const a = localStorage.getItem(AUTHOR_KEY);
|
||||||
|
if (a) setAuthor(a);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
const data = await workApi.pad(padId);
|
||||||
|
setPad(data.pad);
|
||||||
|
if (!dirty.current) setText(data.pad.text);
|
||||||
|
}, [padId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load().catch(() => setStatus(zh ? "加载失败" : "Load failed"));
|
||||||
|
const t = setInterval(() => {
|
||||||
|
if (!dirty.current) void load().catch(() => undefined);
|
||||||
|
}, 4000);
|
||||||
|
return () => clearInterval(t);
|
||||||
|
}, [load, zh]);
|
||||||
|
|
||||||
|
const persist = useCallback(
|
||||||
|
async (next: string) => {
|
||||||
|
setStatus(zh ? "保存中…" : "Saving…");
|
||||||
|
try {
|
||||||
|
localStorage.setItem(AUTHOR_KEY, author);
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const data = await workApi.updatePad(padId, next, author);
|
||||||
|
setPad(data.pad);
|
||||||
|
dirty.current = false;
|
||||||
|
setStatus(zh ? "已保存" : "Saved");
|
||||||
|
} catch {
|
||||||
|
setStatus(zh ? "保存失败" : "Save failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[author, padId, zh],
|
||||||
|
);
|
||||||
|
|
||||||
|
function onChange(v: string) {
|
||||||
|
dirty.current = true;
|
||||||
|
setText(v);
|
||||||
|
if (timer.current) clearTimeout(timer.current);
|
||||||
|
timer.current = setTimeout(() => void persist(v), 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
const revisions = [...(pad?.revisions || [])].reverse().slice(0, 20);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="ep-shell">
|
||||||
|
<header className="ep-bar">
|
||||||
|
<Link href={socialPath("/work/pads")}>← Pads</Link>
|
||||||
|
<strong>{pad?.title || "…"}</strong>
|
||||||
|
<span className="ep-status">{status}</span>
|
||||||
|
<input
|
||||||
|
value={author}
|
||||||
|
onChange={(e) => setAuthor(e.target.value)}
|
||||||
|
placeholder={zh ? "昵称" : "Author"}
|
||||||
|
aria-label="author"
|
||||||
|
/>
|
||||||
|
</header>
|
||||||
|
<div className="ep-body">
|
||||||
|
<textarea
|
||||||
|
className="ep-editor"
|
||||||
|
value={text}
|
||||||
|
onChange={(e) => onChange(e.target.value)}
|
||||||
|
spellCheck={false}
|
||||||
|
/>
|
||||||
|
<aside className="ep-hist">
|
||||||
|
<h2>{zh ? "历史" : "History"}</h2>
|
||||||
|
{revisions.map((r) => (
|
||||||
|
<button
|
||||||
|
key={r.id}
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
dirty.current = true;
|
||||||
|
setText(r.text);
|
||||||
|
void persist(r.text);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<b>{r.author}</b>
|
||||||
|
<time dateTime={r.at}>
|
||||||
|
{new Date(r.at).toLocaleString(zh ? "zh-CN" : "en-US")}
|
||||||
|
</time>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
144
src/modules/work/components/PadsClient.tsx
Normal file
144
src/modules/work/components/PadsClient.tsx
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { FormEvent, useCallback, useEffect, useState } from "react";
|
||||||
|
import SiteShell from "@social/components/SiteShell";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import { socialTx } from "@social/lib/socialTx";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import { workApi } from "../lib/api";
|
||||||
|
import type { WorkPad } from "../lib/types";
|
||||||
|
import "./work.css";
|
||||||
|
|
||||||
|
export default function PadsClient() {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
const [pads, setPads] = useState<WorkPad[]>([]);
|
||||||
|
const [title, setTitle] = useState("");
|
||||||
|
const [author, setAuthor] = useState("");
|
||||||
|
const [err, setErr] = useState("");
|
||||||
|
const [busy, setBusy] = useState(false);
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const data = await workApi.pads();
|
||||||
|
setPads(data.pads || []);
|
||||||
|
setErr("");
|
||||||
|
} catch {
|
||||||
|
setErr(
|
||||||
|
zh
|
||||||
|
? "无法连接 work API。请先启动 pnpm dev:work-api"
|
||||||
|
: "Work API unreachable — run pnpm dev:work-api",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [zh]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load();
|
||||||
|
}, [load]);
|
||||||
|
|
||||||
|
async function onCreate(e: FormEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!title.trim() || busy) return;
|
||||||
|
setBusy(true);
|
||||||
|
try {
|
||||||
|
const { pad } = await workApi.createPad(title.trim(), author || "guest");
|
||||||
|
window.location.href = socialPath(`/work/pads/${pad.id}`);
|
||||||
|
} catch {
|
||||||
|
setErr(zh ? "创建失败" : "Create failed");
|
||||||
|
} finally {
|
||||||
|
setBusy(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SiteShell title={socialTx("实时文档")}>
|
||||||
|
<div className="work-landing work-subpage">
|
||||||
|
<header className="work-subhead">
|
||||||
|
<p className="work-landing-brand work-sub-brand">
|
||||||
|
<Link href={socialPath("/work")}>Nomadro <span>Work</span></Link>
|
||||||
|
</p>
|
||||||
|
<h1>{zh ? "实时文档" : "Live pads"}</h1>
|
||||||
|
<p className="work-landing-lead">
|
||||||
|
{zh
|
||||||
|
? "多人笔记、自动保存与修订历史——像 Etherpad,长在 Nomadro 里。"
|
||||||
|
: "Shared notes with autosave and revisions — Etherpad-shaped, native to Nomadro."}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<form className="work-create-bar" onSubmit={onCreate}>
|
||||||
|
<input
|
||||||
|
value={title}
|
||||||
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
|
placeholder={zh ? "文档标题" : "Pad title"}
|
||||||
|
aria-label={zh ? "文档标题" : "Pad title"}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
className="work-create-author"
|
||||||
|
value={author}
|
||||||
|
onChange={(e) => setAuthor(e.target.value)}
|
||||||
|
placeholder={zh ? "昵称" : "Author"}
|
||||||
|
aria-label={zh ? "昵称" : "Author"}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
className="work-landing-btn work-landing-btn-primary"
|
||||||
|
type="submit"
|
||||||
|
disabled={busy}
|
||||||
|
>
|
||||||
|
{zh ? "新建文档" : "Create pad"}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{err ? <p className="work-err">{err}</p> : null}
|
||||||
|
|
||||||
|
<div className="work-sub-toolbar">
|
||||||
|
<h2>
|
||||||
|
{zh ? "全部文档" : "All pads"}
|
||||||
|
<span>{pads.length}</span>
|
||||||
|
</h2>
|
||||||
|
<Link className="work-sub-link" href={socialPath("/work/boards")}>
|
||||||
|
{zh ? "看板 →" : "Boards →"}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{pads.length === 0 && !err ? (
|
||||||
|
<p className="work-empty-hint">
|
||||||
|
{zh
|
||||||
|
? "还没有文档 — 输入标题创建第一份。"
|
||||||
|
: "No pads yet — create your first one above."}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="work-pad-grid">
|
||||||
|
{pads.map((p) => (
|
||||||
|
<li key={p.id}>
|
||||||
|
<Link
|
||||||
|
href={socialPath(`/work/pads/${p.id}`)}
|
||||||
|
className="work-pad-tile"
|
||||||
|
>
|
||||||
|
<div className="work-pad-tile-lines" aria-hidden>
|
||||||
|
<em />
|
||||||
|
<em />
|
||||||
|
<em />
|
||||||
|
</div>
|
||||||
|
<strong>{p.title}</strong>
|
||||||
|
<span>{(p.authors || []).join(", ") || "—"}</span>
|
||||||
|
<time dateTime={p.updated_at}>
|
||||||
|
{new Date(p.updated_at).toLocaleString(
|
||||||
|
zh ? "zh-CN" : "en-US",
|
||||||
|
{
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
},
|
||||||
|
)}
|
||||||
|
</time>
|
||||||
|
</Link>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</SiteShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
144
src/modules/work/components/WorkClient.tsx
Normal file
144
src/modules/work/components/WorkClient.tsx
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import SiteShell from "@social/components/SiteShell";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import { socialTx } from "@social/lib/socialTx";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import "./work.css";
|
||||||
|
|
||||||
|
export default function WorkClient() {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SiteShell title={socialTx("远程工作")}>
|
||||||
|
<div className="work-landing">
|
||||||
|
<section className="work-landing-hero" aria-labelledby="work-brand">
|
||||||
|
<div className="work-landing-orb work-landing-orb-a" aria-hidden />
|
||||||
|
<div className="work-landing-orb work-landing-orb-b" aria-hidden />
|
||||||
|
<div className="work-landing-grid" aria-hidden />
|
||||||
|
|
||||||
|
<div className="work-landing-hero-main">
|
||||||
|
<p className="work-landing-brand" id="work-brand">
|
||||||
|
Nomadro <span>Work</span>
|
||||||
|
</p>
|
||||||
|
<h1 className="work-landing-title">
|
||||||
|
{zh ? "远程一起做事" : "Work together, remotely"}
|
||||||
|
</h1>
|
||||||
|
<p className="work-landing-lead">
|
||||||
|
{zh
|
||||||
|
? "看板推进任务,文档沉淀共识——同一套 Nomadro 远程协作。"
|
||||||
|
: "Kanban for momentum, pads for shared notes — one Nomadro work surface."}
|
||||||
|
</p>
|
||||||
|
<div className="work-landing-cta">
|
||||||
|
<Link
|
||||||
|
className="work-landing-btn work-landing-btn-primary"
|
||||||
|
href={socialPath("/work/boards")}
|
||||||
|
>
|
||||||
|
{zh ? "进入看板" : "Open boards"}
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
className="work-landing-btn work-landing-btn-ghost"
|
||||||
|
href={socialPath("/work/pads")}
|
||||||
|
>
|
||||||
|
{zh ? "打开文档" : "Open pads"}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="work-landing-visual" aria-hidden>
|
||||||
|
<div className="work-mini-board">
|
||||||
|
<div className="work-mini-col">
|
||||||
|
<span />
|
||||||
|
<i />
|
||||||
|
<i />
|
||||||
|
</div>
|
||||||
|
<div className="work-mini-col">
|
||||||
|
<span />
|
||||||
|
<i className="accent" />
|
||||||
|
<i />
|
||||||
|
</div>
|
||||||
|
<div className="work-mini-col">
|
||||||
|
<span />
|
||||||
|
<i />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="work-landing-entries" aria-label={zh ? "入口" : "Entries"}>
|
||||||
|
<Link
|
||||||
|
href={socialPath("/work/boards")}
|
||||||
|
className="work-entry work-entry-boards"
|
||||||
|
>
|
||||||
|
<div className="work-entry-preview" aria-hidden>
|
||||||
|
<div className="work-entry-lane">
|
||||||
|
<b />
|
||||||
|
<b />
|
||||||
|
<b />
|
||||||
|
</div>
|
||||||
|
<div className="work-entry-lane">
|
||||||
|
<b className="hot" />
|
||||||
|
<b />
|
||||||
|
</div>
|
||||||
|
<div className="work-entry-lane">
|
||||||
|
<b />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="work-entry-copy">
|
||||||
|
<h2>{zh ? "看板协作" : "Kanban boards"}</h2>
|
||||||
|
<p>
|
||||||
|
{zh
|
||||||
|
? "拖拽列与卡片、标签、清单、成员与活动流。"
|
||||||
|
: "Drag lists & cards, labels, checklists, members, activity."}
|
||||||
|
</p>
|
||||||
|
<span className="work-entry-go">
|
||||||
|
{zh ? "打开看板" : "Enter boards"} →
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
<Link
|
||||||
|
href={socialPath("/work/pads")}
|
||||||
|
className="work-entry work-entry-pads"
|
||||||
|
>
|
||||||
|
<div className="work-entry-preview work-entry-preview-pad" aria-hidden>
|
||||||
|
<div className="work-pad-lines">
|
||||||
|
<em />
|
||||||
|
<em />
|
||||||
|
<em />
|
||||||
|
<em />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="work-entry-copy">
|
||||||
|
<h2>{zh ? "实时文档" : "Live pads"}</h2>
|
||||||
|
<p>
|
||||||
|
{zh
|
||||||
|
? "多人笔记、自动保存与修订历史,随时回看。"
|
||||||
|
: "Shared notes with autosave and revision history."}
|
||||||
|
</p>
|
||||||
|
<span className="work-entry-go">
|
||||||
|
{zh ? "打开文档" : "Enter pads"} →
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</Link>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<details className="work-landing-dev">
|
||||||
|
<summary>{zh ? "开发者本地启动" : "Local developer setup"}</summary>
|
||||||
|
<ol>
|
||||||
|
<li>
|
||||||
|
<code>pnpm dev:work-api</code>
|
||||||
|
<span>{zh ? "FastAPI work_svc" : "FastAPI work_svc"}</span>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<code>pnpm dev</code>
|
||||||
|
<span>→ /social/work</span>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
|
</SiteShell>
|
||||||
|
);
|
||||||
|
}
|
||||||
66
src/modules/work/components/board/ActivityPanel.tsx
Normal file
66
src/modules/work/components/board/ActivityPanel.tsx
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { WorkActivity } from "../../lib/types";
|
||||||
|
|
||||||
|
/** Planka Action.js Types + legacy aliases */
|
||||||
|
function activityLabel(type: string, zh: boolean) {
|
||||||
|
const map: Record<string, [string, string]> = {
|
||||||
|
createCard: ["创建卡片", "Created card"],
|
||||||
|
moveCard: ["移动卡片", "Moved card"],
|
||||||
|
move_card: ["移动卡片", "Moved card"],
|
||||||
|
addMemberToCard: ["加入成员", "Added member"],
|
||||||
|
removeMemberFromCard: ["移除成员", "Removed member"],
|
||||||
|
member_toggle: ["成员变更", "Member update"],
|
||||||
|
completeTask: ["完成任务", "Completed task"],
|
||||||
|
uncompleteTask: ["取消完成", "Uncompleted task"],
|
||||||
|
comment: ["评论", "Comment"],
|
||||||
|
delete_card: ["删除卡片", "Deleted card"],
|
||||||
|
delete_list: ["删除列表", "Deleted list"],
|
||||||
|
};
|
||||||
|
const pair = map[type];
|
||||||
|
if (!pair) return type;
|
||||||
|
return zh ? pair[0] : pair[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
zh: boolean;
|
||||||
|
activities: WorkActivity[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ActivityPanel({ zh, activities }: Props) {
|
||||||
|
return (
|
||||||
|
<aside className="planka-activity">
|
||||||
|
<h2>{zh ? "最近动态" : "Recent activity"}</h2>
|
||||||
|
{activities.length === 0 ? (
|
||||||
|
<p className="planka-activity-empty">
|
||||||
|
{zh
|
||||||
|
? "创建 / 移动 / 清单 / 成员会出现在这里"
|
||||||
|
: "Creates, moves, tasks & members show up here"}
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<ul className="planka-activity-list">
|
||||||
|
{activities.map((a) => (
|
||||||
|
<li key={a.id}>
|
||||||
|
<div className="act-type">
|
||||||
|
{activityLabel(a.type, zh)}
|
||||||
|
{typeof a.data?.text === "string" ? ` — ${a.data.text}` : ""}
|
||||||
|
{typeof a.data?.name === "string" ? ` · ${a.data.name}` : ""}
|
||||||
|
</div>
|
||||||
|
<div className="act-meta">
|
||||||
|
<span>{a.actor}</span>
|
||||||
|
<time dateTime={a.created_at}>
|
||||||
|
{new Date(a.created_at).toLocaleString(zh ? "zh-CN" : "en-US", {
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
hour: "2-digit",
|
||||||
|
minute: "2-digit",
|
||||||
|
})}
|
||||||
|
</time>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</aside>
|
||||||
|
);
|
||||||
|
}
|
||||||
73
src/modules/work/components/board/BoardChrome.tsx
Normal file
73
src/modules/work/components/board/BoardChrome.tsx
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import {
|
||||||
|
BOARD_GRADIENT_CSS,
|
||||||
|
NOMADRO_BOARD_GRADIENTS,
|
||||||
|
type BoardGradientId,
|
||||||
|
} from "../../lib/backgrounds";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
zh: boolean;
|
||||||
|
boardName: string;
|
||||||
|
gradientId?: string | null;
|
||||||
|
showActivity: boolean;
|
||||||
|
showSettings: boolean;
|
||||||
|
onToggleActivity: () => void;
|
||||||
|
onToggleSettings: () => void;
|
||||||
|
onPickGradient: (id: BoardGradientId) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function BoardChrome({
|
||||||
|
zh,
|
||||||
|
boardName,
|
||||||
|
gradientId,
|
||||||
|
showActivity,
|
||||||
|
showSettings,
|
||||||
|
onToggleActivity,
|
||||||
|
onToggleSettings,
|
||||||
|
onPickGradient,
|
||||||
|
}: Props) {
|
||||||
|
return (
|
||||||
|
<header className="planka-board-bar">
|
||||||
|
<Link href={socialPath("/work/boards")}>
|
||||||
|
← {zh ? "看板" : "Boards"}
|
||||||
|
</Link>
|
||||||
|
<h1>{boardName || "…"}</h1>
|
||||||
|
<div className="planka-bar-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`planka-bar-chip${showSettings ? " on" : ""}`}
|
||||||
|
onClick={onToggleSettings}
|
||||||
|
>
|
||||||
|
{zh ? "背景" : "Theme"}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`planka-bar-chip${showActivity ? " on" : ""}`}
|
||||||
|
onClick={onToggleActivity}
|
||||||
|
>
|
||||||
|
{zh ? "动态" : "Activity"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{showSettings ? (
|
||||||
|
<div className="planka-bg-picker" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<p>{zh ? "看板背景(Planka gradient id · Nomadro 配色)" : "Board background"}</p>
|
||||||
|
<div className="planka-bg-swatches">
|
||||||
|
{NOMADRO_BOARD_GRADIENTS.map((id) => (
|
||||||
|
<button
|
||||||
|
key={id}
|
||||||
|
type="button"
|
||||||
|
className={gradientId === id ? "on" : undefined}
|
||||||
|
style={{ background: BOARD_GRADIENT_CSS[id] }}
|
||||||
|
title={id}
|
||||||
|
onClick={() => onPickGradient(id)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
117
src/modules/work/components/board/KanbanCard.tsx
Normal file
117
src/modules/work/components/board/KanbanCard.tsx
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Draggable } from "@hello-pangea/dnd";
|
||||||
|
import {
|
||||||
|
PLANKA_LABEL_COLORS,
|
||||||
|
type WorkCard,
|
||||||
|
type WorkCardMember,
|
||||||
|
type WorkLabel,
|
||||||
|
} from "../../lib/types";
|
||||||
|
import { formatStopwatch, isRunning, type Stopwatch } from "../../lib/stopwatch";
|
||||||
|
|
||||||
|
function initials(name: string) {
|
||||||
|
return name
|
||||||
|
.split(/\s+/)
|
||||||
|
.map((p) => p[0])
|
||||||
|
.join("")
|
||||||
|
.slice(0, 2)
|
||||||
|
.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
card: WorkCard;
|
||||||
|
index: number;
|
||||||
|
labels: (WorkLabel | undefined)[];
|
||||||
|
members: WorkCardMember[];
|
||||||
|
taskProgress: { done: number; total: number } | null;
|
||||||
|
commentCount: number;
|
||||||
|
onOpen: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function KanbanCard({
|
||||||
|
card,
|
||||||
|
index,
|
||||||
|
labels,
|
||||||
|
members,
|
||||||
|
taskProgress,
|
||||||
|
commentCount,
|
||||||
|
onOpen,
|
||||||
|
}: Props) {
|
||||||
|
const sw = card.stopwatch as Stopwatch | null | undefined;
|
||||||
|
const dueDone = Boolean(card.is_due_completed);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Draggable draggableId={`card:${card.id}`} index={index}>
|
||||||
|
{(drag, snapshot) => (
|
||||||
|
<div
|
||||||
|
className={`planka-card${snapshot.isDragging ? " planka-card-dragging" : ""}`}
|
||||||
|
ref={drag.innerRef}
|
||||||
|
{...drag.draggableProps}
|
||||||
|
{...drag.dragHandleProps}
|
||||||
|
onClick={onOpen}
|
||||||
|
>
|
||||||
|
{card.cover_color ? (
|
||||||
|
<div
|
||||||
|
className="planka-card-cover"
|
||||||
|
style={{ background: card.cover_color }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<div className="planka-card-body">
|
||||||
|
<div className="planka-card-labels">
|
||||||
|
{labels.map((lb) =>
|
||||||
|
lb ? (
|
||||||
|
<span
|
||||||
|
key={lb.id}
|
||||||
|
className="planka-card-label"
|
||||||
|
style={{
|
||||||
|
background: PLANKA_LABEL_COLORS[lb.color] || "#888",
|
||||||
|
}}
|
||||||
|
title={lb.name || lb.color}
|
||||||
|
/>
|
||||||
|
) : null,
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{card.name}
|
||||||
|
{card.description ? (
|
||||||
|
<p className="planka-card-desc">{card.description}</p>
|
||||||
|
) : null}
|
||||||
|
<div className="planka-card-meta">
|
||||||
|
{card.due_date ? (
|
||||||
|
<span
|
||||||
|
className={`planka-due${dueDone ? " done" : ""}`}
|
||||||
|
>
|
||||||
|
{dueDone ? "✓ " : "📅 "}
|
||||||
|
{card.due_date.slice(0, 10)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{sw && (sw.total > 0 || sw.startedAt) ? (
|
||||||
|
<span
|
||||||
|
className={`planka-card-badge${isRunning(sw) ? " running" : ""}`}
|
||||||
|
>
|
||||||
|
⏱ {formatStopwatch(sw)}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{taskProgress ? (
|
||||||
|
<span className="planka-card-badge">
|
||||||
|
✓ {taskProgress.done}/{taskProgress.total}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
{commentCount > 0 ? (
|
||||||
|
<span className="planka-card-badge">💬 {commentCount}</span>
|
||||||
|
) : null}
|
||||||
|
{members.length ? (
|
||||||
|
<div className="planka-card-avatars">
|
||||||
|
{members.slice(0, 4).map((m) => (
|
||||||
|
<span key={m.name} className="planka-avatar" title={m.name}>
|
||||||
|
{initials(m.name)}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Draggable>
|
||||||
|
);
|
||||||
|
}
|
||||||
62
src/modules/work/components/board/ListMenu.tsx
Normal file
62
src/modules/work/components/board/ListMenu.tsx
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { LIST_ACCENT_COLORS } from "../../lib/types";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
zh: boolean;
|
||||||
|
renameDraft: string;
|
||||||
|
accent: string;
|
||||||
|
onRenameDraft: (v: string) => void;
|
||||||
|
onSaveName: () => void;
|
||||||
|
onColor: (c: string) => void;
|
||||||
|
onDelete: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function ListMenu({
|
||||||
|
zh,
|
||||||
|
renameDraft,
|
||||||
|
accent,
|
||||||
|
onRenameDraft,
|
||||||
|
onSaveName,
|
||||||
|
onColor,
|
||||||
|
onDelete,
|
||||||
|
}: Props) {
|
||||||
|
return (
|
||||||
|
<div className="planka-list-menu" onClick={(e) => e.stopPropagation()}>
|
||||||
|
<input
|
||||||
|
value={renameDraft}
|
||||||
|
onChange={(e) => onRenameDraft(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
onSaveName();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
placeholder={zh ? "列表名称" : "List name"}
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="planka-btn-primary"
|
||||||
|
style={{ width: "100%", marginBottom: 8 }}
|
||||||
|
onClick={onSaveName}
|
||||||
|
>
|
||||||
|
{zh ? "重命名" : "Rename"}
|
||||||
|
</button>
|
||||||
|
<div className="planka-list-menu-colors">
|
||||||
|
{LIST_ACCENT_COLORS.map((c) => (
|
||||||
|
<button
|
||||||
|
key={c}
|
||||||
|
type="button"
|
||||||
|
className={accent === c ? "on" : undefined}
|
||||||
|
style={{ background: c }}
|
||||||
|
onClick={() => onColor(c)}
|
||||||
|
aria-label={c}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<button type="button" className="planka-list-menu-danger" onClick={onDelete}>
|
||||||
|
{zh ? "删除列表" : "Delete list"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
111
src/modules/work/components/etherpad-pad.css
Normal file
111
src/modules/work/components/etherpad-pad.css
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/**
|
||||||
|
* Chrome closer to Etherpad pad UI (dark toolbar + editor).
|
||||||
|
*/
|
||||||
|
.ep-shell {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 80;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: #fff;
|
||||||
|
color: #111;
|
||||||
|
font-family: "Segoe UI", Arial, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-bar {
|
||||||
|
flex: 0 0 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
padding: 0 12px;
|
||||||
|
background: #4d7c0f;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-bar a {
|
||||||
|
color: #fff;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-bar strong {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-bar input {
|
||||||
|
margin-left: auto;
|
||||||
|
min-height: 28px;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 2px 8px;
|
||||||
|
width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-status {
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-body {
|
||||||
|
flex: 1;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 220px;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-editor {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
padding: 24px 28px;
|
||||||
|
font-size: 15px;
|
||||||
|
line-height: 1.55;
|
||||||
|
resize: none;
|
||||||
|
outline: none;
|
||||||
|
font-family: Consolas, "Courier New", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-hist {
|
||||||
|
border-left: 1px solid #ddd;
|
||||||
|
background: #f7f7f7;
|
||||||
|
padding: 12px;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-hist h2 {
|
||||||
|
margin: 0 0 10px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-hist button {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
background: #fff;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
padding: 8px;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
min-height: 44px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ep-hist time {
|
||||||
|
display: block;
|
||||||
|
font-size: 11px;
|
||||||
|
color: #888;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 800px) {
|
||||||
|
.ep-body {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
.ep-hist {
|
||||||
|
border-left: 0;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
max-height: 30vh;
|
||||||
|
}
|
||||||
|
}
|
||||||
1048
src/modules/work/components/planka-board.css
Normal file
1048
src/modules/work/components/planka-board.css
Normal file
File diff suppressed because it is too large
Load Diff
1153
src/modules/work/components/work.css
Normal file
1153
src/modules/work/components/work.css
Normal file
File diff suppressed because it is too large
Load Diff
25
src/modules/work/index.ts
Normal file
25
src/modules/work/index.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
export { WORK_MODULE_ID, WORK_SERVICES, resolveWorkService } from "./lib/config";
|
||||||
|
export type { WorkService, WorkServiceId } from "./lib/config";
|
||||||
|
export { default as WorkClient } from "./components/WorkClient";
|
||||||
|
export { workApi } from "./lib/api";
|
||||||
|
export {
|
||||||
|
boardBackgroundCss,
|
||||||
|
NOMADRO_BOARD_GRADIENTS,
|
||||||
|
CARD_COVER_COLORS,
|
||||||
|
} from "./lib/backgrounds";
|
||||||
|
export {
|
||||||
|
formatStopwatch,
|
||||||
|
getFullSeconds,
|
||||||
|
isRunning,
|
||||||
|
} from "./lib/stopwatch";
|
||||||
|
export type { Stopwatch } from "./lib/stopwatch";
|
||||||
|
export type {
|
||||||
|
WorkActivity,
|
||||||
|
WorkAttachment,
|
||||||
|
WorkBoard,
|
||||||
|
WorkCard,
|
||||||
|
WorkCardMember,
|
||||||
|
WorkList,
|
||||||
|
WorkPad,
|
||||||
|
WorkProject,
|
||||||
|
} from "./lib/types";
|
||||||
158
src/modules/work/lib/api.ts
Normal file
158
src/modules/work/lib/api.ts
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/**
|
||||||
|
* Client for Nomadro work FastAPI (`/api/work/v1`).
|
||||||
|
* Falls back to Next local JSON routes if FastAPI is down (offline / first paint).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const BASE = "/api/work/v1";
|
||||||
|
|
||||||
|
async function j<T>(path: string, init?: RequestInit): Promise<T> {
|
||||||
|
const res = await fetch(`${BASE}${path}`, {
|
||||||
|
...init,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
...(init?.headers || {}),
|
||||||
|
},
|
||||||
|
cache: "no-store",
|
||||||
|
});
|
||||||
|
const data = await res.json().catch(() => ({}));
|
||||||
|
if (!res.ok || data?.ok === false) {
|
||||||
|
throw new Error(data?.error || `http_${res.status}`);
|
||||||
|
}
|
||||||
|
return data as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
type BoardRes = { ok: true; board: import("./types").WorkBoard };
|
||||||
|
|
||||||
|
export const workApi = {
|
||||||
|
projects: () => j<{ ok: true; projects: import("./types").WorkProject[] }>("/projects"),
|
||||||
|
createProject: (name: string, description = "") =>
|
||||||
|
j<{ ok: true; project: import("./types").WorkProject }>("/projects", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ name, description }),
|
||||||
|
}),
|
||||||
|
boards: (projectId?: string) =>
|
||||||
|
j<{ ok: true; boards: import("./types").WorkBoard[] }>(
|
||||||
|
projectId ? `/boards?project_id=${encodeURIComponent(projectId)}` : "/boards",
|
||||||
|
),
|
||||||
|
board: (id: string) => j<BoardRes>(`/boards/${id}`),
|
||||||
|
updateBoard: (
|
||||||
|
boardId: string,
|
||||||
|
patch: {
|
||||||
|
name?: string;
|
||||||
|
background_gradient?: string;
|
||||||
|
show_card_counter?: boolean;
|
||||||
|
},
|
||||||
|
) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify(patch),
|
||||||
|
}),
|
||||||
|
createBoard: (project_id: string, name: string) =>
|
||||||
|
j<BoardRes>("/boards", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ project_id, name }),
|
||||||
|
}),
|
||||||
|
addList: (boardId: string, name: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/lists`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ name }),
|
||||||
|
}),
|
||||||
|
addCard: (boardId: string, list_id: string, name: string, description = "") =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ list_id, name, description }),
|
||||||
|
}),
|
||||||
|
moveCard: (boardId: string, cardId: string, list_id: string, position: number) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/move`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ list_id, position }),
|
||||||
|
}),
|
||||||
|
updateCard: (
|
||||||
|
boardId: string,
|
||||||
|
cardId: string,
|
||||||
|
patch: {
|
||||||
|
name?: string;
|
||||||
|
description?: string;
|
||||||
|
due_date?: string;
|
||||||
|
clear_due?: boolean;
|
||||||
|
is_due_completed?: boolean;
|
||||||
|
cover_color?: string;
|
||||||
|
clear_cover?: boolean;
|
||||||
|
},
|
||||||
|
) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify(patch),
|
||||||
|
}),
|
||||||
|
moveList: (boardId: string, listId: string, position: number) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/lists/${listId}/move`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ position }),
|
||||||
|
}),
|
||||||
|
toggleLabel: (boardId: string, cardId: string, label_id: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/labels/toggle`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ label_id }),
|
||||||
|
}),
|
||||||
|
addTask: (boardId: string, cardId: string, name: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/tasks`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ name }),
|
||||||
|
}),
|
||||||
|
toggleTask: (boardId: string, taskId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/tasks/${taskId}/toggle`, {
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
|
addComment: (boardId: string, cardId: string, text: string, author = "guest") =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/comments`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ text, author }),
|
||||||
|
}),
|
||||||
|
updateList: (
|
||||||
|
boardId: string,
|
||||||
|
listId: string,
|
||||||
|
patch: { name?: string; color?: string | null },
|
||||||
|
) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/lists/${listId}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
body: JSON.stringify(patch),
|
||||||
|
}),
|
||||||
|
deleteList: (boardId: string, listId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/lists/${listId}`, { method: "DELETE" }),
|
||||||
|
deleteCard: (boardId: string, cardId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}`, { method: "DELETE" }),
|
||||||
|
toggleMember: (boardId: string, cardId: string, name: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/members/toggle`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ name }),
|
||||||
|
}),
|
||||||
|
toggleStopwatch: (boardId: string, cardId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/stopwatch/toggle`, {
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
|
archiveCard: (boardId: string, cardId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/archive`, {
|
||||||
|
method: "POST",
|
||||||
|
}),
|
||||||
|
addAttachment: (boardId: string, cardId: string, name: string, url: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/cards/${cardId}/attachments`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ name, url }),
|
||||||
|
}),
|
||||||
|
deleteAttachment: (boardId: string, attachmentId: string) =>
|
||||||
|
j<BoardRes>(`/boards/${boardId}/attachments/${attachmentId}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
}),
|
||||||
|
pads: () => j<{ ok: true; pads: import("./types").WorkPad[] }>("/pads"),
|
||||||
|
pad: (id: string) => j<{ ok: true; pad: import("./types").WorkPad }>(`/pads/${id}`),
|
||||||
|
createPad: (title: string, author = "guest") =>
|
||||||
|
j<{ ok: true; pad: import("./types").WorkPad }>("/pads", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({ title, author }),
|
||||||
|
}),
|
||||||
|
updatePad: (id: string, text: string, author = "guest", title?: string) =>
|
||||||
|
j<{ ok: true; pad: import("./types").WorkPad }>(`/pads/${id}`, {
|
||||||
|
method: "PUT",
|
||||||
|
body: JSON.stringify({ text, author, title }),
|
||||||
|
}),
|
||||||
|
};
|
||||||
56
src/modules/work/lib/backgrounds.ts
Normal file
56
src/modules/work/lib/backgrounds.ts
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Planka BackgroundGradients names → Nomadro dark-tech CSS (amber / teal / slate).
|
||||||
|
* Keeps Planka enum ids for API parity; visuals are Nomadro-custom.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const NOMADRO_BOARD_GRADIENTS = [
|
||||||
|
"ocean-dive",
|
||||||
|
"warm-rust",
|
||||||
|
"steel-grey",
|
||||||
|
"heat-waves",
|
||||||
|
"blue-steel",
|
||||||
|
"green-mist",
|
||||||
|
"sun-scream",
|
||||||
|
"coral-reef",
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type BoardGradientId = (typeof NOMADRO_BOARD_GRADIENTS)[number];
|
||||||
|
|
||||||
|
/** CSS backgrounds tuned for #0c0c0f + amber VIP accent */
|
||||||
|
export const BOARD_GRADIENT_CSS: Record<BoardGradientId, string> = {
|
||||||
|
"ocean-dive":
|
||||||
|
"radial-gradient(1100px 560px at 10% -5%, rgba(56,189,248,0.16), transparent 55%), radial-gradient(800px 420px at 90% 0%, rgba(14,165,233,0.08), transparent 50%), linear-gradient(165deg,#0e1620,#0c0c0f 55%)",
|
||||||
|
"warm-rust":
|
||||||
|
"radial-gradient(1000px 520px at 15% -8%, rgba(245,158,11,0.18), transparent 55%), radial-gradient(700px 400px at 85% 5%, rgba(234,88,12,0.1), transparent 50%), linear-gradient(165deg,#16120c,#0c0c0f 55%)",
|
||||||
|
"steel-grey":
|
||||||
|
"radial-gradient(1000px 500px at 20% 0%, rgba(148,163,184,0.12), transparent 55%), linear-gradient(165deg,#12141a,#0c0c0f 60%)",
|
||||||
|
"heat-waves":
|
||||||
|
"radial-gradient(900px 480px at 8% -10%, rgba(251,113,133,0.14), transparent 50%), radial-gradient(700px 400px at 95% 0%, rgba(245,158,11,0.12), transparent 45%), linear-gradient(165deg,#1a1014,#0c0c0f 55%)",
|
||||||
|
"blue-steel":
|
||||||
|
"radial-gradient(1000px 520px at 12% -5%, rgba(99,102,241,0.1), transparent 50%), radial-gradient(800px 400px at 90% 0%, rgba(56,189,248,0.12), transparent 50%), linear-gradient(165deg,#0f1420,#0c0c0f 55%)",
|
||||||
|
"green-mist":
|
||||||
|
"radial-gradient(1000px 520px at 10% -5%, rgba(52,211,153,0.14), transparent 55%), linear-gradient(165deg,#0e1612,#0c0c0f 55%)",
|
||||||
|
"sun-scream":
|
||||||
|
"radial-gradient(900px 480px at 20% -10%, rgba(250,204,21,0.16), transparent 50%), radial-gradient(700px 380px at 80% 0%, rgba(245,158,11,0.1), transparent 45%), linear-gradient(165deg,#18140a,#0c0c0f 55%)",
|
||||||
|
"coral-reef":
|
||||||
|
"radial-gradient(900px 480px at 15% -8%, rgba(244,114,182,0.1), transparent 50%), radial-gradient(700px 400px at 88% 5%, rgba(56,189,248,0.1), transparent 45%), linear-gradient(165deg,#141018,#0c0c0f 55%)",
|
||||||
|
};
|
||||||
|
|
||||||
|
export function boardBackgroundCss(id?: string | null): string {
|
||||||
|
if (id && id in BOARD_GRADIENT_CSS) {
|
||||||
|
return BOARD_GRADIENT_CSS[id as BoardGradientId];
|
||||||
|
}
|
||||||
|
return BOARD_GRADIENT_CSS["ocean-dive"];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Card cover chips — Planka-ish solids, Nomadro palette */
|
||||||
|
export const CARD_COVER_COLORS = [
|
||||||
|
"#f59e0b",
|
||||||
|
"#ea580c",
|
||||||
|
"#38bdf8",
|
||||||
|
"#34d399",
|
||||||
|
"#fb7185",
|
||||||
|
"#a78bfa",
|
||||||
|
"#94a3b8",
|
||||||
|
"#0ea5e9",
|
||||||
|
] as const;
|
||||||
50
src/modules/work/lib/config.ts
Normal file
50
src/modules/work/lib/config.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
export const WORK_MODULE_ID = "work" as const;
|
||||||
|
|
||||||
|
export type WorkServiceId = "boards" | "pads";
|
||||||
|
|
||||||
|
export type WorkService = {
|
||||||
|
id: WorkServiceId;
|
||||||
|
emoji: string;
|
||||||
|
titleZh: string;
|
||||||
|
titleEn: string;
|
||||||
|
descZh: string;
|
||||||
|
descEn: string;
|
||||||
|
href: string;
|
||||||
|
inspiredBy: string;
|
||||||
|
backend: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WORK_SERVICES: WorkService[] = [
|
||||||
|
{
|
||||||
|
id: "boards",
|
||||||
|
emoji: "📋",
|
||||||
|
titleZh: "看板协作",
|
||||||
|
titleEn: "Kanban boards",
|
||||||
|
descZh:
|
||||||
|
"分析 Planka 源码后自研:项目/看板/列/卡片 · Next UI + FastAPI work_svc。",
|
||||||
|
descEn:
|
||||||
|
"Rebuilt from Planka domain: projects/boards/lists/cards — Next + FastAPI.",
|
||||||
|
href: "/work/boards",
|
||||||
|
inspiredBy: "https://github.com/plankanban/planka",
|
||||||
|
backend: "apps/api/services/work_svc",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "pads",
|
||||||
|
emoji: "📝",
|
||||||
|
titleZh: "实时文档",
|
||||||
|
titleEn: "Live pads",
|
||||||
|
descZh:
|
||||||
|
"分析 Etherpad 源码后自研:文档/作者/修订 · Next UI + FastAPI work_svc。",
|
||||||
|
descEn:
|
||||||
|
"Rebuilt from Etherpad domain: pads/authors/revisions — Next + FastAPI.",
|
||||||
|
href: "/work/pads",
|
||||||
|
inspiredBy: "https://github.com/ether/etherpad",
|
||||||
|
backend: "apps/api/services/work_svc",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export function resolveWorkService(id: WorkServiceId): WorkService {
|
||||||
|
const hit = WORK_SERVICES.find((s) => s.id === id);
|
||||||
|
if (!hit) throw new Error(`unknown work service ${id}`);
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
31
src/modules/work/lib/stopwatch.ts
Normal file
31
src/modules/work/lib/stopwatch.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Port of Planka client/src/utils/stopwatch.js — Fair Use secondary-dev.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type Stopwatch = {
|
||||||
|
startedAt: string | null;
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function getFullSeconds(sw: Stopwatch | null | undefined): number {
|
||||||
|
if (!sw) return 0;
|
||||||
|
if (sw.startedAt) {
|
||||||
|
const started = Date.parse(sw.startedAt.endsWith("Z") ? sw.startedAt : `${sw.startedAt}Z`);
|
||||||
|
const base = Number.isFinite(started) ? started : Date.now();
|
||||||
|
return Math.floor((Date.now() - base) / 1000) + (sw.total || 0);
|
||||||
|
}
|
||||||
|
return sw.total || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatStopwatch(sw: Stopwatch | null | undefined): string {
|
||||||
|
const full = getFullSeconds(sw);
|
||||||
|
const hours = Math.floor(full / 3600);
|
||||||
|
const minutes = Math.floor((full - hours * 3600) / 60);
|
||||||
|
const seconds = full - hours * 3600 - minutes * 60;
|
||||||
|
const pad = (n: number) => (n < 10 ? `0${n}` : String(n));
|
||||||
|
return `${hours}:${pad(minutes)}:${pad(seconds)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRunning(sw: Stopwatch | null | undefined): boolean {
|
||||||
|
return Boolean(sw?.startedAt);
|
||||||
|
}
|
||||||
289
src/modules/work/lib/store.ts
Normal file
289
src/modules/work/lib/store.ts
Normal file
@ -0,0 +1,289 @@
|
|||||||
|
import { randomUUID } from "crypto";
|
||||||
|
import { promises as fs } from "fs";
|
||||||
|
import path from "path";
|
||||||
|
import type { WorkBoard, WorkCard, WorkPad, WorkStoreFile } from "./types";
|
||||||
|
|
||||||
|
const DATA_DIR = path.join(process.cwd(), "data", "work");
|
||||||
|
const STORE_PATH = path.join(DATA_DIR, "store.json");
|
||||||
|
|
||||||
|
function now() {
|
||||||
|
return new Date().toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
function seed(): WorkStoreFile {
|
||||||
|
const t = now();
|
||||||
|
const listTodo = "list-todo";
|
||||||
|
const listDoing = "list-doing";
|
||||||
|
const listDone = "list-done";
|
||||||
|
return {
|
||||||
|
boards: [
|
||||||
|
{
|
||||||
|
id: "board-demo",
|
||||||
|
title: "Nomadro remote sprint",
|
||||||
|
description: "原生看板种子 · 可改可删",
|
||||||
|
createdAt: t,
|
||||||
|
updatedAt: t,
|
||||||
|
lists: [
|
||||||
|
{ id: listTodo, title: "Backlog", position: 0 },
|
||||||
|
{ id: listDoing, title: "Doing", position: 1 },
|
||||||
|
{ id: listDone, title: "Done", position: 2 },
|
||||||
|
],
|
||||||
|
cards: [
|
||||||
|
{
|
||||||
|
id: "card-1",
|
||||||
|
title: "Ship /social/work native UI",
|
||||||
|
description: "No subdomain redirects",
|
||||||
|
listId: listDoing,
|
||||||
|
position: 0,
|
||||||
|
updatedAt: t,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "card-2",
|
||||||
|
title: "Wire public API + SDK",
|
||||||
|
description: "",
|
||||||
|
listId: listDone,
|
||||||
|
position: 0,
|
||||||
|
updatedAt: t,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "card-3",
|
||||||
|
title: "Invite remote collaborators",
|
||||||
|
description: "From /social/team",
|
||||||
|
listId: listTodo,
|
||||||
|
position: 0,
|
||||||
|
updatedAt: t,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pads: [
|
||||||
|
{
|
||||||
|
id: "pad-welcome",
|
||||||
|
title: "Welcome pad",
|
||||||
|
text:
|
||||||
|
"# Nomadro Live Pad\n\n多人共写草稿(Etherpad 模型二次开发)。\n改这里会写入修订历史。\n",
|
||||||
|
authors: ["system"],
|
||||||
|
revisions: [
|
||||||
|
{
|
||||||
|
id: "rev-0",
|
||||||
|
author: "system",
|
||||||
|
text:
|
||||||
|
"# Nomadro Live Pad\n\n多人共写草稿(Etherpad 模型二次开发)。\n改这里会写入修订历史。\n",
|
||||||
|
at: t,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
createdAt: t,
|
||||||
|
updatedAt: t,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensure(): Promise<WorkStoreFile> {
|
||||||
|
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||||
|
try {
|
||||||
|
const raw = await fs.readFile(STORE_PATH, "utf8");
|
||||||
|
const parsed = JSON.parse(raw) as WorkStoreFile;
|
||||||
|
if (!parsed.boards || !parsed.pads) return seed();
|
||||||
|
return parsed;
|
||||||
|
} catch {
|
||||||
|
const s = seed();
|
||||||
|
await fs.writeFile(STORE_PATH, JSON.stringify(s, null, 2), "utf8");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save(data: WorkStoreFile) {
|
||||||
|
await fs.mkdir(DATA_DIR, { recursive: true });
|
||||||
|
await fs.writeFile(STORE_PATH, JSON.stringify(data, null, 2), "utf8");
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listBoards(): Promise<
|
||||||
|
Pick<WorkBoard, "id" | "title" | "description" | "updatedAt" | "createdAt">[]
|
||||||
|
> {
|
||||||
|
const data = await ensure();
|
||||||
|
return data.boards.map(({ id, title, description, updatedAt, createdAt }) => ({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
updatedAt,
|
||||||
|
createdAt,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getBoard(id: string): Promise<WorkBoard | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
return data.boards.find((b) => b.id === id) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createBoard(input: {
|
||||||
|
title: string;
|
||||||
|
description?: string;
|
||||||
|
}): Promise<WorkBoard> {
|
||||||
|
const data = await ensure();
|
||||||
|
const t = now();
|
||||||
|
const board: WorkBoard = {
|
||||||
|
id: `board-${randomUUID().slice(0, 8)}`,
|
||||||
|
title: input.title.trim() || "Untitled board",
|
||||||
|
description: (input.description || "").trim(),
|
||||||
|
createdAt: t,
|
||||||
|
updatedAt: t,
|
||||||
|
lists: [
|
||||||
|
{ id: `list-${randomUUID().slice(0, 8)}`, title: "Backlog", position: 0 },
|
||||||
|
{ id: `list-${randomUUID().slice(0, 8)}`, title: "Doing", position: 1 },
|
||||||
|
{ id: `list-${randomUUID().slice(0, 8)}`, title: "Done", position: 2 },
|
||||||
|
],
|
||||||
|
cards: [],
|
||||||
|
};
|
||||||
|
data.boards.unshift(board);
|
||||||
|
await save(data);
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addCard(
|
||||||
|
boardId: string,
|
||||||
|
input: { listId: string; title: string; description?: string },
|
||||||
|
): Promise<WorkCard | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
const board = data.boards.find((b) => b.id === boardId);
|
||||||
|
if (!board) return null;
|
||||||
|
const list = board.lists.find((l) => l.id === input.listId);
|
||||||
|
if (!list) return null;
|
||||||
|
const t = now();
|
||||||
|
const siblings = board.cards.filter((c) => c.listId === input.listId);
|
||||||
|
const card: WorkCard = {
|
||||||
|
id: `card-${randomUUID().slice(0, 8)}`,
|
||||||
|
title: input.title.trim() || "Untitled",
|
||||||
|
description: (input.description || "").trim(),
|
||||||
|
listId: input.listId,
|
||||||
|
position: siblings.length,
|
||||||
|
updatedAt: t,
|
||||||
|
};
|
||||||
|
board.cards.push(card);
|
||||||
|
board.updatedAt = t;
|
||||||
|
await save(data);
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function moveCard(
|
||||||
|
boardId: string,
|
||||||
|
cardId: string,
|
||||||
|
input: { listId: string; position: number },
|
||||||
|
): Promise<WorkBoard | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
const board = data.boards.find((b) => b.id === boardId);
|
||||||
|
if (!board) return null;
|
||||||
|
const card = board.cards.find((c) => c.id === cardId);
|
||||||
|
if (!card) return null;
|
||||||
|
if (!board.lists.some((l) => l.id === input.listId)) return null;
|
||||||
|
const t = now();
|
||||||
|
const fromList = card.listId;
|
||||||
|
const others = board.cards
|
||||||
|
.filter((c) => c.listId === input.listId && c.id !== cardId)
|
||||||
|
.sort((a, b) => a.position - b.position);
|
||||||
|
const pos = Math.max(0, Math.min(input.position, others.length));
|
||||||
|
others.splice(pos, 0, card);
|
||||||
|
card.listId = input.listId;
|
||||||
|
card.updatedAt = t;
|
||||||
|
others.forEach((c, i) => {
|
||||||
|
c.position = i;
|
||||||
|
});
|
||||||
|
if (fromList !== input.listId) {
|
||||||
|
board.cards
|
||||||
|
.filter((c) => c.listId === fromList)
|
||||||
|
.sort((a, b) => a.position - b.position)
|
||||||
|
.forEach((c, i) => {
|
||||||
|
c.position = i;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
board.updatedAt = t;
|
||||||
|
await save(data);
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addList(
|
||||||
|
boardId: string,
|
||||||
|
title: string,
|
||||||
|
): Promise<WorkBoard | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
const board = data.boards.find((b) => b.id === boardId);
|
||||||
|
if (!board) return null;
|
||||||
|
const t = now();
|
||||||
|
board.lists.push({
|
||||||
|
id: `list-${randomUUID().slice(0, 8)}`,
|
||||||
|
title: title.trim() || "List",
|
||||||
|
position: board.lists.length,
|
||||||
|
});
|
||||||
|
board.updatedAt = t;
|
||||||
|
await save(data);
|
||||||
|
return board;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listPads(): Promise<
|
||||||
|
Pick<WorkPad, "id" | "title" | "updatedAt" | "createdAt" | "authors">[]
|
||||||
|
> {
|
||||||
|
const data = await ensure();
|
||||||
|
return data.pads.map(({ id, title, updatedAt, createdAt, authors }) => ({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
updatedAt,
|
||||||
|
createdAt,
|
||||||
|
authors,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPad(id: string): Promise<WorkPad | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
return data.pads.find((p) => p.id === id) ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createPad(input: {
|
||||||
|
title: string;
|
||||||
|
author?: string;
|
||||||
|
}): Promise<WorkPad> {
|
||||||
|
const data = await ensure();
|
||||||
|
const t = now();
|
||||||
|
const author = (input.author || "guest").trim() || "guest";
|
||||||
|
const text = "";
|
||||||
|
const pad: WorkPad = {
|
||||||
|
id: `pad-${randomUUID().slice(0, 8)}`,
|
||||||
|
title: input.title.trim() || "Untitled pad",
|
||||||
|
text,
|
||||||
|
authors: [author],
|
||||||
|
revisions: [{ id: `rev-${randomUUID().slice(0, 8)}`, author, text, at: t }],
|
||||||
|
createdAt: t,
|
||||||
|
updatedAt: t,
|
||||||
|
};
|
||||||
|
data.pads.unshift(pad);
|
||||||
|
await save(data);
|
||||||
|
return pad;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updatePad(
|
||||||
|
id: string,
|
||||||
|
input: { text: string; author?: string; title?: string },
|
||||||
|
): Promise<WorkPad | null> {
|
||||||
|
const data = await ensure();
|
||||||
|
const pad = data.pads.find((p) => p.id === id);
|
||||||
|
if (!pad) return null;
|
||||||
|
const t = now();
|
||||||
|
const author = (input.author || "guest").trim() || "guest";
|
||||||
|
if (typeof input.title === "string" && input.title.trim()) {
|
||||||
|
pad.title = input.title.trim();
|
||||||
|
}
|
||||||
|
pad.text = input.text;
|
||||||
|
if (!pad.authors.includes(author)) pad.authors.push(author);
|
||||||
|
pad.revisions.push({
|
||||||
|
id: `rev-${randomUUID().slice(0, 8)}`,
|
||||||
|
author,
|
||||||
|
text: input.text,
|
||||||
|
at: t,
|
||||||
|
});
|
||||||
|
// keep last 40 revisions
|
||||||
|
if (pad.revisions.length > 40) {
|
||||||
|
pad.revisions = pad.revisions.slice(-40);
|
||||||
|
}
|
||||||
|
pad.updatedAt = t;
|
||||||
|
await save(data);
|
||||||
|
return pad;
|
||||||
|
}
|
||||||
163
src/modules/work/lib/types.ts
Normal file
163
src/modules/work/lib/types.ts
Normal file
@ -0,0 +1,163 @@
|
|||||||
|
/** Domain aligned with Planka (boards) + Etherpad (pads) secondary-dev. */
|
||||||
|
|
||||||
|
import type { Stopwatch } from "./stopwatch";
|
||||||
|
|
||||||
|
export type WorkProject = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
background_type?: string | null;
|
||||||
|
background_gradient?: string | null;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
board_id?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkList = {
|
||||||
|
id: string;
|
||||||
|
board_id: string;
|
||||||
|
name: string;
|
||||||
|
/** Planka: active | closed | archive | trash */
|
||||||
|
type: string;
|
||||||
|
position: number;
|
||||||
|
color?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkLabel = {
|
||||||
|
id: string;
|
||||||
|
board_id: string;
|
||||||
|
name: string | null;
|
||||||
|
color: string;
|
||||||
|
position: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkCardLabel = {
|
||||||
|
card_id: string;
|
||||||
|
label_id: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkTaskList = {
|
||||||
|
id: string;
|
||||||
|
card_id: string;
|
||||||
|
name: string;
|
||||||
|
position: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkTask = {
|
||||||
|
id: string;
|
||||||
|
task_list_id: string;
|
||||||
|
name: string;
|
||||||
|
is_completed: number | boolean;
|
||||||
|
position: number;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkComment = {
|
||||||
|
id: string;
|
||||||
|
card_id: string;
|
||||||
|
author: string;
|
||||||
|
text: string;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkCardMember = {
|
||||||
|
card_id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkAttachment = {
|
||||||
|
id: string;
|
||||||
|
card_id: string;
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkActivity = {
|
||||||
|
id: string;
|
||||||
|
board_id: string;
|
||||||
|
card_id?: string | null;
|
||||||
|
actor: string;
|
||||||
|
/** Planka Action types + Nomadro extras */
|
||||||
|
type: string;
|
||||||
|
data: Record<string, unknown>;
|
||||||
|
created_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkCard = {
|
||||||
|
id: string;
|
||||||
|
list_id: string;
|
||||||
|
board_id: string;
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
type: string;
|
||||||
|
position: number;
|
||||||
|
due_date?: string | null;
|
||||||
|
is_due_completed?: number | boolean;
|
||||||
|
stopwatch?: Stopwatch | null;
|
||||||
|
cover_color?: string | null;
|
||||||
|
is_closed: number | boolean;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkBoard = {
|
||||||
|
id: string;
|
||||||
|
project_id: string;
|
||||||
|
name: string;
|
||||||
|
position: number;
|
||||||
|
default_view: string;
|
||||||
|
background_gradient?: string | null;
|
||||||
|
show_card_counter?: number | boolean;
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
lists: WorkList[];
|
||||||
|
cards: WorkCard[];
|
||||||
|
labels?: WorkLabel[];
|
||||||
|
card_labels?: WorkCardLabel[];
|
||||||
|
task_lists?: WorkTaskList[];
|
||||||
|
tasks?: WorkTask[];
|
||||||
|
comments?: WorkComment[];
|
||||||
|
card_members?: WorkCardMember[];
|
||||||
|
attachments?: WorkAttachment[];
|
||||||
|
activities?: WorkActivity[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkPadRevision = {
|
||||||
|
id: string;
|
||||||
|
author: string;
|
||||||
|
text: string;
|
||||||
|
at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WorkPad = {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
text: string;
|
||||||
|
authors: string[];
|
||||||
|
revisions: WorkPadRevision[];
|
||||||
|
created_at: string;
|
||||||
|
updated_at: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Planka label color → hex (subset used in Nomadro seed) */
|
||||||
|
export const PLANKA_LABEL_COLORS: Record<string, string> = {
|
||||||
|
"berry-red": "#b04632",
|
||||||
|
"lagoon-blue": "#0079bf",
|
||||||
|
"pumpkin-orange": "#d29034",
|
||||||
|
"pink-tulip": "#cd5a91",
|
||||||
|
"fresh-salad": "#61bd4f",
|
||||||
|
"antique-blue": "#055a8c",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LIST_ACCENT_COLORS = [
|
||||||
|
"#f59e0b",
|
||||||
|
"#38bdf8",
|
||||||
|
"#a78bfa",
|
||||||
|
"#34d399",
|
||||||
|
"#fb7185",
|
||||||
|
"#f472b6",
|
||||||
|
"#94a3b8",
|
||||||
|
] as const;
|
||||||
147
src/modules/work/micro/MicroAppHost.tsx
Normal file
147
src/modules/work/micro/MicroAppHost.tsx
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import { useSocialI18n } from "@social/lib/useSocialI18n";
|
||||||
|
import { resolveMicroApp, type WorkMicroAppId } from "./registry";
|
||||||
|
import { ensureMicroHost } from "./start";
|
||||||
|
import "./micro.css";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
appId: WorkMicroAppId;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Micro-frontend host via @micro-zoe/micro-app (WebComponent + JS sandbox).
|
||||||
|
* No iframe. Child = same-origin secondary-dev Planka / Etherpad under /work-mf/*.
|
||||||
|
*/
|
||||||
|
export default function MicroAppHost({ appId }: Props) {
|
||||||
|
const { locale } = useSocialI18n();
|
||||||
|
const zh = locale === "zh";
|
||||||
|
const app = resolveMicroApp(appId);
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
const [alive, setAlive] = useState(false);
|
||||||
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await ensureMicroHost();
|
||||||
|
if (!cancelled) setReady(true);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
if (!cancelled) setError(zh ? "微前端宿主启动失败" : "MF host failed");
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [zh]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ready) return;
|
||||||
|
|
||||||
|
const onMounted = (e: Event) => {
|
||||||
|
const detail = (e as CustomEvent).detail as { name?: string } | undefined;
|
||||||
|
if (detail?.name === app.name) {
|
||||||
|
setAlive(true);
|
||||||
|
setError("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const onError = (e: Event) => {
|
||||||
|
const detail = (e as CustomEvent).detail as
|
||||||
|
| { name?: string; error?: Error }
|
||||||
|
| undefined;
|
||||||
|
if (detail?.name === app.name) {
|
||||||
|
setError(
|
||||||
|
zh
|
||||||
|
? `子应用错误:${detail.error?.message || "load failed"}`
|
||||||
|
: `Sub-app error: ${detail.error?.message || "load failed"}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("mounted", onMounted as EventListener);
|
||||||
|
window.addEventListener("error", onError as EventListener);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("mounted", onMounted as EventListener);
|
||||||
|
window.removeEventListener("error", onError as EventListener);
|
||||||
|
};
|
||||||
|
}, [ready, app.name, zh]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const res = await fetch(app.entry, {
|
||||||
|
credentials: "include",
|
||||||
|
cache: "no-store",
|
||||||
|
redirect: "follow",
|
||||||
|
});
|
||||||
|
if (!cancelled && res.status >= 500) {
|
||||||
|
setError(
|
||||||
|
zh
|
||||||
|
? `上游未就绪(HTTP ${res.status})`
|
||||||
|
: `Upstream down (HTTP ${res.status})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
if (!cancelled) {
|
||||||
|
setError(zh ? "无法连接同域子应用" : "Cannot reach same-origin sub-app");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [app.entry, zh]);
|
||||||
|
|
||||||
|
const title = zh ? app.titleZh : app.titleEn;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="work-mf work-mf--solo" data-app={app.id}>
|
||||||
|
<header className="work-mf-bar">
|
||||||
|
<div className="work-mf-bar-left">
|
||||||
|
<Link href={socialPath("/work")} className="work-mf-back">
|
||||||
|
← {zh ? "远程工作" : "Remote work"}
|
||||||
|
</Link>
|
||||||
|
<span className="work-mf-sep" aria-hidden>
|
||||||
|
/
|
||||||
|
</span>
|
||||||
|
<strong>{title}</strong>
|
||||||
|
<span
|
||||||
|
className={`work-mf-dot ${alive ? "on" : ""}`}
|
||||||
|
title={alive ? "live" : "loading"}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
{error ? (
|
||||||
|
<div className="work-mf-fallback" role="alert">
|
||||||
|
<p>{error}</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<div className="work-mf-viewport">
|
||||||
|
{ready ? (
|
||||||
|
<micro-app
|
||||||
|
name={app.name}
|
||||||
|
url={app.entry}
|
||||||
|
// NO iframe — JS sandbox WebComponent
|
||||||
|
keep-alive={app.keepAlive ? "true" : undefined}
|
||||||
|
disable-memory-router="true"
|
||||||
|
disable-scopecss="true"
|
||||||
|
router-mode="pure"
|
||||||
|
style={{ display: "block", width: "100%", height: "100%" }}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="work-mf-loading">
|
||||||
|
{zh ? "加载微前端…" : "Loading micro-app…"}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
24
src/modules/work/micro/micro-app.d.ts
vendored
Normal file
24
src/modules/work/micro/micro-app.d.ts
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import type { DetailedHTMLProps, HTMLAttributes } from "react";
|
||||||
|
|
||||||
|
type MicroAppProps = DetailedHTMLProps<
|
||||||
|
HTMLAttributes<HTMLElement>,
|
||||||
|
HTMLElement
|
||||||
|
> & {
|
||||||
|
name: string;
|
||||||
|
url: string;
|
||||||
|
iframe?: string | boolean;
|
||||||
|
"keep-alive"?: string | boolean;
|
||||||
|
"disable-memory-router"?: string | boolean;
|
||||||
|
"router-mode"?: string;
|
||||||
|
baseroute?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
namespace JSX {
|
||||||
|
interface IntrinsicElements {
|
||||||
|
"micro-app": MicroAppProps;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
94
src/modules/work/micro/micro.css
Normal file
94
src/modules/work/micro/micro.css
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
.work-mf {
|
||||||
|
--mf-bar: 44px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100dvh;
|
||||||
|
min-height: 100dvh;
|
||||||
|
margin: 0;
|
||||||
|
background: #0c0c0f;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf--solo {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 80;
|
||||||
|
background: #0c0c0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-bar {
|
||||||
|
flex: 0 0 var(--mf-bar);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
padding: 0 0.85rem;
|
||||||
|
border-bottom: 1px solid rgba(148, 163, 184, 0.16);
|
||||||
|
background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-bar-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.45rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-back {
|
||||||
|
color: #f59e0b;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-sep {
|
||||||
|
opacity: 0.35;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-bar strong {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-dot.on {
|
||||||
|
background: #22c55e;
|
||||||
|
box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-viewport {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
position: relative;
|
||||||
|
min-height: 0;
|
||||||
|
background: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-frame {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
background: #111827;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-fallback {
|
||||||
|
margin: 0.75rem 0.85rem 0;
|
||||||
|
padding: 0.85rem 1rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(248, 113, 113, 0.35);
|
||||||
|
background: rgba(248, 113, 113, 0.08);
|
||||||
|
font-size: 0.88rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.work-mf-loading {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
height: 100%;
|
||||||
|
opacity: 0.65;
|
||||||
|
}
|
||||||
52
src/modules/work/micro/registry.ts
Normal file
52
src/modules/work/micro/registry.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Micro-frontend registry for OSS secondary-dev apps.
|
||||||
|
* Each entry is same-origin (Next rewrite → Docker upstream), never a foreign host.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export type WorkMicroAppId = "planka" | "etherpad";
|
||||||
|
|
||||||
|
export type WorkMicroApp = {
|
||||||
|
id: WorkMicroAppId;
|
||||||
|
/** micro-app name (unique) */
|
||||||
|
name: string;
|
||||||
|
/** Same-origin entry (proxied) */
|
||||||
|
entry: string;
|
||||||
|
titleZh: string;
|
||||||
|
titleEn: string;
|
||||||
|
/** Upstream reference for secondary-dev */
|
||||||
|
upstream: string;
|
||||||
|
overlayDir: string;
|
||||||
|
/** Prefer iframe sandbox for complex legacy bundles (Etherpad) */
|
||||||
|
iframe: boolean;
|
||||||
|
/** Keep alive when navigating away */
|
||||||
|
keepAlive: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WORK_MICRO_APPS: Record<WorkMicroAppId, WorkMicroApp> = {
|
||||||
|
planka: {
|
||||||
|
id: "planka",
|
||||||
|
name: "nomadro-planka",
|
||||||
|
entry: "/work-mf/planka",
|
||||||
|
titleZh: "看板协作",
|
||||||
|
titleEn: "Kanban",
|
||||||
|
upstream: "https://github.com/plankanban/planka",
|
||||||
|
overlayDir: "apps/work/overlay/planka",
|
||||||
|
iframe: true,
|
||||||
|
keepAlive: true,
|
||||||
|
},
|
||||||
|
etherpad: {
|
||||||
|
id: "etherpad",
|
||||||
|
name: "nomadro-etherpad",
|
||||||
|
entry: "/work-mf/etherpad",
|
||||||
|
titleZh: "实时文档",
|
||||||
|
titleEn: "Pads",
|
||||||
|
upstream: "https://github.com/ether/etherpad",
|
||||||
|
overlayDir: "apps/work/overlay/etherpad",
|
||||||
|
iframe: true,
|
||||||
|
keepAlive: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function resolveMicroApp(id: WorkMicroAppId): WorkMicroApp {
|
||||||
|
return WORK_MICRO_APPS[id];
|
||||||
|
}
|
||||||
48
src/modules/work/micro/start.ts
Normal file
48
src/modules/work/micro/start.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Boot @micro-zoe/micro-app once — JS sandbox / WebComponent, no iframe.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let started = false;
|
||||||
|
let starting: Promise<void> | null = null;
|
||||||
|
|
||||||
|
export async function ensureMicroHost(): Promise<void> {
|
||||||
|
if (typeof window === "undefined") return;
|
||||||
|
if (started) return;
|
||||||
|
if (starting) return starting;
|
||||||
|
|
||||||
|
starting = (async () => {
|
||||||
|
const microApp = (await import("@micro-zoe/micro-app")).default;
|
||||||
|
microApp.start({
|
||||||
|
// Child keeps own history; host owns /social/work/*
|
||||||
|
"disable-memory-router": true,
|
||||||
|
// Same-origin /work-mf/* — allow fetch/XHR patching into child
|
||||||
|
"disable-patch-request": false,
|
||||||
|
lifeCycles: {
|
||||||
|
created(e?: { detail?: { name?: string } }) {
|
||||||
|
console.info("[work-mf] created", e?.detail?.name);
|
||||||
|
},
|
||||||
|
beforemount(e?: { detail?: { name?: string } }) {
|
||||||
|
console.info("[work-mf] beforemount", e?.detail?.name);
|
||||||
|
},
|
||||||
|
mounted(e?: { detail?: { name?: string } }) {
|
||||||
|
console.info("[work-mf] mounted", e?.detail?.name);
|
||||||
|
},
|
||||||
|
unmount(e?: { detail?: { name?: string } }) {
|
||||||
|
console.info("[work-mf] unmount", e?.detail?.name);
|
||||||
|
},
|
||||||
|
error(e?: { detail?: { name?: string; error?: Error } }) {
|
||||||
|
console.error("[work-mf] error", e?.detail?.name, e?.detail?.error);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
started = true;
|
||||||
|
})();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await starting;
|
||||||
|
} finally {
|
||||||
|
starting = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
111
src/modules/work/planka/bridge/PlankaNextRoot.tsx
Normal file
111
src/modules/work/planka/bridge/PlankaNextRoot.tsx
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Next.js host for forked Planka client (vendor).
|
||||||
|
* Single React tree — Planka Root as child (no iframe / second createRoot).
|
||||||
|
*/
|
||||||
|
import Link from "next/link";
|
||||||
|
import {
|
||||||
|
Component,
|
||||||
|
type ComponentType,
|
||||||
|
type ErrorInfo,
|
||||||
|
type ReactNode,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
|
import { socialPath } from "@social/lib/socialPath";
|
||||||
|
import "./nomadro-planka.css";
|
||||||
|
import "./shell.css";
|
||||||
|
|
||||||
|
type RootProps = {
|
||||||
|
store: unknown;
|
||||||
|
history: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Bundle = {
|
||||||
|
Root: ComponentType<RootProps>;
|
||||||
|
store: unknown;
|
||||||
|
history: unknown;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PlankaErrorBoundary extends Component<
|
||||||
|
{ children: ReactNode },
|
||||||
|
{ error: string }
|
||||||
|
> {
|
||||||
|
state = { error: "" };
|
||||||
|
static getDerivedStateFromError(error: Error) {
|
||||||
|
return { error: error.message || String(error) };
|
||||||
|
}
|
||||||
|
componentDidCatch(error: Error, info: ErrorInfo) {
|
||||||
|
console.error("[planka-next]", error, info);
|
||||||
|
}
|
||||||
|
render() {
|
||||||
|
if (this.state.error) {
|
||||||
|
return (
|
||||||
|
<div className="planka-next-err" role="alert">
|
||||||
|
<p>Planka 渲染错误:{this.state.error}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return this.props.children;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function PlankaNextRoot() {
|
||||||
|
const [bundle, setBundle] = useState<Bundle | null>(null);
|
||||||
|
const [err, setErr] = useState("");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const [{ default: store }, { default: history }, { default: Root }] =
|
||||||
|
await Promise.all([
|
||||||
|
import("../vendor/store.js"),
|
||||||
|
import("../vendor/history.js"),
|
||||||
|
import("../vendor/components/common/Root.jsx"),
|
||||||
|
]);
|
||||||
|
await import("../vendor/i18n.js");
|
||||||
|
if (!cancelled) {
|
||||||
|
setBundle({ Root, store, history });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("[planka-next] load", e);
|
||||||
|
if (!cancelled) setErr(e instanceof Error ? e.message : String(e));
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const Root = bundle?.Root;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="planka-next-shell">
|
||||||
|
<header className="planka-next-bar">
|
||||||
|
<Link href={socialPath("/work")}>← 远程工作</Link>
|
||||||
|
<strong>看板协作</strong>
|
||||||
|
<span className={`dot ${bundle ? "on" : ""}`} />
|
||||||
|
</header>
|
||||||
|
{err ? (
|
||||||
|
<div className="planka-next-err" role="alert">
|
||||||
|
<p>Planka Next 加载失败:{err}</p>
|
||||||
|
<p>
|
||||||
|
先 <code>pnpm work:sync-ui && pnpm work:patch-ui</code>,并保证{" "}
|
||||||
|
<code>/work-api</code> 代理到 Planka 服务端。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div id="planka-next-root" className="planka-next-body">
|
||||||
|
<PlankaErrorBoundary>
|
||||||
|
{Root && bundle ? (
|
||||||
|
<Root store={bundle.store} history={bundle.history} />
|
||||||
|
) : !err ? (
|
||||||
|
<div className="planka-next-loading">正在装载 Planka 前端源码…</div>
|
||||||
|
) : null}
|
||||||
|
</PlankaErrorBoundary>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
22
src/modules/work/planka/bridge/SvgIcon.jsx
Normal file
22
src/modules/work/planka/bridge/SvgIcon.jsx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*! Nomadro shim for Planka Vite `*.svg?react` imports */
|
||||||
|
export default function SvgIcon(props) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
aria-hidden
|
||||||
|
{...props}
|
||||||
|
style={{
|
||||||
|
display: "inline-block",
|
||||||
|
width: "1em",
|
||||||
|
height: "1em",
|
||||||
|
background: "currentColor",
|
||||||
|
maskImage:
|
||||||
|
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 5v14M5 12h14'/%3E%3C/svg%3E\")",
|
||||||
|
WebkitMaskImage:
|
||||||
|
"url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M12 5v14M5 12h14'/%3E%3C/svg%3E\")",
|
||||||
|
maskSize: "contain",
|
||||||
|
WebkitMaskSize: "contain",
|
||||||
|
...props.style,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
20
src/modules/work/planka/bridge/nomadro-planka.css
Normal file
20
src/modules/work/planka/bridge/nomadro-planka.css
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* Nomadro × Planka secondary-dev skin (dark / amber) */
|
||||||
|
:root {
|
||||||
|
--nomadro-amber: #f59e0b;
|
||||||
|
--nomadro-ink: #0c0c0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#planka-next-root {
|
||||||
|
background: var(--nomadro-ink) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#planka-next-root {
|
||||||
|
min-height: 100dvh;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#planka-next-root a {
|
||||||
|
color: var(--nomadro-amber);
|
||||||
|
}
|
||||||
62
src/modules/work/planka/bridge/shell.css
Normal file
62
src/modules/work/planka/bridge/shell.css
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
.planka-next-shell {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 80;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: #0c0c0f;
|
||||||
|
color: #e2e8f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-bar {
|
||||||
|
flex: 0 0 44px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0 0.85rem;
|
||||||
|
border-bottom: 1px solid rgba(148, 163, 184, 0.16);
|
||||||
|
background: linear-gradient(180deg, rgba(245, 158, 11, 0.08), transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-bar a {
|
||||||
|
color: #f59e0b;
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-bar .dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #64748b;
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-bar .dot.on {
|
||||||
|
background: #22c55e;
|
||||||
|
box-shadow: 0 0 8px rgba(34, 197, 94, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-body {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: auto;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-loading {
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
height: 100%;
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
|
||||||
|
.planka-next-err {
|
||||||
|
margin: 0.75rem;
|
||||||
|
padding: 0.85rem 1rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
border: 1px solid rgba(248, 113, 113, 0.4);
|
||||||
|
background: rgba(248, 113, 113, 0.08);
|
||||||
|
font-size: 0.9rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
@ -23,6 +23,7 @@
|
|||||||
"@social/*": ["./src/modules/social/*"],
|
"@social/*": ["./src/modules/social/*"],
|
||||||
"@navmini/*": ["./src/modules/nav/*"],
|
"@navmini/*": ["./src/modules/nav/*"],
|
||||||
"@vip/*": ["./src/modules/vip/*"],
|
"@vip/*": ["./src/modules/vip/*"],
|
||||||
|
"@work/*": ["./src/modules/work/*"],
|
||||||
"@nomadro/pay": ["./packages/pay/src/index.ts"],
|
"@nomadro/pay": ["./packages/pay/src/index.ts"],
|
||||||
"@nomadro/pb": ["./packages/pb/src/index.ts"],
|
"@nomadro/pb": ["./packages/pb/src/index.ts"],
|
||||||
"@nomadro/sdk": ["./packages/sdk/src/index.ts"]
|
"@nomadro/sdk": ["./packages/sdk/src/index.ts"]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user