Files
EasyDesignCollection/lib/modules/README.md
T
admin 0a3f2c5cc6 v1.3.13: 模块化注册架构 + PDS流程设计套件更名 + 依赖/圆周交互修复
- 模块化:EdcModule 契约 + registry + 模块独立目录;发布包增加 modules/registry.json
- 更名:PDS流程设计套件 / ProcessDesignSuite;同步构建、发布脚本与文档
- 时序图:依赖偏移以时间显示/编辑;紧贴依赖隐藏箭头并在接缝显示标签;动作条磁吸
- 圆周:依赖标签沿圆弧方向、环间空隙;动作旋转磁吸增强;短弧标签优先动作名
- 清理:release 移至源码同级(本地不入库);tool 合并到 tools;发布说明迁移 docs/release-notes
2026-11-22 10:02:54 +08:00

151 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 模块开发速查
> 本目录下每个子目录 = 一个功能模块。模块入口实现 `EdcModule`,然后在
> `registry.dart` 注册。**不要修改 `lib/ui/app_shell.dart` 来加入模块专属逻辑。**
## 目录约定
```text
modules/
├── module.dart # 契约:EdcModule / ModuleUiContext / PlannedModule
├── registry.dart # ★ 唯一注册表
├── <id>/
│ ├── <id>_module.dart # 模块入口(元数据 / 文档生命周期 / UI 委托)
│ ├── domain/ # 可选:模块领域模型
│ ├── layout/ # 可选:几何布局
│ ├── render/ # 可选:绘制
│ ├── export/ # 可选:导出
│ └── ui/ # 可选:模块 UI(工作区 / 工具栏 / 侧栏 / 状态栏)
```
## 最小模块模板
```dart
import 'package:flutter/material.dart';
import 'package:sequence_diagram/modules/module.dart';
import 'package:sequence_diagram/state/app_controller.dart';
const FooModule fooModule = FooModule();
class FooModule extends EdcModule {
const FooModule();
@override
String get id => 'foo';
@override
String get name => '示例图';
@override
String get shortName => '示例';
@override
IconData get icon => Icons.widgets_outlined;
@override
int get accent => 0xFF38BDF8;
@override
String get suffix => '.foo.json';
@override
bool get available => true;
@override
String get defaultName => '未命名-示例图';
@override
String get blurb => '一句话简介';
@override
void newDocument(AppController c) {}
@override
void loadDocument(AppController c, String source, {String? path}) {}
@override
String encodeDocument(AppController c) => '{}';
@override
String documentName(AppController c) => '示例图';
@override
String? filePath(AppController c) => null;
@override
bool isDirty(AppController c) => false;
@override
Future<void> saveTo(AppController c, String path) async {}
@override
Future<void> markSaved(AppController c, String displayPath) async {}
@override
Widget buildWorkspace(ModuleUiContext ui) =>
const Center(child: Text('Foo module'));
@override
Widget buildStatusBar(ModuleUiContext ui) =>
Text('示例图', style: TextStyle(color: ui.tokens.dim, fontSize: 11));
}
```
注册:
```dart
// registry.dart
import 'package:sequence_diagram/modules/foo/foo_module.dart';
const List<EdcModule> kModules = <EdcModule>[
architectureModule,
sequenceModule,
fooModule,
...
];
```
## 可选扩展点
| 方法 / 属性 | 作用 |
| --- | --- |
| `buildToolbarCenter(ui, compact:)` | 工具栏中段工具(视图切换 / 模块工具) |
| `buildToolbarRight(ui)` | 工具栏右侧工具(导出 / 缩放 / 适应视图 / 单位) |
| `buildLeftPanel(ui, floating:)` | 左侧栏;`hasLeftPanel` 控制外壳是否显示停靠 / 轨道 |
| `buildRightPanel(ui, floating:)` | 右侧栏;`hasRightPanel` 同上 |
| `buildStatusBar(ui)` | 底部状态栏 |
| `buildShortcuts(ui)` | 模块快捷键,与外壳公共快捷键合并 |
| `isReadOnly(c)` | 只读视图(撤销 / 重做置灰) |
| `enterStatus` | 进入模块时的状态栏提示 |
`ModuleUiContext` 提供:
- `context / controller / tokens`
- `compact / toolScale / toolFont`
- `leftRail / rightRail / leftPanelWidth / rightPanelWidth`
- `panelControls(left)`(外壳的钉住 / 收起按钮)
## 规范
1. 模块内使用 `package:sequence_diagram/...` 绝对导入。
2. 模块之间禁止互相 import;共享代码上移到 `lib/` 公共层或 `lib/export/`。
3. 不要在模块 UI 里硬编码品牌名 / 模块名;使用 `ui.controller.activeModuleId` +
`registry` 或模块元数据。
4. 文档新增字段必须可缺省,保证旧 JSON 可打开。
5. 新增模块必须补测试:注册表唯一性、打开 / 保存、首页与品牌菜单。
6. 只改 `registry.dart` 一处全局文件;如果发现必须改 `AppShell`,说明契约缺少
扩展点,应优先扩展契约而不是加分支。
## 发布级模块清单
发布包内包含:
```text
ProcessDesignSuite/modules/
├── registry.json # 顺序 / 显示名 / 颜色 / 启用状态
├── architecture/module.json
├── sequence/module.json
└── elec/io/topo/pid/module.json
```
- 源码模板在 `assets/modules/`,构建时复制到发布包 `modules/`。
- 启动时桌面优先读取 exe 同级 `modules/registry.json`,安卓读取内置
`assets/modules/registry.json`;失败回退 `registry.dart`。
- 清单可以调整顺序 / 名称 / 颜色 / 启用状态;未编译进应用的模块显示为
「组件未安装」。**新增 UI 代码仍需重新构建应用(Flutter AOT 限制)**。
## 规划中模块
`elec` / `io` / `topo` / `pid` 已用 `PlannedModule` 占位并注册,首页灰显。
实现时:
1. 在对应目录新增领域模型与 UI;
2. 把 `extends PlannedModule` 改为 `extends EdcModule`(或继承新的真实模块类);
3. 补齐文档生命周期与 `available => true`;
4. 注册表无需变动(已经登记)。