@pactor-app/runtime 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 +54 -0
- package/dist/index.cjs +938 -0
- package/dist/index.d.cts +447 -0
- package/dist/index.d.ts +447 -0
- package/dist/index.js +909 -0
- package/package.json +69 -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,54 @@
|
|
|
1
|
+
# @pactor-app/runtime
|
|
2
|
+
|
|
3
|
+
[Pactor](https://github.com/426-330/pactor) 的运行时引擎包:把 PageDsl 运行起来——RuntimeContext 组装、StateStore、DataSource 运行时、Action 引擎、React Renderer 与 PageRuntime 完整链路。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @pactor-app/runtime react
|
|
9
|
+
# 或
|
|
10
|
+
pnpm add @pactor-app/runtime react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`react >= 18` 为 peer dependency。非 React 部分(context / state / datasource / action)零 React 依赖,可脱离 React 单独使用与测试。
|
|
14
|
+
|
|
15
|
+
## 示例
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { createPageRuntime, PageRuntimeView } from '@pactor-app/runtime';
|
|
19
|
+
|
|
20
|
+
const runtime = createPageRuntime(pageDsl, {
|
|
21
|
+
// 可选:注入自定义 Registry / Adapter
|
|
22
|
+
// services / components / permission / router / http ...
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 注册组件与服务
|
|
26
|
+
runtime.context.components.register('Button', Button);
|
|
27
|
+
runtime.context.services.register('customer.list', async (params) => fetchList(params));
|
|
28
|
+
|
|
29
|
+
await runtime.initialized; // autoLoad + onInit + onLoad 完成
|
|
30
|
+
|
|
31
|
+
// React 渲染入口
|
|
32
|
+
<PageRuntimeView runtime={runtime} />;
|
|
33
|
+
|
|
34
|
+
// 宿主(Router)触发生命周期
|
|
35
|
+
await runtime.show();
|
|
36
|
+
await runtime.destroy();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 功能一览
|
|
40
|
+
|
|
41
|
+
- **RuntimeContext**:`createRuntimeContext(options)` 组装 `app / page / state / data / route / user / services / components / actions / permission / capabilities`,支持注入自定义 Registry 与 Adapter(permission 默认放行、navigate 默认 no-op、http 默认基于全局 fetch,可替换)。
|
|
42
|
+
- **StateStore**:框架无关的最小状态容器,`getState() / get('a.b.c') / set(patch) / set('a.b', v) / reset() / subscribe()`,全部不可变更新。
|
|
43
|
+
- **DataSource 运行时**:`static / service / http` 三种类型,`autoLoad`、`loading / error / data` 状态、params 表达式求值、`refresh(name)` / `reload(name?)`;错误写入 `error` 状态,不抛到渲染层。
|
|
44
|
+
- **Action 引擎**:`condition` 跳过 → `permission` 拦截 → Registry 执行的管线,全程受控返回 `{ ok, data?, error?, skipped? }`;内置 UI 无关动作 `setState / resetState / reload / request / sequence / parallel / if / delay`。
|
|
45
|
+
- **React Renderer**:`<DslRenderer>` 递归渲染 DSL 树——props 深度表达式解析、`when` 条件渲染、`events` 绑定(事件对象注入 `event` 作用域)、未注册组件渲染 `UnsupportedComponent` 占位、`withScope` 子作用域机制(`useRenderer().renderChildren(children, { row, rowIndex })`)。
|
|
46
|
+
- **PageRuntime**:`createPageRuntime(pageDsl)` 完成 校验(失败抛 `PageRuntimeError`)→ 上下文组装 → autoLoad → 生命周期的完整链路。
|
|
47
|
+
|
|
48
|
+
## 文档
|
|
49
|
+
|
|
50
|
+
完整文档见 <https://github.com/426-330/pactor/tree/main/docs>(`pnpm docs:dev` 本地启动文档站)。
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
[MIT](../../LICENSE)
|