@pactor-app/app 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/dist/index.cjs +680 -0
- package/dist/index.d.cts +278 -0
- package/dist/index.d.ts +278 -0
- package/dist/index.js +672 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pactor Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @pactor-app/app
|
|
2
|
+
|
|
3
|
+
[Pactor](https://github.com/426-330/pactor) 的一站式组合层(设计文档第 86–89 节)。业务工程只调 `createPactorApplication({ appId, api }).mount('#root')` 即可完成:DSL 资源加载(loader)→ bootstrap 编排(权限 / 菜单 / 布局)→ 共享 registries(内置组件 + 交互动作 + 业务扩展)→ react-router 动态路由 → 布局外壳 → PageRuntime 页面渲染 → Overlay/Provider 集成 → 启动与页面错误兜底。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pactor-app/app @pactor-app/ui react react-dom react-router-dom
|
|
9
|
+
# 或
|
|
10
|
+
pnpm add @pactor-app/app @pactor-app/ui react react-dom react-router-dom
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react >= 18`、`react-dom >= 18`、`react-router-dom >= 6` 为 peer dependency(开发基准为 react-router-dom v7)。内置 UI kit 为 `@pactor-app/ui`(shadcn,传递依赖),需导入其预建样式表 `import '@pactor-app/ui/styles.css'`。
|
|
14
|
+
|
|
15
|
+
## 一站式用法
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { createPactorApplication } from '@pactor-app/app';
|
|
19
|
+
|
|
20
|
+
createPactorApplication({
|
|
21
|
+
appId: 'risk-admin',
|
|
22
|
+
api: { baseURL: '/api/runtime' }, // 缺省即 '/api/runtime'
|
|
23
|
+
authTokenProvider: () => getToken(), // 可选,注入 Authorization: Bearer
|
|
24
|
+
}).mount('#root');
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
服务端需提供 `{baseURL}/bootstrap` 与 `{baseURL}/pages/{id}` 端点(@pactor-app/resource Envelope 协议);bootstrap 期望字段(全部可选):`app.name`、`user`、`permissions`、`menus`、`layout.type` 与布局开关(`header`/`sidebar`/`tabs`/`breadcrumb`/`footer`)、`pageVersions`。
|
|
28
|
+
|
|
29
|
+
## Options
|
|
30
|
+
|
|
31
|
+
| 字段 | 说明 |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| `appId`(必填) | 应用 id:app 作用域缺省 `id`、brand 缺省标题回退 |
|
|
34
|
+
| `api.baseURL` | DSL 资源 API 基础路径(缺省 `/api/runtime`),未注入 loader 时创建 `HttpDslResourceLoader` |
|
|
35
|
+
| `loader` | 自定义 `DslResourceLoader`(优先于 api;测试/本地用 `StaticDslLoader`) |
|
|
36
|
+
| `layout` | 布局类型覆盖(优先级:`options.layout` > `bootstrap.layout.type` > `'admin'`) |
|
|
37
|
+
| `brand` | 品牌区覆盖(缺省取 `bootstrap.app.name`,再回退 `appId`) |
|
|
38
|
+
| `router` | `{ type?: 'browser' \| 'hash', basename?: string }`(V1 支持 browser + basename) |
|
|
39
|
+
| `components` / `actions` / `services` / `capabilities` | 业务扩展,写入应用级共享 registry(同名覆盖内置) |
|
|
40
|
+
| `authTokenProvider` | 认证令牌:注入 DSL 资源请求与页面 HTTP 出口(`Authorization: Bearer`) |
|
|
41
|
+
|
|
42
|
+
## 启动编排
|
|
43
|
+
|
|
44
|
+
mount 后依次:加载 bootstrap(全屏 loading)→ `PermissionStore` 写入 `permissions`(缺省 `[]`)→ `MenuRegistry(menus)`(缺省 `[]`)→ 解析布局 → 组装共享 registries 与 adapters。bootstrap 失败渲染含**重试**按钮的启动错误页,不白屏。
|
|
45
|
+
|
|
46
|
+
应用级共享 registries 被所有页面 PageRuntime 共享:内置组件(@pactor-app/ui components 层)+ 交互动作(overlay.open / overlay.close / confirm / message,应用级 OverlayManager / UiBridge 单例)+ navigate 动作 + options 扩展。页面运行时创建时注入 permission / router / http adapters 与 route context(`route.params` / `route.query`)、`user`(bootstrap.user)、`app`(bootstrap.app)。
|
|
47
|
+
|
|
48
|
+
## 扩展注册 API
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const app = createPactorApplication({ appId: 'risk-admin', api: { baseURL: '/api/runtime' } });
|
|
52
|
+
|
|
53
|
+
app.registerComponent('StrategyFlow', StrategyFlow);
|
|
54
|
+
app.registerAction('strategy.export', exportStrategy);
|
|
55
|
+
app.registerService('strategy', strategyService);
|
|
56
|
+
app.registerCapability('strategy.backtest', backtestCapability);
|
|
57
|
+
|
|
58
|
+
app.mount('#root');
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
写入应用级共享 registry(同名覆盖);新创建/重建的页面即可用(当前已创建页面下次重建后生效)。`app.unmount()` 卸载根;重复 `mount` 会先卸载旧根。
|
|
62
|
+
|
|
63
|
+
## 页面加载与错误兜底
|
|
64
|
+
|
|
65
|
+
- 页面切换:`pageId` 或 `route.params`/`query` 变化即销毁旧运行时重建(V1 无 keepAlive);
|
|
66
|
+
- 加载中渲染 loading 态;加载/校验失败渲染含重试的受控错误页;渲染期异常由 ErrorBoundary 捕获显示错误页,外壳不崩溃;
|
|
67
|
+
- 未命中路径渲染 404,命中但无权限渲染 403(菜单项 `permission` 配置);
|
|
68
|
+
- `overlay.open` 的 page 类型 overlay 经 loader 加载页面 DSL,子运行时共享应用级 registries。
|
|
69
|
+
|
|
70
|
+
## 文档
|
|
71
|
+
|
|
72
|
+
完整文档见 <https://github.com/426-330/pactor/tree/main/docs>(`pnpm docs:dev` 本地启动文档站)。
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
[MIT](../../LICENSE)
|