@worm-print-platform/plugin-kit 1.5.0 → 1.5.3
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/README.md +49 -35
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@worm-print-platform/plugin-kit</strong><br>
|
|
3
|
+
<em>插件设计器 UI 契约与注册表(框架无关)</em>
|
|
4
|
+
</p>
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
<p align="center">
|
|
7
|
+
<img src="https://img.shields.io/badge/npm-v1.5.3-384BFF" alt="npm">
|
|
8
|
+
<img src="https://img.shields.io/badge/license-MIT-9A9A9A" alt="license">
|
|
9
|
+
</p>
|
|
4
10
|
|
|
5
|
-
|
|
11
|
+
> monorepo 根:[worm-print-platform](https://github.com/worm-longliu/worm-print-platform)
|
|
12
|
+
|
|
13
|
+
自定义元素的**框架无关设计器 UI 契约与注册表**。插件作者只写一份 DOM 渲染能力(返回 HTML 字符串或 DOM 节点),即可同时被两类宿主消费:
|
|
6
14
|
|
|
7
15
|
| 宿主 | 消费方式 |
|
|
8
16
|
| --- | --- |
|
|
9
17
|
| `@worm-print-platform/canvas` | 零框架原生挂载:素材卡、画布、属性台「自定义属性」页签直接使用 UI |
|
|
10
|
-
| `@worm-
|
|
11
|
-
|
|
12
|
-
> 状态:随工作区主线开发,**尚未发布到 npm**;通过 workspace / `file:` 依赖接入。
|
|
18
|
+
| `@worm-print-platform/canvas/vue3` | Vue 3 门面:复用同一份 UI 契约 |
|
|
13
19
|
|
|
14
20
|
## 与 core 插件描述符的关系
|
|
15
21
|
|
|
16
|
-
- **元素语义**(kind
|
|
17
|
-
|
|
18
|
-
- **设计器 UI**(画布长什么样、属性台怎么改)由本包的 `defineElementUI` + `registerElementUI` 声明。
|
|
22
|
+
- **元素语义**(kind 类型、标签、图标、默认值、绑定、出图、校验)由 `@worm-print-platform/core/designer` 的 `defineElementPlugin` + `registerElementPlugin` 声明。
|
|
23
|
+
- **设计器 UI**(画布渲染什么样、属性台怎么改)由本包的 `defineElementUI` + `registerElementUI` 声明。
|
|
19
24
|
- 两者用元素 `type` 关联:宿主只展示「core 注册表里有 kind 且 plugin-kit 里有 UI」的元素,避免出现无法渲染的素材卡。
|
|
20
25
|
|
|
21
|
-
##
|
|
26
|
+
## 安装
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm i @worm-print-platform/plugin-kit
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 契约与使用
|
|
22
33
|
|
|
23
34
|
```ts
|
|
24
35
|
import { defineElementUI, registerElementUI } from '@worm-print-platform/plugin-kit'
|
|
@@ -29,7 +40,6 @@ export const MY_ELEMENT_UI = defineElementUI({
|
|
|
29
40
|
renderProperty: ({ element, update }) => {
|
|
30
41
|
const form = document.createElement('form')
|
|
31
42
|
form.className = 'pd-form'
|
|
32
|
-
// …原生 DOM 构建,控件类名与 canvas / common 的 .pd-* 一致即可复用两侧样式
|
|
33
43
|
const input = document.createElement('input')
|
|
34
44
|
input.className = 'pd-input'
|
|
35
45
|
input.value = String(element.options.myText ?? '')
|
|
@@ -38,14 +48,12 @@ export const MY_ELEMENT_UI = defineElementUI({
|
|
|
38
48
|
return form
|
|
39
49
|
},
|
|
40
50
|
hasProperties: element => element.options.myText !== undefined,
|
|
41
|
-
// 素材卡分组:core 描述符的 designer.materialCard.group 优先,缺省回落到这里
|
|
42
51
|
group: '我的元素',
|
|
43
52
|
searchKeywords: ['我的元素', 'myElement'],
|
|
44
53
|
styles: '.my-element-row { display: flex; gap: 6px; }',
|
|
45
54
|
})
|
|
46
55
|
|
|
47
|
-
// 包入口 import
|
|
48
|
-
registerElementUI(MY_ELEMENT_UI)
|
|
56
|
+
registerElementUI(MY_ELEMENT_UI) // 包入口 import 即注册
|
|
49
57
|
```
|
|
50
58
|
|
|
51
59
|
### 渲染结果
|
|
@@ -60,29 +68,18 @@ registerElementUI(MY_ELEMENT_UI)
|
|
|
60
68
|
|
|
61
69
|
### 设计态上下文:`data` 与 `fields`
|
|
62
70
|
|
|
63
|
-
两个渲染函数都会收到 `data`(数组信封,`data[0]` 是数据根对象);属性台还额外收到 `fields`:
|
|
64
|
-
|
|
65
71
|
| 字段 | 来源 | 用途 |
|
|
66
72
|
| --- | --- | --- |
|
|
67
73
|
| `data` | 宿主注入的设计态示例数据;未注入时回落 core 的 `DEFAULT_DEMO_DATA` | 画布预览按真实业务数据出图(图表类插件的柱子/扇区由此而来) |
|
|
68
|
-
| `fields` | 宿主的业务字段清单(`fieldKey` / `fieldLabel` / `fieldType`) | 生成「数据源 / 类目 /
|
|
69
|
-
|
|
70
|
-
`@worm-print-platform/canvas` 宿主用 `el.designData = {...}`(或 `design-data` attribute 的 JSON 串)注入示例数据,
|
|
71
|
-
单对象会自动归一成 `[对象]`;`fields` 来自 `el.fields`。未注入时 `fields` 为空数组,插件应回落 `data[0]` 的键。
|
|
72
|
-
Vue 3 的 `@worm-vue3-print/canvas` 属性台透传宿主的 `fields`,画布组件则透传宿主的 `printData`。
|
|
74
|
+
| `fields` | 宿主的业务字段清单(`fieldKey` / `fieldLabel` / `fieldType`) | 生成「数据源 / 类目 / 数值字段」下拉 |
|
|
73
75
|
|
|
74
76
|
### 属性写回
|
|
75
77
|
|
|
76
|
-
属性上下文只提供 `update(partial)` / `repaint()`(`data` / `fields`
|
|
78
|
+
属性上下文只提供 `update(partial)` / `repaint()`(`data` / `fields` 只读):
|
|
77
79
|
|
|
78
|
-
- `update(partial)`:宿主把补丁合并进 `element.options
|
|
80
|
+
- `update(partial)`:宿主把补丁合并进 `element.options`、记一条历史并重绘。
|
|
79
81
|
- `repaint()`:只请求重绘,不写数据、不记历史。
|
|
80
|
-
- 插件不得绕过宿主直接改 store
|
|
81
|
-
|
|
82
|
-
### 事件建议
|
|
83
|
-
|
|
84
|
-
- **common** 的属性台是整树重绘模型,文本输入用 `change`(失焦/回车提交)而不是 `input`,否则每次提交都会重建 DOM、丢失焦点。
|
|
85
|
-
- **canvas** 的桥接组件对「自身 update 引起的变化」不做重渲染,对撤销/外部程序化修改会重渲染,因此同一份 UI 在两侧都可连续输入。
|
|
82
|
+
- 插件不得绕过宿主直接改 store。
|
|
86
83
|
|
|
87
84
|
## 注册表 API
|
|
88
85
|
|
|
@@ -92,16 +89,33 @@ Vue 3 的 `@worm-vue3-print/canvas` 属性台透传宿主的 `fields`,画布
|
|
|
92
89
|
| `registerElementUI(ui)` | 注册;同 type 后注册者覆盖,返回只注销自己这一版的句柄 |
|
|
93
90
|
| `getElementUI(type)` | 按元素类型取 UI |
|
|
94
91
|
| `getElementUIEntries()` | `{ type, ui }[]`,供宿主生成素材卡/属性页签 |
|
|
95
|
-
| `getElementUIs()` | 去重后的 UI 列表(一份 UI 覆盖多 type 时只返回一次) |
|
|
96
|
-
| `getElementUITypes()` | 已注册类型 |
|
|
97
92
|
| `subscribeElementUIRegistry(fn)` | 订阅注册态变化,宿主据此刷新素材台/属性台 |
|
|
98
93
|
| `clearElementUIs()` | 清空(单测/热重载) |
|
|
99
94
|
|
|
100
|
-
注册态挂在 `globalThis` 的固定 `Symbol` 上,与 core
|
|
101
|
-
出现「注册在这份、查询在那份」的漂移。因此 common 的 UMD 直挂形态与插件的 ESM 形态可以共享同一份注册态。
|
|
95
|
+
注册态挂在 `globalThis` 的固定 `Symbol` 上,与 core 元素插件注册表同一约定,避免多打包副本漂移。
|
|
102
96
|
|
|
103
97
|
## 边界
|
|
104
98
|
|
|
105
99
|
- 本包纯 TS,不依赖 Vue / React / 任何 UI 组件库;DOM 操作只在渲染函数被宿主调用时发生。
|
|
106
|
-
- 插件 UI
|
|
107
|
-
-
|
|
100
|
+
- 插件 UI 用样式串注入宿主样式作用域,不提供独立 CSS 文件。
|
|
101
|
+
- 出纸仍走 `@worm-print-platform/core` 的通用渲染协议,本包不负责。
|
|
102
|
+
|
|
103
|
+
## 开发
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run build # tsup
|
|
107
|
+
npm test # vitest
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 参考实现
|
|
111
|
+
|
|
112
|
+
- 官方图表插件:[`@worm-print-platform/echarts`](../echarts/README.md) — 用 `/kit` 提供框架无关纯 TS 能力,`/ui` 提供 plugin-kit 适配层
|
|
113
|
+
|
|
114
|
+
## 相关链接
|
|
115
|
+
|
|
116
|
+
- [根 README](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md)
|
|
117
|
+
- [插件化自定义元素章节](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md#插件化自定义元素)
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](../../LICENSE)
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@worm-print-platform/plugin-kit",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "打印模板自定义元素的框架无关设计器 UI 契约与注册表:插件写一份 DOM 渲染能力,canvas(原生)与 /vue3(门面)同时消费",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test:watch": "vitest"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@worm-print-platform/core": "^1.5.
|
|
39
|
+
"@worm-print-platform/core": "^1.5.3"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"happy-dom": "^20.10.6",
|