mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-06-12 18:32:00 +00:00
Compare commits
89 Commits
v1.7.14-be
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27fac02e99 | ||
|
|
1298104732 | ||
|
|
9fe10e274c | ||
|
|
89cef4e9a9 | ||
|
|
273d13dd1f | ||
|
|
771880b994 | ||
|
|
113af7dd51 | ||
|
|
846f05e04d | ||
|
|
fd652b0d13 | ||
|
|
7d45aa5eec | ||
|
|
171d31e207 | ||
|
|
6ba59c0d14 | ||
|
|
4f284e8d9c | ||
|
|
c4ec2c5c72 | ||
|
|
48519b0155 | ||
|
|
a965dfb06e | ||
|
|
614f12adf3 | ||
|
|
bddc6f343c | ||
|
|
be3a900e6a | ||
|
|
bc555ebdc0 | ||
|
|
b7d1cea7c1 | ||
|
|
3bd0eecb42 | ||
|
|
cd19dec790 | ||
|
|
10b70c36bb | ||
|
|
27b2c2c685 | ||
|
|
a8a9cf372d | ||
|
|
6253d7ed23 | ||
|
|
444d4223a9 | ||
|
|
a9e9e65f9c | ||
|
|
42162f2e4a | ||
|
|
7a161cab00 | ||
|
|
1cd69b33fe | ||
|
|
12069e0937 | ||
|
|
1b66ab1b88 | ||
|
|
64d35d5363 | ||
|
|
35fc394199 | ||
|
|
8612311db1 | ||
|
|
818b41f07f | ||
|
|
9b34124805 | ||
|
|
7a61a35664 | ||
|
|
025cca365c | ||
|
|
a3333e2b4e | ||
|
|
cbc4b25072 | ||
|
|
b02aa75ddc | ||
|
|
f0c66427b8 | ||
|
|
c854dfa8bf | ||
|
|
59f4e0edac | ||
|
|
0f8abf7298 | ||
|
|
62a2ee6693 | ||
|
|
0446202ba6 | ||
|
|
285434ef3e | ||
|
|
8dae67769c | ||
|
|
09558fa027 | ||
|
|
4c855ba50b | ||
|
|
e2c065f90d | ||
|
|
a341c7d73e | ||
|
|
de94a75803 | ||
|
|
d01a28ce76 | ||
|
|
6c40425d8c | ||
|
|
b8b0490260 | ||
|
|
2846f9eb2a | ||
|
|
62fc818ae1 | ||
|
|
ff810d09e4 | ||
|
|
b1193b909e | ||
|
|
540a2716d8 | ||
|
|
a1fcb191d2 | ||
|
|
b9a6dd5b84 | ||
|
|
08011efd6d | ||
|
|
fbbd05e291 | ||
|
|
9b65917371 | ||
|
|
3d038513e3 | ||
|
|
eb1c5a3ec1 | ||
|
|
7ff590b1b6 | ||
|
|
7eeb9b544e | ||
|
|
638c3e9f3c | ||
|
|
2d31b3812f | ||
|
|
05e512b1fe | ||
|
|
1e69bc221d | ||
|
|
12ce19fb02 | ||
|
|
aa2ee9fd4b | ||
|
|
f00e84793d | ||
|
|
297e5cebb0 | ||
|
|
5ba2019d0b | ||
|
|
c45df6f6ec | ||
|
|
f1aedc4ce7 | ||
|
|
873a51fc87 | ||
|
|
d16ab9a805 | ||
|
|
df8790042f | ||
|
|
e64d86660d |
161
CHANGELOG.md
161
CHANGELOG.md
@ -1,3 +1,164 @@
|
||||
# [1.8.0-beta.5](https://github.com/Tencent/tmagic-editor/compare/v1.8.0-beta.4...v1.8.0-beta.5) (2026-06-11)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **editor:** 优化历史回滚确认流程 ([48519b0](https://github.com/Tencent/tmagic-editor/commit/48519b0155a7cda8226217fa3bfd97a92410a7a6))
|
||||
* **editor:** 修复历史对比属性配置上下文缺失 ([be3a900](https://github.com/Tencent/tmagic-editor/commit/be3a900e6a132751f3b1d59c06b850c00604ee15))
|
||||
* **stage:** 复用 TargetShadow 修正闪烁高亮定位 ([171d31e](https://github.com/Tencent/tmagic-editor/commit/171d31e20797ab0e68ac8b2a4c39740e1f636634))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **design:** popover 支持点击外部关闭 ([846f05e](https://github.com/Tencent/tmagic-editor/commit/846f05e04d6d85d37611148185eae93661e9d0da))
|
||||
* **editor:** 将侧边栏激活面板状态同步至 uiService ([6ba59c0](https://github.com/Tencent/tmagic-editor/commit/6ba59c0d141947727c83bc708c9fb7fc6b71a47f))
|
||||
* **editor:** 支持历史记录持久化 ([614f12a](https://github.com/Tencent/tmagic-editor/commit/614f12adf3174a4dadac028bda27057d18831a81))
|
||||
* **editor:** 支持按历史记录 uuid 回滚 ([bddc6f3](https://github.com/Tencent/tmagic-editor/commit/bddc6f343cc97d3034c869c3fc46780759134f7c))
|
||||
* **editor:** 支持页面初始基线与 root 变更历史记录 ([4f284e8](https://github.com/Tencent/tmagic-editor/commit/4f284e8d9cf6af9af234d345c14a2bf9176e5284))
|
||||
* **editor:** 页面删除前增加确认弹窗并支持危险样式按钮 ([113af7d](https://github.com/Tencent/tmagic-editor/commit/113af7dd5104f5f49515abd66f12f5e62098f7e2))
|
||||
* **editor:** 页面历史记录点击选中对应画布节点 ([fd652b0](https://github.com/Tencent/tmagic-editor/commit/fd652b0d13a2bf87db55d03013dc2c9ff01ff45d))
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* **editor:** 优化节点信息查找性能 ([c4ec2c5](https://github.com/Tencent/tmagic-editor/commit/c4ec2c5c722963c95141ac2d2ddf94d952d2e47d))
|
||||
|
||||
|
||||
|
||||
# [1.8.0-beta.4](https://github.com/Tencent/tmagic-editor/compare/v1.8.0-beta.3...v1.8.0-beta.4) (2026-06-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **editor:** 修复历史对比样式配置显示 ([cd19dec](https://github.com/Tencent/tmagic-editor/commit/cd19dec7907cac5cff775f1cbde24cb3f384e87b))
|
||||
* **editor:** 修复合并历史记录信息展示 ([3bd0eec](https://github.com/Tencent/tmagic-editor/commit/3bd0eecb42d06f06f50cc4736ecc31cc07cc1886))
|
||||
* **editor:** 禁止缺少变更记录的历史回滚 ([10b70c3](https://github.com/Tencent/tmagic-editor/commit/10b70c36bbace6af48bf6fa63f2df0704c6861af))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 历史记录支持操作来源 ([27b2c2c](https://github.com/Tencent/tmagic-editor/commit/27b2c2c68598264e97a1e1ecc34121829851c85e))
|
||||
|
||||
|
||||
|
||||
# [1.8.0-beta.3](https://github.com/Tencent/tmagic-editor/compare/v1.8.0-beta.2...v1.8.0-beta.3) (2026-06-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **form:** 对比模式下无 name 字段时不展示差异 ([64d35d5](https://github.com/Tencent/tmagic-editor/commit/64d35d53631698e8d94362765a1621654bd3d1f6))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 历史记录列表展示时间并优化回滚差异弹窗 ([a9e9e65](https://github.com/Tencent/tmagic-editor/commit/a9e9e65f9c50e47b22de8eab7184cebd87632bc6))
|
||||
* **editor:** 历史记录差异对比弹窗关闭时派发 close 事件 ([42162f2](https://github.com/Tencent/tmagic-editor/commit/42162f2e4ac651ad78ff2f5291e00639a658a1ae))
|
||||
* **editor:** 历史记录面板支持自定义扩展 tab 并开放 Bucket/goto 配置 ([8612311](https://github.com/Tencent/tmagic-editor/commit/8612311db12a22adcc30188ae1ead03729fa6a7a))
|
||||
* **editor:** 对比表单支持自定义 loadConfig 加载逻辑 ([1cd69b3](https://github.com/Tencent/tmagic-editor/commit/1cd69b33fecd75fe8522d9a261e1c03e806ecf69))
|
||||
* **form:** fieldset legend 支持函数动态生成标题 ([35fc394](https://github.com/Tencent/tmagic-editor/commit/35fc39419902e14e2d5bdf98f99802f05a4b5934))
|
||||
* **form:** submitForm 支持返回 changeRecords ([12069e0](https://github.com/Tencent/tmagic-editor/commit/12069e0937589cf9b7684e4bd5ed927e15462513))
|
||||
* **stage:** 非点击画布选中组件时高亮闪烁选中区域 ([444d422](https://github.com/Tencent/tmagic-editor/commit/444d4223a943d763a33b752ffbbfa704591820ca))
|
||||
|
||||
|
||||
|
||||
# [1.8.0-beta.2](https://github.com/Tencent/tmagic-editor/compare/v1.8.0-beta.1...v1.8.0-beta.2) (2026-05-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **editor:** 修复移动到菜单导致节点引用异常的问题 ([d01a28c](https://github.com/Tencent/tmagic-editor/commit/d01a28ce76203765f333548b30b4ec2954e68d4c))
|
||||
* **editor:** 多选时对多个节点的操作合并入同一条历史记录 ([a341c7d](https://github.com/Tencent/tmagic-editor/commit/a341c7d73e78f0727c1adffce767b6806d356beb))
|
||||
* **editor:** 显式标注 CompareForm 的 defineExpose 类型以修复 DTS 构建报错 ([7a61a35](https://github.com/Tencent/tmagic-editor/commit/7a61a356649838531f4f51c45e2e76ab84474107))
|
||||
* 对比模式下关闭 tab-pane 的 lazy,确保差异数能正确统计 ([0f8abf7](https://github.com/Tencent/tmagic-editor/commit/0f8abf729854f5bfc3fbad98153a77e947ead246))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** vs-code 字段对比模式改用 monaco diff 编辑器 ([c854dfa](https://github.com/Tencent/tmagic-editor/commit/c854dfa8bf80bd501534b98c72fa1b2802076cac))
|
||||
* **editor:** 代码块与数据源支持按 id 独立的历史记录 ([e2c065f](https://github.com/Tencent/tmagic-editor/commit/e2c065f90d12d1234edd3620430262857a014ee9))
|
||||
* **editor:** 写操作支持 doNotPushHistory 选项以跳过历史记录 ([4c855ba](https://github.com/Tencent/tmagic-editor/commit/4c855ba50b69a2e0ab73f944171c4d5561d5a06a))
|
||||
* **editor:** 历史记录接入 changeRecords,undo/redo 按 propPath 局部更新 ([09558fa](https://github.com/Tencent/tmagic-editor/commit/09558fa0273af0b7d25b4338a8ea56810b09bb1c))
|
||||
* **editor:** 历史记录面板支持单步回滚(类 git revert) ([b02aa75](https://github.com/Tencent/tmagic-editor/commit/b02aa75ddc2b37a024a8966ddad96cf8d85317bb))
|
||||
* **editor:** 历史记录面板支持差异对比 ([59f4e0e](https://github.com/Tencent/tmagic-editor/commit/59f4e0edac47e986a83a3f9b7862cf92650b7fee))
|
||||
* **editor:** 历史记录面板支持点击跳转与回到初始状态 ([62a2ee6](https://github.com/Tencent/tmagic-editor/commit/62a2ee66931caed51f86bf170c3bce96c7e40dea))
|
||||
* **editor:** 字段对比模式逐项展示差异并补充历史记录面板文档 ([cbc4b25](https://github.com/Tencent/tmagic-editor/commit/cbc4b25072542d98f19707a11b87be0295157216))
|
||||
* **editor:** 数据源与代码块 service 支持 undo/redo ([8dae677](https://github.com/Tencent/tmagic-editor/commit/8dae67769c32dbf65413d47ac56ca46e65eaeecf))
|
||||
* **editor:** 新增 hideSidebar 配置支持隐藏左侧面板 ([a3333e2](https://github.com/Tencent/tmagic-editor/commit/a3333e2b4e0f05b2f83c9dc539466ebd31c04250))
|
||||
* **editor:** 新增历史记录列表面板 ([0446202](https://github.com/Tencent/tmagic-editor/commit/0446202ba6aaf0c99265b367343c7a4d1a8201e9))
|
||||
* form 新增 showDiff prop 支持自定义对比判断 ([f0c6642](https://github.com/Tencent/tmagic-editor/commit/f0c66427b8e011252110a11c90a109f5f58d3101))
|
||||
* **form:** 支持自定义 label slot ([285434e](https://github.com/Tencent/tmagic-editor/commit/285434ef3effd94c51d3ed10198842f6e689046a))
|
||||
|
||||
|
||||
### Performance Improvements
|
||||
|
||||
* **dep:** 依赖收集改为单次遍历批量处理多 target ([025cca3](https://github.com/Tencent/tmagic-editor/commit/025cca365c87d755abfc047786ac9a75758019f5))
|
||||
|
||||
|
||||
|
||||
# [1.8.0-beta.1](https://github.com/Tencent/tmagic-editor/compare/v1.8.0-beta.0...v1.8.0-beta.1) (2026-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **core:** app.emit 在节点配置事件时不应短路 super.emit ([2846f9e](https://github.com/Tencent/tmagic-editor/commit/2846f9eb2a8655175a024b16eaba22b522e88603))
|
||||
* **editor:** serializeConfig 只去掉对象 key 的引号,避免破坏字符串 value 内的引号 ([540a271](https://github.com/Tencent/tmagic-editor/commit/540a2716d8e8e7b947ec5aa6352736dff6ee225c))
|
||||
* **editor:** 修复 root 整体替换时图层面板节点状态残留与组件树闪烁问题 ([b9a6dd5](https://github.com/Tencent/tmagic-editor/commit/b9a6dd5b84d6f043eda94dbc1a07b75aea87e6f2))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 数据源字段选择按钮在对比模式与禁用态下禁止切换 ([ff810d0](https://github.com/Tencent/tmagic-editor/commit/ff810d09e41163834f0ac9fd2057bd9fb9d53c55))
|
||||
* **editor:** 样式设置器 StyleSetter 支持表单对比模式 ([b1193b9](https://github.com/Tencent/tmagic-editor/commit/b1193b909e5e15f78783f72eb21959a52128e973))
|
||||
* **eslint-config:** 禁止匿名 default class/function 导出 ([a1fcb19](https://github.com/Tencent/tmagic-editor/commit/a1fcb191d243b3c7034f31f753757ca4bbd83f5f))
|
||||
|
||||
|
||||
|
||||
# [1.8.0-beta.0](https://github.com/Tencent/tmagic-editor/compare/v1.7.14-beta.3...v1.8.0-beta.0) (2026-05-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **editor:** 属性面板 padding 仅作用于最外层表单 ([eb1c5a3](https://github.com/Tencent/tmagic-editor/commit/eb1c5a3ec1c5987b50c700dfb9019aad695e042a))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 新增 DSL 修改方法的 doNotSwitchPage 选项 ([3d03851](https://github.com/Tencent/tmagic-editor/commit/3d038513e3f0d1c303332fd902c1ef83d7dfe860))
|
||||
|
||||
|
||||
|
||||
## [1.7.14-beta.3](https://github.com/Tencent/tmagic-editor/compare/v1.7.14-beta.2...v1.7.14-beta.3) (2026-05-21)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **form:** select 在 model 值变化时补拉 init 选项 ([aa2ee9f](https://github.com/Tencent/tmagic-editor/commit/aa2ee9fd4b08a4a2896eead33dfd1d4ba029c501))
|
||||
* **form:** 修复table-group-list中model属性可能为undefined导致的报错 ([12ce19f](https://github.com/Tencent/tmagic-editor/commit/12ce19fb02af7ac621d220b7e6d0a98859e631de))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 新增 DSL 修改方法的 doNotSelect 选项 ([05e512b](https://github.com/Tencent/tmagic-editor/commit/05e512b1fe978e26aa3064e7deae9a1aeadcae25))
|
||||
* **form:** 容器组件新增 extendState 属性 ([2d31b38](https://github.com/Tencent/tmagic-editor/commit/2d31b3812f2195f4afc5f16774e155f00cb0ec20))
|
||||
* **form:** 新增 submitForm 命令式提交函数 ([638c3e9](https://github.com/Tencent/tmagic-editor/commit/638c3e9f3cb550da2749fd4814c3bec9d518d081))
|
||||
|
||||
|
||||
|
||||
## [1.7.14-beta.2](https://github.com/Tencent/tmagic-editor/compare/v1.7.14-beta.1...v1.7.14-beta.2) (2026-05-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **editor:** 修复 CodeEditor setValue 时滚动位置与折叠等视图状态丢失 ([f1aedc4](https://github.com/Tencent/tmagic-editor/commit/f1aedc4ce7f93dd07cb4b7b3c1d39e459b504176))
|
||||
* **form:** 修复 Select 在 value 为空时仍发起 initUrl 请求的问题 ([e64d866](https://github.com/Tencent/tmagic-editor/commit/e64d86660d83769b498de05d221b900a8c9c5b3c))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** 导航菜单支持菜单项溢出收纳,新增 NavMenuColumn 组件 ([df87900](https://github.com/Tencent/tmagic-editor/commit/df8790042fd1309a6599c2db45bae7c61e1a2600))
|
||||
|
||||
|
||||
|
||||
## [1.7.14-beta.1](https://github.com/Tencent/tmagic-editor/compare/v1.7.14-beta.0...v1.7.14-beta.1) (2026-05-14)
|
||||
|
||||
|
||||
|
||||
@ -103,9 +103,10 @@ export default defineConfig({
|
||||
link: '/guide/advanced/data-source.md'
|
||||
},
|
||||
{
|
||||
text: '@tmagic/ui',
|
||||
link: '/guide/advanced/tmagic-ui.md',
|
||||
text: '历史记录面板',
|
||||
link: '/guide/advanced/history-list.md',
|
||||
},
|
||||
|
||||
{
|
||||
text: '@tmagic/form',
|
||||
link: '/guide/advanced/tmagic-form.md',
|
||||
@ -200,7 +201,16 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
text: 'uiService',
|
||||
link: '/api/editor/uiServiceMethods.md',
|
||||
items: [
|
||||
{
|
||||
text: '方法',
|
||||
link: '/api/editor/uiServiceMethods.md',
|
||||
},
|
||||
{
|
||||
text: '事件',
|
||||
link: '/api/editor/uiServiceEvents.md',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'codeBlockService',
|
||||
@ -253,6 +263,15 @@ export default defineConfig({
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '工具函数',
|
||||
items: [
|
||||
{
|
||||
text: 'submitForm',
|
||||
link: '/api/form/submit-form'
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -551,14 +570,8 @@ export default defineConfig({
|
||||
},
|
||||
|
||||
vite: {
|
||||
optimizeDeps: {
|
||||
rolldownOptions: {
|
||||
transform: {
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
},
|
||||
},
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
resolve: {
|
||||
alias:[
|
||||
|
||||
@ -1,9 +1,20 @@
|
||||
# codeBlockService方法
|
||||
|
||||
写入历史栈的方法([setCodeDslById](#setcodedslbyid)、[setCodeDslByIdSync](#setcodedslbyidsync)、[deleteCodeDslByIds](#deletecodedslbyids) 等)的 `options` 支持
|
||||
[historyDescription / historySource](./editorServiceMethods.md#历史记录相关-options),会透传到 `historyService.pushCodeBlock` 的 `historyDescription` / `source` 字段。
|
||||
|
||||
## setCodeDsl
|
||||
|
||||
- **参数:**
|
||||
- {[CodeBlockDSL](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L75)} codeDsl 代码块DSL
|
||||
- {`CodeBlockDSL`} codeDsl 代码块DSL
|
||||
|
||||
::: details 查看 CodeBlockDSL 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockDSL{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeParam{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -15,7 +26,7 @@
|
||||
## getCodeDsl
|
||||
|
||||
- **返回:**
|
||||
- {[CodeBlockDSL](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L75) | null}
|
||||
- {`CodeBlockDSL` | null}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -27,7 +38,7 @@
|
||||
- `{string | number}` id 代码块id
|
||||
|
||||
- **返回:**
|
||||
- {[CodeBlockContent](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L79) | null}
|
||||
- {`CodeBlockContent` | null}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -39,7 +50,16 @@
|
||||
|
||||
- **参数:**
|
||||
- `{string | number}` id 代码块id
|
||||
- {Partial<[CodeBlockContent](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L79)>} codeConfig 代码块内容配置信息
|
||||
- {Partial<`CodeBlockContent`>} codeConfig 代码块内容配置信息
|
||||
- `{Object}` options 可选配置
|
||||
- {`ChangeRecord`[]} changeRecords form 端变更记录,用于历史记录的精细化撤销/重做
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
::: details 查看 ChangeRecord 类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -52,8 +72,13 @@
|
||||
|
||||
- **参数:**
|
||||
- `{string | number}` id 代码块id
|
||||
- {Partial<[CodeBlockContent](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L79)>} codeConfig 代码块内容配置信息
|
||||
- {Partial<`CodeBlockContent`>} codeConfig 代码块内容配置信息
|
||||
- `{boolean}` force 是否强制写入,默认 `true`;为 `false` 时若同 id 已存在则跳过
|
||||
- `{Object}` options 可选配置
|
||||
- {`ChangeRecord`[]} changeRecords form 端变更记录,用于历史记录的精细化撤销/重做
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -62,13 +87,20 @@
|
||||
|
||||
同步版本的 [setCodeDslById](#setcodedslbyid),并会触发 `addOrUpdate` 事件
|
||||
|
||||
::: tip
|
||||
写入成功时(`force=false` 且同 id 已存在的跳过场景除外)会自动调用 `historyService.pushCodeBlock`
|
||||
把本次变更入历史栈,参见 [historyService.pushCodeBlock](./historyServiceMethods.md#pushcodeblock)。
|
||||
传入的 `changeRecords` 会一同写进 step,撤销/重做时调用方可据此按 `propPath` 局部回放。
|
||||
传入 `doNotPushHistory: true` 可跳过写入历史栈,常用于批量导入、外部同步等非用户操作场景。
|
||||
:::
|
||||
|
||||
## getCodeDslByIds
|
||||
|
||||
- **参数:**
|
||||
- `{string[]}` ids 代码块id数组
|
||||
|
||||
- **返回:**
|
||||
- {[CodeBlockDSL](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts#L75)} 命中的代码块dsl
|
||||
- {`CodeBlockDSL`} 命中的代码块dsl
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -186,6 +218,10 @@
|
||||
|
||||
- **参数:**
|
||||
- `{(string | number)[]}` codeIds 需要删除的代码块id数组
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -194,6 +230,157 @@
|
||||
|
||||
在dsl数据源中删除指定id的代码块,每删除一个会触发一次 `remove` 事件
|
||||
|
||||
::: tip
|
||||
对每个实际存在并被删除的代码块,会自动调用 `historyService.pushCodeBlock` 入栈一条
|
||||
`newContent=null` 的删除记录;不存在的 id 不会入历史。传入 `doNotPushHistory: true` 也可显式跳过写入历史栈。
|
||||
:::
|
||||
|
||||
## setCodeDslByIdAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [setCodeDslById](#setcodedslbyid)
|
||||
|
||||
- **返回:**
|
||||
- {`Promise<string | null>`} 本次写入历史记录的 uuid;未写入历史(`doNotPushHistory: true` 等)时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [setCodeDslById](#setcodedslbyid) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`,可用于精确引用 / 定位该条历史记录。
|
||||
参见 [editorService 历史记录 uuid 与 \*AndGetHistoryId](./editorServiceMethods.md#历史记录-uuid-与-andgethistoryid)。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { codeBlockService } from "@tmagic/editor";
|
||||
|
||||
const historyId = await codeBlockService.setCodeDslByIdAndGetHistoryId("code_1234", {
|
||||
name: "代码块1",
|
||||
content: "() => {}",
|
||||
});
|
||||
console.log(historyId); // 本次变更对应的历史记录 uuid,或 null
|
||||
```
|
||||
|
||||
## setCodeDslByIdSyncAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [setCodeDslByIdSync](#setcodedslbyidsync)
|
||||
|
||||
- **返回:**
|
||||
- {`string | null`} 本次写入历史记录的 uuid;未写入历史(`doNotPushHistory: true`、或 `force=false` 跳过等)时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [setCodeDslByIdSync](#setcodedslbyidsync) 行为完全一致(同步),仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## deleteCodeDslByIdsAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [deleteCodeDslByIds](#deletecodedslbyids)
|
||||
|
||||
- **返回:**
|
||||
- {`Promise<string[]>`} 本次写入的全部历史记录 uuid(按删除顺序);未写入任何历史时返回空数组 `[]`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [deleteCodeDslByIds](#deletecodedslbyids) 行为完全一致。由于一次可删除多个代码块、会产生多条历史记录,因此返回的是 uuid 数组(每条删除记录一个 uuid);不存在的 id 不会入历史,也不会出现在返回数组中。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { codeBlockService } from "@tmagic/editor";
|
||||
|
||||
const historyIds = await codeBlockService.deleteCodeDslByIdsAndGetHistoryId(["code_1", "code_2"]);
|
||||
console.log(historyIds); // ['xxxx', 'yyyy'],或 []
|
||||
```
|
||||
|
||||
## revertById
|
||||
|
||||
- **参数:**
|
||||
- `{string}` uuid 目标历史记录的 uuid(通常由 [setCodeDslByIdAndGetHistoryId](#setcodedslbyidandgethistoryid) 等方法返回)
|
||||
|
||||
- **返回:**
|
||||
- {`Promise<CodeBlockStepValue | null>`} 反向应用后产生的新 step;找不到对应 uuid / 该步未应用时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
通过历史记录 uuid「回滚」某条代码块历史步骤(类 git revert 语义),语义同按 `(id, index)` 回滚,
|
||||
仅无需调用方再传 `codeBlockId` 与 `index`:内部会按 uuid 在全部代码块栈中定位对应步骤后再回滚。
|
||||
参见 [editorService 历史记录 uuid 与 \*AndGetHistoryId](./editorServiceMethods.md#历史记录-uuid-与-andgethistoryid)。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { codeBlockService } from "@tmagic/editor";
|
||||
|
||||
const historyId = await codeBlockService.setCodeDslByIdAndGetHistoryId("code_1234", { name: "代码块1" });
|
||||
if (historyId) {
|
||||
await codeBlockService.revertById(historyId);
|
||||
}
|
||||
```
|
||||
|
||||
## undo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 代码块id
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<CodeBlockStepValue | null>}` 撤销的 step;栈不存在或已无可撤销时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
撤销指定代码块的最近一次变更。内部根据 [historyService](./historyServiceMethods.md) 取出 step 后,
|
||||
复用 [setCodeDslByIdSync](#setcodedslbyidsync) / [deleteCodeDslByIds](#deletecodedslbyids) 写回,
|
||||
并自动带上 `doNotPushHistory: true`,确保不会再次入栈。
|
||||
|
||||
写回会触发对应的 `addOrUpdate` / `remove` 事件,编辑器内部据此重新维护
|
||||
`DepTargetType.CODE_BLOCK` 的 dep target,无需调用方额外处理。
|
||||
|
||||
对于带有 `changeRecords` 的更新 step,会按 `propPath` 局部 patch 当前代码块内容;缺省才退化为整内容替换,
|
||||
避免冲掉同代码块上的其它无关变更。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { codeBlockService } from "@tmagic/editor";
|
||||
|
||||
if (codeBlockService.canUndo("code_1234")) {
|
||||
await codeBlockService.undo("code_1234");
|
||||
}
|
||||
```
|
||||
|
||||
## redo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 代码块id
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<CodeBlockStepValue | null>}` 重做的 step;栈不存在或已无可重做时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
重做指定代码块的下一次变更。其它行为同 [undo](#undo)。
|
||||
|
||||
## canUndo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 代码块id
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
当前指定代码块是否可撤销,等价于 `historyService.canUndoCodeBlock(id)`。
|
||||
|
||||
## canRedo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 代码块id
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
当前指定代码块是否可重做,等价于 `historyService.canRedoCodeBlock(id)`。
|
||||
|
||||
## setParamsColConfig
|
||||
|
||||
- **参数:**
|
||||
@ -227,9 +414,25 @@
|
||||
## copyWithRelated
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 组件节点配置
|
||||
- {`MNode` | `MNode`[]} config 组件节点配置
|
||||
- `{TargetOptions}` collectorOptions 可选的依赖收集器配置
|
||||
|
||||
::: details 查看 MNode 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MIteratorContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
|
||||
@ -264,15 +467,11 @@
|
||||
|
||||
销毁 codeBlockService,重置状态并移除所有事件监听和插件
|
||||
|
||||
## use
|
||||
|
||||
使用中间件的方式扩展方法,上述方法中标记有`扩展支持: 是`的方法都支持使用use扩展
|
||||
|
||||
## usePlugin
|
||||
|
||||
- **详情:**
|
||||
|
||||
相对于[use](#use), usePlugin支持更加灵活更加细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
usePlugin支持灵活细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
|
||||
每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值
|
||||
|
||||
@ -281,3 +480,4 @@
|
||||
- **详情:**
|
||||
|
||||
删掉当前设置的所有扩展
|
||||
|
||||
|
||||
@ -4,7 +4,13 @@
|
||||
|
||||
- **参数:**
|
||||
|
||||
- {[ComponentGroup](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/editor/src/type.ts#L355)[]} componentGroupList 组件列表配置
|
||||
- {`ComponentGroup`[]} componentGroupList 组件列表配置
|
||||
|
||||
::: details 查看 ComponentGroup 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#ComponentGroup{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#ComponentItem{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
|
||||
@ -48,7 +54,7 @@ componentListService.setList([
|
||||
|
||||
- **返回:**
|
||||
|
||||
- {[ComponentGroup](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/editor/src/type.ts#L355)[]} 组件列表配置
|
||||
- {`ComponentGroup`[]} 组件列表配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -102,3 +108,4 @@ import { componentListService } from '@tmagic/editor';
|
||||
|
||||
componentListService.destroy();
|
||||
```
|
||||
|
||||
|
||||
@ -59,7 +59,19 @@ dataSourceService.set("editable", false);
|
||||
- `{string}` type 数据源类型,默认为 'base'
|
||||
|
||||
- **返回:**
|
||||
- {[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)} 表单配置
|
||||
- {`FormConfig`} 表单配置
|
||||
|
||||
::: details 查看 FormConfig 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItemConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChildConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicTypeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -80,7 +92,7 @@ console.log(config);
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 数据源类型
|
||||
- {[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)} config 表单配置
|
||||
- {`FormConfig`} config 表单配置
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -120,7 +132,23 @@ dataSourceService.setFormConfig("http", [
|
||||
- `{string}` type 数据源类型,默认为 'base'
|
||||
|
||||
- **返回:**
|
||||
- {Partial<[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)>} 数据源默认值
|
||||
- {Partial<`DataSourceSchema`>} 数据源默认值
|
||||
|
||||
::: details 查看 DataSourceSchema 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MockSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeParam{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#EventConfig{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#JsEngine{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -141,7 +169,7 @@ console.log(defaultValue);
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 数据源类型
|
||||
- {Partial<[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)>} value 数据源默认值
|
||||
- {Partial<`DataSourceSchema`>} value 数据源默认值
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -170,7 +198,11 @@ dataSourceService.setFormValue("http", {
|
||||
- `{string}` type 数据源类型,默认为 'base'
|
||||
|
||||
- **返回:**
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} 事件列表
|
||||
- {`EventOption`[]} 事件列表
|
||||
|
||||
::: details 查看 EventOption 类型定义
|
||||
<<< @/../packages/core/src/utils.ts#EventOption{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -191,7 +223,7 @@ console.log(events);
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 数据源类型
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} value 事件列表
|
||||
- {`EventOption`[]} value 事件列表
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -219,7 +251,7 @@ dataSourceService.setFormEvent("http", [
|
||||
- `{string}` type 数据源类型,默认为 'base'
|
||||
|
||||
- **返回:**
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} 方法列表
|
||||
- {`EventOption`[]} 方法列表
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -240,7 +272,7 @@ console.log(methods);
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 数据源类型
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} value 方法列表
|
||||
- {`EventOption`[]} value 方法列表
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -265,15 +297,25 @@ dataSourceService.setFormMethod("http", [
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)} config 数据源配置
|
||||
- {`DataSourceSchema`} config 数据源配置
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- {[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)} 添加后的数据源配置
|
||||
- {`DataSourceSchema`} 添加后的数据源配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
添加一个数据源,如果配置中没有id或id已存在,会自动生成新的id
|
||||
|
||||
::: tip
|
||||
添加成功会自动调用 `historyService.pushDataSource` 入栈一条 `oldSchema=null` 的新增记录,
|
||||
参见 [historyService.pushDataSource](./historyServiceMethods.md#pushdatasource)。
|
||||
传入 `doNotPushHistory: true` 可跳过写入历史栈,常用于批量导入、外部同步等非用户操作场景。
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
@ -294,17 +336,30 @@ console.log(newDs.id); // 自动生成的id
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)} config 数据源配置
|
||||
- {`DataSourceSchema`} config 数据源配置
|
||||
- `{Object}` options 可选配置
|
||||
- {[ChangeRecord](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/form/src/schema.ts#L27-L39)[]} changeRecords 变更记录
|
||||
- {`ChangeRecord`[]} changeRecords 变更记录
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
::: details 查看 ChangeRecord 类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)} 更新后的数据源配置
|
||||
- {`DataSourceSchema`} 更新后的数据源配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
更新数据源
|
||||
|
||||
::: tip
|
||||
更新成功会自动调用 `historyService.pushDataSource` 入栈一条 `oldSchema` / `newSchema`
|
||||
均为对应 schema 的更新记录,传入的 `changeRecords` 也会一并写进 step;撤销/重做时调用方可据此按
|
||||
`propPath` 局部回放,缺省才退化为整 schema 替换。传入 `doNotPushHistory: true` 可跳过写入历史栈。
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
@ -326,6 +381,10 @@ console.log(updatedDs);
|
||||
|
||||
- **参数:**
|
||||
- `{string}` id 数据源id
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见 [editorService 历史记录相关 options](./editorServiceMethods.md#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -334,6 +393,11 @@ console.log(updatedDs);
|
||||
|
||||
删除指定id的数据源
|
||||
|
||||
::: tip
|
||||
对实际存在的数据源会自动调用 `historyService.pushDataSource` 入栈一条 `newSchema=null`
|
||||
的删除记录;不存在的 id 不会入历史。传入 `doNotPushHistory: true` 也可显式跳过写入历史栈。
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
@ -342,6 +406,78 @@ import { dataSourceService } from "@tmagic/editor";
|
||||
dataSourceService.remove("ds_123");
|
||||
```
|
||||
|
||||
## addAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [add](#add)
|
||||
|
||||
- **返回:**
|
||||
- {`string` | null} 本次写入历史记录的 uuid;未写入历史(`doNotPushHistory: true` 等)时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [add](#add) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`,可用于精确引用 / 定位该条历史记录。
|
||||
参见 [editorService 历史记录 uuid 与 \*AndGetHistoryId](./editorServiceMethods.md#历史记录-uuid-与-andgethistoryid)。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { dataSourceService } from "@tmagic/editor";
|
||||
|
||||
const historyId = dataSourceService.addAndGetHistoryId({
|
||||
type: "http",
|
||||
title: "用户信息",
|
||||
url: "/api/user",
|
||||
});
|
||||
console.log(historyId); // 本次新增对应的历史记录 uuid,或 null
|
||||
```
|
||||
|
||||
## updateAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [update](#update)
|
||||
|
||||
- **返回:**
|
||||
- {`string` | null} 本次写入历史记录的 uuid;未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [update](#update) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## removeAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [remove](#remove)
|
||||
|
||||
- **返回:**
|
||||
- {`string` | null} 本次写入历史记录的 uuid;删除的 id 不存在或未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [remove](#remove) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## revertById
|
||||
|
||||
- **参数:**
|
||||
- `{string}` uuid 目标历史记录的 uuid(通常由 [addAndGetHistoryId](#addandgethistoryid) 等方法返回)
|
||||
|
||||
- **返回:**
|
||||
- {`DataSourceStepValue` | null} 反向应用后产生的新 step;找不到对应 uuid / 该步未应用时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
通过历史记录 uuid「回滚」某条数据源历史步骤(类 git revert 语义),语义同按 `(id, index)` 回滚,
|
||||
仅无需调用方再传 `dataSourceId` 与 `index`:内部会按 uuid 在全部数据源栈中定位对应步骤后再回滚。
|
||||
参见 [editorService 历史记录 uuid 与 \*AndGetHistoryId](./editorServiceMethods.md#历史记录-uuid-与-andgethistoryid)。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { dataSourceService } from "@tmagic/editor";
|
||||
|
||||
const historyId = dataSourceService.addAndGetHistoryId({ type: "http", title: "用户信息" });
|
||||
if (historyId) {
|
||||
dataSourceService.revertById(historyId);
|
||||
}
|
||||
```
|
||||
|
||||
## createId
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
@ -370,7 +506,7 @@ console.log(id); // 'ds_xxx-xxx-xxx'
|
||||
- `{string}` id 数据源id
|
||||
|
||||
- **返回:**
|
||||
- {[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221) | undefined} 数据源配置
|
||||
- {`DataSourceSchema` | undefined} 数据源配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -385,12 +521,94 @@ const ds = dataSourceService.getDataSourceById("ds_123");
|
||||
console.log(ds);
|
||||
```
|
||||
|
||||
## undo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 数据源id
|
||||
|
||||
- **返回:**
|
||||
- {`DataSourceStepValue` | null} 撤销的 step;栈不存在或已无可撤销时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
撤销指定数据源的最近一次变更。内部根据 [historyService](./historyServiceMethods.md) 取出 step 后,
|
||||
复用 [add](#add) / [update](#update) / [remove](#remove) 写回,并自动带上 `doNotPushHistory: true`,
|
||||
确保不会再次入栈。
|
||||
|
||||
写回会触发对应的 `add` / `update` / `remove` 事件,编辑器内部据此重新维护数据源相关的依赖收集
|
||||
(`DepTargetType.DATA_SOURCE` / `DATA_SOURCE_COND` / `DATA_SOURCE_METHOD`),无需调用方额外处理。
|
||||
|
||||
对于带有 `changeRecords` 的更新 step,会按 `propPath` 局部 patch 当前数据源;缺省才退化为整 schema 替换,
|
||||
避免冲掉同节点上的其它无关变更。
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { dataSourceService } from "@tmagic/editor";
|
||||
|
||||
if (dataSourceService.canUndo("ds_123")) {
|
||||
dataSourceService.undo("ds_123");
|
||||
}
|
||||
```
|
||||
|
||||
## redo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 数据源id
|
||||
|
||||
- **返回:**
|
||||
- {`DataSourceStepValue` | null} 重做的 step;栈不存在或已无可重做时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
重做指定数据源的下一次变更。其它行为同 [undo](#undo)。
|
||||
|
||||
## canUndo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 数据源id
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
当前指定数据源是否可撤销,等价于 `historyService.canUndoDataSource(id)`。
|
||||
|
||||
## canRedo
|
||||
|
||||
- **参数:**
|
||||
- `{Id}` id 数据源id
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
当前指定数据源是否可重做,等价于 `historyService.canRedoDataSource(id)`。
|
||||
|
||||
## copyWithRelated
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 组件节点配置
|
||||
- {`MNode` | `MNode`[]} config 组件节点配置
|
||||
- `{TargetOptions}` collectorOptions 可选的收集器配置
|
||||
|
||||
::: details 查看 MNode 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MIteratorContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
|
||||
@ -505,3 +723,4 @@ import { dataSourceService } from "@tmagic/editor";
|
||||
|
||||
dataSourceService.removeAllPlugins();
|
||||
```
|
||||
|
||||
|
||||
@ -4,37 +4,71 @@
|
||||
|
||||
- **详情:** dsl跟节点发生变化,[editorService.set('root', {})](./editorServiceMethods.md#set)后触发
|
||||
|
||||
- **事件回调函数:** (value: [MApp](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts?plain=1#L66-L73), preValue?: [MApp](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts?plain=1#L66-L73)) => void
|
||||
- **事件回调函数:** `(value: MApp, preValue?: MApp) => void`
|
||||
|
||||
::: details 查看 MApp 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#NodeType{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockDSL{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceDeps{ts}
|
||||
:::
|
||||
|
||||
## select
|
||||
|
||||
- **详情:** 选中组件,[editorService.select()](./editorServiceMethods.md#select)后触发
|
||||
|
||||
- **事件回调函数:** (node: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)) => void
|
||||
- **事件回调函数:** `(node: MNode) => void`
|
||||
|
||||
::: details 查看 MNode 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
## add
|
||||
|
||||
- **详情:** 添加节点后触发,[editorService.add()](./editorServiceMethods.md#add)后触发
|
||||
|
||||
- **事件回调函数:** (node: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]) => void
|
||||
- **事件回调函数:** `(node: MNode[]) => void`
|
||||
|
||||
## remove
|
||||
|
||||
- **详情:** 删除节点后触发,[editorService.remove()](./editorServiceMethods.md#remove)后触发
|
||||
|
||||
- **事件回调函数:** (node: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]) => void
|
||||
- **事件回调函数:** `(node: MNode[]) => void`
|
||||
|
||||
## update
|
||||
|
||||
- **详情:** 更新组件后触发,[editorService.update()](./editorServiceMethods.md#update)后触发
|
||||
|
||||
- **事件回调函数:** (data: Array<{ newNode: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210); oldNode: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210); changeRecords?: [ChangeRecord](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/form/src/schema.ts#L27-L39)[] }>) => void
|
||||
- **事件回调函数:** `(data: Array<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }>) => void`
|
||||
|
||||
::: details 查看 ChangeRecord 类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
## move-layer
|
||||
|
||||
- **详情:** 移动节点层级后触发,[editorService.moveLayer()](./editorServiceMethods.md#movelayer)后触发
|
||||
|
||||
- **事件回调函数:** (offset: number | [LayerOffset](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts)) => void
|
||||
- **事件回调函数:** `(offset: number | LayerOffset) => void`
|
||||
|
||||
其中 `LayerOffset` 枚举值为 `'top'` / `'bottom'`
|
||||
|
||||
@ -42,10 +76,14 @@
|
||||
|
||||
- **详情:** 拖拽节点到指定容器后触发,[editorService.dragTo()](./editorServiceMethods.md#dragto)后触发
|
||||
|
||||
- **事件回调函数:** (data: { targetIndex: number; configs: [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]; targetParent: [MContainer](https://github.com/Tencent/tmagic-editor/blob/c143a5f7670ae61d80c1a2cfcc780cfb5259849d/packages/schema/src/index.ts#L54-L59) }) => void
|
||||
- **事件回调函数:** `(data: { targetIndex: number; configs: MNode | MNode[]; targetParent: MContainer }) => void`
|
||||
|
||||
::: details 查看 MContainer 类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
:::
|
||||
|
||||
## history-change
|
||||
|
||||
- **详情:** 历史记录改变,[editorService.redo(),editorService.undo()](./editorServiceMethods.md#undo)后触发
|
||||
|
||||
- **事件回调函数:** (data: [MPage](https://github.com/Tencent/tmagic-editor/blob/c143a5f7670ae61d80c1a2cfcc780cfb5259849d/packages/schema/src/index.ts#L61) | [MPageFragment](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)) => void
|
||||
- **事件回调函数:** `(data: MPage | MPageFragment) => void`
|
||||
|
||||
@ -1,5 +1,48 @@
|
||||
# editorService方法
|
||||
|
||||
## 历史记录相关 options
|
||||
|
||||
下列 DSL 操作方法([add](#add)、[remove](#remove)、[update](#update) 等)的 `options` / `data` 参数,以及
|
||||
[codeBlockService](./codeBlockServiceMethods.md) / [dataSourceService](./dataSourceServiceMethods.md)
|
||||
的 `options`,在 `doNotPushHistory` 之外还可传入:
|
||||
|
||||
- `{string}` **historyDescription**:入栈时附带的人类可读描述,用于历史面板展示;不影响 undo/redo 行为,缺省时面板会自动生成描述
|
||||
- `{HistoryOpSource}` **historySource**:操作途径,用于历史面板展示与埋点;不影响 undo/redo 行为,缺省时面板视为「未知」
|
||||
|
||||
编辑器内置交互(画布、树面板、配置面板、右键菜单、快捷键等)会自动传入对应的 `historySource`;
|
||||
业务侧程序化调用时建议显式传入(如 `api`),便于历史面板区分来源。
|
||||
|
||||
## 历史记录 uuid 与 \*AndGetHistoryId
|
||||
|
||||
每条历史记录入栈时都会自动生成一个唯一标识 `uuid`(见 [StepValue](#undo)),可用于精确引用 / 定位某一条历史记录(如埋点、回滚、跨端同步等)。
|
||||
|
||||
DSL 操作方法(`add` / `remove` / `update` 等)默认返回操作结果(节点 / 节点集合 / void),不会返回 `uuid`。若需要拿到本次写入历史记录的 `uuid`,可改用对应的 `*AndGetHistoryId` 方法:它们与原方法行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`(`string`)。当本次操作未写入历史(`doNotPushHistory: true`、无实际变更或提前返回)时返回 `null`。
|
||||
|
||||
| 原方法 | 取 uuid 的方法 | 返回值 |
|
||||
| --- | --- | --- |
|
||||
| [add](#add) | [addAndGetHistoryId](#addandgethistoryid) | `Promise<string \| null>` |
|
||||
| [remove](#remove) | [removeAndGetHistoryId](#removeandgethistoryid) | `Promise<string \| null>` |
|
||||
| [update](#update) | [updateAndGetHistoryId](#updateandgethistoryid) | `Promise<string \| null>` |
|
||||
| [moveLayer](#movelayer) | [moveLayerAndGetHistoryId](#movelayerandgethistoryid) | `Promise<string \| null>` |
|
||||
| [moveToContainer](#movetocontainer) | [moveToContainerAndGetHistoryId](#movetocontainerandgethistoryid) | `Promise<string \| null>` |
|
||||
| [dragTo](#dragto) | [dragToAndGetHistoryId](#dragtoandgethistoryid) | `Promise<string \| null>` |
|
||||
|
||||
[dataSourceService](./dataSourceServiceMethods.md) / [codeBlockService](./codeBlockServiceMethods.md) 也提供了同名约定的 `*AndGetHistoryId` 方法。
|
||||
|
||||
拿到 `uuid` 后,可在需要时按 uuid「回滚」对应的历史记录(类 git revert 语义,详见[历史记录面板](../../guide/advanced/history-list.md))。相比按 index 回滚,uuid 不会随栈内步骤增删而变化,更适合业务侧持有引用后再回滚:
|
||||
|
||||
- 页面:[editorService.revertPageStepById(uuid)](#revertpagestepbyid)
|
||||
- 数据源:[dataSourceService.revertById(uuid)](./dataSourceServiceMethods.md#revertbyid)
|
||||
- 代码块:[codeBlockService.revertById(uuid)](./codeBlockServiceMethods.md#revertbyid)
|
||||
|
||||
::: details 查看 HistoryOpOptions / DslOpOptions / HistoryOpSource 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpOptions{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#DslOpOptions{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
:::
|
||||
|
||||
## get
|
||||
|
||||
- **参数:**
|
||||
@ -78,7 +121,19 @@ editorService.set("node", {
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {[EditorNodeInfo](https://github.com/Tencent/tmagic-editor/blob/c143a5f7670ae61d80c1a2cfcc780cfb5259849d/packages/editor/src/type.ts#L139-L143)}
|
||||
- {`EditorNodeInfo`}
|
||||
|
||||
::: details 查看 EditorNodeInfo 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#EditorNodeInfo{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -103,7 +158,23 @@ console.log(info.page);
|
||||
- `{boolean}` raw 是否使用toRaw,默认为true
|
||||
|
||||
- **返回:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} 组件节点配置
|
||||
- {`MNode`} 组件节点配置
|
||||
|
||||
::: details 查看 MNode 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MIteratorContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -126,7 +197,7 @@ console.log(node);
|
||||
- `{boolean}` raw 是否使用toRaw,默认为true
|
||||
|
||||
- **返回:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} 指点组件的父节点配置
|
||||
- {`MNode`} 指点组件的父节点配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -142,16 +213,43 @@ const parent = editorService.getParentById("text_123");
|
||||
console.log(parent);
|
||||
```
|
||||
|
||||
## isOnDifferentPage
|
||||
|
||||
- **参数:**
|
||||
- {`MNode`} node 节点配置
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}` true 表示该节点位于非当前页面(即选中该节点将会引起当前页面切换)
|
||||
|
||||
- **详情:**
|
||||
|
||||
判断给定节点是否位于非当前页面,通常用于配合 `doNotSwitchPage` 选项判断 DSL 操作是否会引起页面切换
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { editorService } from "@tmagic/editor";
|
||||
|
||||
const otherPageNode = editorService.getNodeById("text_456");
|
||||
if (editorService.isOnDifferentPage(otherPageNode)) {
|
||||
console.log("该节点在其它页面,操作会触发页面切换");
|
||||
}
|
||||
```
|
||||
|
||||
## getLayout
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} parent
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} node 可选
|
||||
- {`MNode`} parent
|
||||
- {`MNode`} node 可选
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[Layout](https://github.com/Tencent/tmagic-editor/blob/c143a5f7670ae61d80c1a2cfcc780cfb5259849d/packages/editor/src/type.ts#L297-L302)>} 当前布局模式
|
||||
- {Promise<`Layout`>} 当前布局模式
|
||||
|
||||
::: details 查看 Layout 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#Layout{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -179,10 +277,10 @@ editorService.getLayout(parent).then((layout) => {
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {number | string | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config 需要选中的节点或节点ID
|
||||
- {number | string | `MNode`} config 需要选中的节点或节点ID
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>} 当前选中的节点配置
|
||||
- {Promise<`MNode`>} 当前选中的节点配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -229,7 +327,7 @@ editorService.get("stage")?.multiSelect(["text_123", "button_123"]);
|
||||
## selectNextNode
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | null>} 选中后的节点配置
|
||||
- {Promise<`MNode` | null>} 选中后的节点配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -238,7 +336,7 @@ editorService.get("stage")?.multiSelect(["text_123", "button_123"]);
|
||||
## selectNextPage
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>} 选中后的页面配置
|
||||
- {Promise<`MNode`>} 选中后的页面配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -258,7 +356,7 @@ editorService.get("stage")?.multiSelect(["text_123", "button_123"]);
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {number | string | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config 需要高亮的节点或节点ID
|
||||
- {number | string | `MNode`} config 需要高亮的节点或节点ID
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -280,12 +378,12 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} node 新组件节点
|
||||
- {`MNode`} node 新组件节点
|
||||
|
||||
- {[MContainer](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L139)} parent 指定的容器节点
|
||||
- {`MContainer`} parent 指定的容器节点
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>} 新增的组件
|
||||
- {Promise<`MNode`>} 新增的组件
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -296,12 +394,19 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} node 新组件节点配置或多个节点集合
|
||||
- {`MNode` | `MNode`[]} node 新组件节点配置或多个节点集合
|
||||
|
||||
- {[MContainer](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L139)} parent 指定的容器组件节点配置,如果不设置,默认为当前选中的组件的父节点
|
||||
- {`MContainer`} parent 指定的容器组件节点配置,如果不设置,默认为当前选中的组件的父节点
|
||||
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 添加后是否不更新当前选中节点(默认 false,添加后会选中新增的节点)
|
||||
- `{boolean}` doNotSwitchPage 添加后是否不切换当前页面(默认 false;新增页面 / 跨页新增时为 true 会跳过会引发页面切换的选中操作)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]>} 新增的组件或组件集合
|
||||
- {Promise<`MNode` | `MNode`[]>} 新增的组件或组件集合
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -319,7 +424,10 @@ editorService.highlight("text_123");
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} node 要删除的节点
|
||||
- {`MNode`} node 要删除的节点
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 删除后是否不更新当前选中节点(默认 false)
|
||||
- `{boolean}` doNotSwitchPage 删除后是否不切换当前页面(默认 false;删除页面 / 页面片段时为 true 会跳过自动切换到首个剩余页面)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -328,12 +436,22 @@ editorService.highlight("text_123");
|
||||
|
||||
删除指定的组件或者页面
|
||||
|
||||
:::tip
|
||||
无论是否传入 `doNotSelect` / `doNotSwitchPage`,当被删除节点在当前选中列表中时,state 都会自动移除该节点的引用;当被删除的正好是当前页面时,state.page 也会同步清空,避免持有已删除节点
|
||||
:::
|
||||
|
||||
## remove
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[])} node 要删除的节点或节点集合
|
||||
- {`MNode` | `MNode`[])} node 要删除的节点或节点集合
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 删除后是否不更新当前选中节点(默认 false,删除后会选中父节点或首个页面)
|
||||
- `{boolean}` doNotSwitchPage 删除后是否不切换当前页面(默认 false;删除页面 / 页面片段时为 true 会跳过自动切换到首个剩余页面)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -355,20 +473,27 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config 新的节点
|
||||
- {`MNode`} config 新的节点
|
||||
- `{Object}` data 可选配置
|
||||
- {[ChangeRecord](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form/src/schema.ts#L8)[]} changeRecords 变更记录
|
||||
- `{boolean}` selectedAfterUpdate 更新后是否将新节点同步到当前选中节点列表
|
||||
- {`ChangeRecord`[]} changeRecords 变更记录
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }>}` 更新前后的节点信息
|
||||
|
||||
::: details 查看 ChangeRecord 类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
更新节点
|
||||
|
||||
:::tip
|
||||
节点中应该要有id,不然不知道要更新哪个节点
|
||||
|
||||
当被更新节点正好在当前选中列表中时,state 会自动同步到新的节点引用,无需调用方处理
|
||||
|
||||
当被更新节点正好是当前页面时,state.page 也会同步到新的节点引用;更新非当前页面(不同 ID)时不会把编辑器切到该页
|
||||
:::
|
||||
|
||||
## update
|
||||
@ -376,13 +501,20 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 新的节点或节点集合
|
||||
- {`MNode` | `MNode`[]} config 新的节点或节点集合
|
||||
- `{Object}` data 可选配置
|
||||
- {[ChangeRecord](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/form/src/schema.ts#L27-L39)[]} changeRecords 变更记录
|
||||
- `{boolean}` selectedAfterUpdate 更新后是否同步到当前选中节点列表
|
||||
- {`ChangeRecord`[]} changeRecords 单节点 form 端变更记录(多节点场景下被忽略,使用 `changeRecordList`)
|
||||
- {`ChangeRecord`[][]} changeRecordList 多节点 form 端变更记录列表,按 `config` 数组同序对应每个节点;优先级高于 `changeRecords`
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
::: details 查看 ChangeRecord 类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]>} 新的节点或节点集合
|
||||
- {Promise<`MNode` | `MNode`[]>} 新的节点或节点集合
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -396,6 +528,16 @@ editorService.highlight("text_123");
|
||||
编辑器内部更新组件都是调用update来实现的,update除了更新操作外,还会记录历史堆,还会更新[代码块](../../guide/advanced/code-block.md)关系链。
|
||||
:::
|
||||
|
||||
:::tip
|
||||
**多节点场景必须使用 `changeRecordList`**:每个节点应保留自己独立的 records,不能把多个节点的
|
||||
records 合并到同一个 `changeRecords` 数组里,否则 `doUpdate` / 依赖收集 / 历史回放都会按错误的
|
||||
`propPath` 处理。
|
||||
|
||||
写入历史时,每个节点的 records 会单独保存到 `updatedItems[i].changeRecords`;撤销/重做时若有
|
||||
records,则仅按 `propPath` 局部更新对应字段,避免整节点替换冲掉同节点上的其它无关变更;缺省
|
||||
才退化为整节点替换(如内部 `sort` / `moveLayer` / 拖动等纯快照场景)。
|
||||
:::
|
||||
|
||||
## sort
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
@ -403,6 +545,11 @@ editorService.highlight("text_123");
|
||||
- **参数:**
|
||||
- `{ string | number }` id1
|
||||
- `{ string | number }` id2
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 排序后是否不更新当前选中节点(默认 false)
|
||||
- `{boolean}` doNotSwitchPage 排序后是否不切换当前页面(排序只发生在同一父节点内,方法内为空操作;保留以与其它 DSL 操作 API 一致)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -418,7 +565,7 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 需要复制的节点或节点集合
|
||||
- {`MNode` | `MNode`[]} config 需要复制的节点或节点集合
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -432,7 +579,7 @@ editorService.highlight("text_123");
|
||||
## copyWithRelated
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 需要复制的节点或节点集合
|
||||
- {`MNode` | `MNode`[]} config 需要复制的节点或节点集合
|
||||
- `{TargetOptions}` collectorOptions 可选的依赖收集器配置
|
||||
|
||||
- **返回:**
|
||||
@ -460,10 +607,22 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[PastePosition](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L152-L163)} position 粘贴的坐标
|
||||
- {`PastePosition`} position 粘贴的坐标
|
||||
|
||||
::: details 查看 PastePosition 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#PastePosition{ts}
|
||||
:::
|
||||
|
||||
- `{TargetOptions}` collectorOptions 可选的依赖收集器配置
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 粘贴后是否不更新当前选中节点(默认 false)
|
||||
- `{boolean}` doNotSwitchPage 粘贴后是否不切换当前页面(默认 false;跨页粘贴时为 true 会跳过页面切换)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]>} 添加后的组件节点配置
|
||||
- {Promise<`MNode` | `MNode`[]>} 添加后的组件节点配置
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -476,10 +635,10 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config 需要居中的组件
|
||||
- {`MNode`} config 需要居中的组件
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>}
|
||||
- {Promise<`MNode`>}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -494,10 +653,16 @@ editorService.highlight("text_123");
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 需要居中的组件或者组件集合
|
||||
- {`MNode` | `MNode`[]} config 需要居中的组件或者组件集合
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 居中后是否不更新当前选中节点(默认 false)
|
||||
- `{boolean}` doNotSwitchPage 居中后是否不切换当前页面(居中只更新节点 style,方法内为空操作;保留以与其它 DSL 操作 API 一致)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]>}
|
||||
- {Promise<`MNode` | `MNode`[]>}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -515,6 +680,10 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
|
||||
- **参数:**
|
||||
- `{number | 'top' | 'bottom'}` offset
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -530,11 +699,17 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config 需要移动的节点
|
||||
- {`MNode`} config 需要移动的节点
|
||||
- `{string | number}` targetId 容器ID
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotSelect 移动后是否不更新当前选中节点(默认 false)
|
||||
- `{boolean}` doNotSwitchPage 移动后是否不切换当前页面(默认 false;目标容器位于其它页面时为 true 会跳过自动选中以避免页面切换)
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | undefined>
|
||||
- Promise<`MNode` | undefined>
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -543,9 +718,13 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
## dragTo
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} config 需要拖拽的节点或节点集合
|
||||
- {[MContainer](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L139)} targetParent 目标父容器
|
||||
- {`MNode` | `MNode`[]} config 需要拖拽的节点或节点集合
|
||||
- {`MContainer`} targetParent 目标父容器
|
||||
- `{number}` targetIndex 目标位置索引
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -554,12 +733,131 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
|
||||
将节点(支持多选)拖拽到目标容器的指定位置,会自动处理跨容器布局切换并记录历史
|
||||
|
||||
## addAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [add](#add)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [add](#add) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`,见[历史记录 uuid 与 \*AndGetHistoryId](#历史记录-uuid-与-andgethistoryid)
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { editorService } from "@tmagic/editor";
|
||||
|
||||
const historyId = await editorService.addAndGetHistoryId(
|
||||
{ type: "text", text: "hello" },
|
||||
parent,
|
||||
{ historySource: "api" },
|
||||
);
|
||||
console.log(historyId); // 本次新增对应的历史记录 uuid,或 null
|
||||
```
|
||||
|
||||
## removeAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [remove](#remove)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [remove](#remove) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## updateAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [update](#update)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [update](#update) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## moveLayerAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [moveLayer](#movelayer)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [moveLayer](#movelayer) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## moveToContainerAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [moveToContainer](#movetocontainer)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [moveToContainer](#movetocontainer) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## dragToAndGetHistoryId
|
||||
|
||||
- **参数:** 同 [dragTo](#dragto)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`string` | null>} 本次写入历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid);未写入历史时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
与 [dragTo](#dragto) 行为完全一致,仅把返回值换成本次写入历史记录的 `uuid`
|
||||
|
||||
## revertPageStepById
|
||||
|
||||
- **参数:**
|
||||
- `{string}` uuid 目标历史记录的 [uuid](#历史记录-uuid-与-andgethistoryid)(通常由 `*AndGetHistoryId` 方法返回)
|
||||
|
||||
- **返回:**
|
||||
- {Promise<`StepValue` | null>} 反向应用后产生的新 step;找不到对应 uuid / 该步未应用 / 反向失败时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
通过历史记录 uuid「回滚」当前页面的某条历史步骤(类 git revert 语义):不移动游标、不丢弃任何步骤,而是把目标 step 的修改**反向应用为一条全新的步骤**压入栈顶。语义与按 index 回滚一致,仅入参从 index 改为 uuid,更适合业务侧持有引用后再回滚。
|
||||
|
||||
::: tip
|
||||
`opType: 'update'` 的步骤必须携带 `changeRecords` 才支持回滚(否则只能整节点替换,会冲掉后续无关变更);未应用(已被撤销)的步骤无法回滚。
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { editorService } from "@tmagic/editor";
|
||||
|
||||
// 执行操作时拿到本次历史记录 uuid
|
||||
const historyId = await editorService.addAndGetHistoryId({ type: "text", text: "hello" });
|
||||
|
||||
// 之后任意时机按 uuid 回滚该步骤
|
||||
if (historyId) {
|
||||
await editorService.revertPageStepById(historyId);
|
||||
}
|
||||
```
|
||||
|
||||
## undo
|
||||
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[StepValue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L400-L404) | null>}
|
||||
- {Promise<`StepValue` | null>}
|
||||
|
||||
::: details 查看 StepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#StepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpType{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -570,7 +868,17 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[StepValue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L400-L404) | null>}
|
||||
- {Promise<`StepValue` | null>}
|
||||
|
||||
::: details 查看 StepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#StepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpType{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -583,6 +891,10 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
- **参数:**
|
||||
- `{number}` left
|
||||
- `{number}` top
|
||||
- `{Object}` options 可选配置
|
||||
- `{boolean}` doNotPushHistory 是否不写入历史记录(默认 false)
|
||||
- `{string}` historyDescription 见[历史记录相关 options](#历史记录相关-options)
|
||||
- `{HistoryOpSource}` historySource 见[历史记录相关 options](#历史记录相关-options)
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -611,45 +923,11 @@ alignCenter可以支持一次水平居中多个组件,alignCenter是通过调
|
||||
|
||||
移除所有事件监听,清空state,移除所有插件
|
||||
|
||||
## use
|
||||
|
||||
使用中间件的方式扩展方法,上述方法中标记有`扩展支持: 是`的方法都支持使用use扩展
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { editorService, getAddParent } from "@tmagic/editor";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
|
||||
editorService.use({
|
||||
// 添加是否删除节点确认提示
|
||||
async remove(node, next) {
|
||||
await ElMessageBox.confirm("是否删除", "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
});
|
||||
|
||||
next();
|
||||
},
|
||||
|
||||
add(node, next) {
|
||||
// text组件只能添加到container中
|
||||
const parentNode = getAddParent(node);
|
||||
if (node.type === "text" && parentNode?.type !== "container") {
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## usePlugin
|
||||
|
||||
- **详情:**
|
||||
|
||||
相对于[use](#use), usePlugin支持更加灵活更加细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
usePlugin支持灵活细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
|
||||
每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值
|
||||
|
||||
@ -673,3 +951,4 @@ editorService.usePlugin({
|
||||
- **详情:**
|
||||
|
||||
删掉当前设置的所有扩展
|
||||
|
||||
|
||||
@ -4,7 +4,9 @@
|
||||
|
||||
- **详情:** 编辑器右侧组件属性配置加载完毕后触发
|
||||
|
||||
- **事件回调函数:** (instance: InstanceType<typeof [FormPanel](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/props-panel/FormPanel.vue)>) => void
|
||||
- **事件回调函数:** `(instance: InstanceType<typeof FormPanel>) => void`
|
||||
|
||||
> [`FormPanel.vue`](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/props-panel/FormPanel.vue) 是属性面板组件实例
|
||||
|
||||
## props-panel-unmounted
|
||||
|
||||
@ -16,7 +18,25 @@
|
||||
|
||||
- **详情:** 当 [modelValue](./props.md#modelvalue-v-model)(DSL) 变化时触发,配合 `v-model` 使用
|
||||
|
||||
- **事件回调函数:** (value: [MApp](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts?plain=1#L66-L73) | null) => void
|
||||
- **事件回调函数:** `(value: MApp | null) => void`
|
||||
|
||||
::: details 查看 MApp 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#NodeType{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockDSL{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceDeps{ts}
|
||||
:::
|
||||
|
||||
## props-form-error
|
||||
|
||||
@ -38,7 +58,13 @@
|
||||
|
||||
默认行为(切换可展开节点的展开/收起状态)会先于该事件执行;可通过 [`beforeLayerNodeDblclick`](./props.md#beforelayernodedblclick) 钩子拦截,返回 `false` 时该事件不会被触发
|
||||
|
||||
- **事件回调函数:** (event: MouseEvent, data: [TreeNodeData](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/type.ts)) => void
|
||||
- **事件回调函数:** `(event: MouseEvent, data: TreeNodeData) => void`
|
||||
|
||||
::: details 查看 TreeNodeData 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#TreeNodeData{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
|
||||
@ -4,7 +4,11 @@
|
||||
|
||||
- **参数:**
|
||||
|
||||
- {Record<string, [EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]>} events 事件配置对象
|
||||
- {Record<string, `EventOption`[]>} events 事件配置对象
|
||||
|
||||
::: details 查看 EventOption 类型定义
|
||||
<<< @/../packages/core/src/utils.ts#EventOption{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
|
||||
@ -35,7 +39,7 @@ eventsService.setEvents({
|
||||
- **参数:**
|
||||
|
||||
- `{string}` type 组件类型
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} events 事件列表
|
||||
- {`EventOption`[]} events 事件列表
|
||||
|
||||
- **返回:**
|
||||
|
||||
@ -64,7 +68,7 @@ eventsService.setEvent('button', [
|
||||
|
||||
- **返回:**
|
||||
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} 事件列表
|
||||
- {`EventOption`[]} 事件列表
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -83,7 +87,7 @@ console.log(events); // [{ label: '点击', value: 'click' }, ...]
|
||||
|
||||
- **参数:**
|
||||
|
||||
- {Record<string, [EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]>} methods 方法配置对象
|
||||
- {Record<string, `EventOption`[]>} methods 方法配置对象
|
||||
|
||||
- **返回:**
|
||||
|
||||
@ -115,7 +119,7 @@ eventsService.setMethods({
|
||||
- **参数:**
|
||||
|
||||
- `{string}` type 组件类型
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} methods 方法列表
|
||||
- {`EventOption`[]} methods 方法列表
|
||||
|
||||
- **返回:**
|
||||
|
||||
@ -146,7 +150,7 @@ eventsService.setMethod('video', [
|
||||
|
||||
- **返回:**
|
||||
|
||||
- {[EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]} 方法列表
|
||||
- {`EventOption`[]} 方法列表
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -200,3 +204,4 @@ import { eventsService } from '@tmagic/editor';
|
||||
|
||||
eventsService.destroy();
|
||||
```
|
||||
|
||||
|
||||
@ -4,14 +4,105 @@
|
||||
|
||||
- **详情:** 页面切换
|
||||
|
||||
- **事件回调函数:** (undoRedo: [UndoRedo](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/utils/undo-redo.ts)) => void
|
||||
- **事件回调函数:** `(undoRedo: UndoRedo) => void`
|
||||
|
||||
::: details 查看 UndoRedo 类定义
|
||||
<<< @/../packages/editor/src/utils/undo-redo.ts#UndoRedo{ts}
|
||||
:::
|
||||
|
||||
## change
|
||||
|
||||
- **详情:** 历史记录发生变化
|
||||
|
||||
- **事件回调函数:** (state: [StepValue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L400-L404) | null) => void
|
||||
- **事件回调函数:** `(state: StepValue | null) => void`
|
||||
|
||||
::: details 查看 StepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#StepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpType{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
:::
|
||||
|
||||
:::tip
|
||||
当游标处于历史栈边界(已经无法继续撤销或重做)时,`UndoRedo.undo()` / `redo()` 返回 `null`,对应 `change` 回调收到的 `state` 为 `null`
|
||||
:::
|
||||
|
||||
## code-block-history-change
|
||||
|
||||
- **详情:** 代码块历史记录发生变化(`pushCodeBlock` / `undoCodeBlock` / `redoCodeBlock` 成功时触发)
|
||||
|
||||
- **事件回调函数:** `(codeBlockId: Id, step: CodeBlockStepValue) => void`
|
||||
|
||||
::: details 查看 CodeBlockStepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#CodeBlockStepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
:::
|
||||
|
||||
:::tip
|
||||
- 新增触发的 step 中 `oldContent` 为 `null`
|
||||
- 删除触发的 step 中 `newContent` 为 `null`
|
||||
- `undo` / `redo` 返回 `null`(边界状态)时不会触发该事件
|
||||
:::
|
||||
|
||||
## data-source-history-change
|
||||
|
||||
- **详情:** 数据源历史记录发生变化(`pushDataSource` / `undoDataSource` / `redoDataSource` 成功时触发)
|
||||
|
||||
- **事件回调函数:** `(dataSourceId: Id, step: DataSourceStepValue) => void`
|
||||
|
||||
::: details 查看 DataSourceStepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#DataSourceStepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
:::
|
||||
|
||||
:::tip
|
||||
- 新增触发的 step 中 `oldSchema` 为 `null`
|
||||
- 删除触发的 step 中 `newSchema` 为 `null`
|
||||
- `undo` / `redo` 返回 `null`(边界状态)时不会触发该事件
|
||||
:::
|
||||
|
||||
## mark-saved
|
||||
|
||||
- **详情:** 调用 `markSaved` / `markPageSaved` / `markCodeBlockSaved` / `markDataSourceSaved` 标记「已保存」记录时触发
|
||||
|
||||
- **事件回调函数:** `(payload: { kind: 'all' | 'page' | 'code-block' | 'data-source'; id?: Id }) => void`
|
||||
|
||||
::: tip
|
||||
- `markSaved` 触发时 `kind` 为 `all`,无 `id`
|
||||
- 细粒度方法触发时 `kind` 对应类别,`id` 为目标页面 / 代码块 / 数据源 id
|
||||
:::
|
||||
|
||||
## save-to-indexed-db
|
||||
|
||||
- **详情:** `saveToIndexedDB` 把历史记录写入本地 IndexedDB 成功时触发
|
||||
|
||||
- **事件回调函数:** `(snapshot: PersistedHistoryState) => void`
|
||||
|
||||
::: details 查看 PersistedHistoryState 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#PersistedHistoryState{ts}
|
||||
|
||||
<<< @/../packages/editor/src/utils/undo-redo.ts#SerializedUndoRedo{ts}
|
||||
:::
|
||||
|
||||
## restore-from-indexed-db
|
||||
|
||||
- **详情:** `restoreFromIndexedDB` 从本地 IndexedDB 读取并重建历史记录成功时触发(找不到记录时不触发)
|
||||
|
||||
- **事件回调函数:** `(snapshot: PersistedHistoryState) => void`
|
||||
|
||||
::: details 查看 PersistedHistoryState 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#PersistedHistoryState{ts}
|
||||
:::
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
- **详情:**
|
||||
|
||||
重置记录
|
||||
重置全部历史记录(包括页面节点栈、代码块栈、数据源栈),并重置当前页面 id / canRedo / canUndo
|
||||
|
||||
## resetPage
|
||||
|
||||
@ -16,12 +16,18 @@
|
||||
|
||||
- **详情:**
|
||||
|
||||
重置历史记录全部内部状态(清空 pageId、pageSteps、canRedo、canUndo)
|
||||
重置历史记录全部内部状态(清空 pageId、pageSteps、canRedo、canUndo、codeBlockState、dataSourceState)
|
||||
|
||||
## changePage
|
||||
|
||||
- **参数:**
|
||||
- {[MPage](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L157) | [MPageFragment](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L162)} page
|
||||
- `{MPage | MPageFragment} page`
|
||||
|
||||
::: details 查看 MPage / MPageFragment 类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -30,35 +36,349 @@
|
||||
## push
|
||||
|
||||
- **参数:**
|
||||
- {[StepValue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L400-L404)} state
|
||||
- `{StepValue} state`
|
||||
|
||||
::: details 查看 StepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#StepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpType{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#Id{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {[StepValue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L400-L404) | null}
|
||||
- `{StepValue | null}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
添加一条历史记录
|
||||
|
||||
::: tip
|
||||
`opType: 'update'` 的每个 `updatedItems[i]` 上可携带 `changeRecords`,用于撤销 / 重做时仅按
|
||||
`propPath` 局部更新对应字段,避免整节点替换冲掉同节点上的其它无关变更;不带
|
||||
`changeRecords` 时退化为整节点替换(如 `sort` / `moveLayer` / 拖动等纯快照场景)。
|
||||
|
||||
`StepValue` 上的 `historyDescription` / `source` 仅用于历史面板展示与埋点,不影响 undo/redo 行为。
|
||||
|
||||
入栈时会为每条记录自动生成唯一标识 `uuid`(调用方未指定时),可用于精确引用 / 定位某一条历史记录。
|
||||
若需要在执行 DSL 操作后拿到本次写入记录的 `uuid`,可使用 editorService / dataSourceService /
|
||||
codeBlockService 提供的 `*AndGetHistoryId` 方法,参见
|
||||
[editorService 历史记录 uuid 与 \*AndGetHistoryId](./editorServiceMethods.md#历史记录-uuid-与-andgethistoryid)。
|
||||
`pushCodeBlock` / `pushDataSource` 同样会自动写入 `uuid`。
|
||||
:::
|
||||
|
||||
## undo
|
||||
|
||||
- **返回:**
|
||||
- {[StepValue](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/editor/src/type.ts#L554-L573) | null}
|
||||
- `{StepValue | null}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
撤销当前操作
|
||||
撤销当前操作。`opType: 'update'` 时,若 `updatedItems[i].changeRecords` 存在,会按
|
||||
`propPath` 从 `oldNode` 取值做局部回滚;否则用 `oldNode` 整节点替换。
|
||||
|
||||
## redo
|
||||
|
||||
- **返回:**
|
||||
- {[StepValue](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/editor/src/type.ts#L554-L573) | null}
|
||||
- `{StepValue | null}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
恢复到下一步
|
||||
恢复到下一步。`opType: 'update'` 时,若 `updatedItems[i].changeRecords` 存在,会按
|
||||
`propPath` 从 `newNode` 取值做局部重做;否则用 `newNode` 整节点替换。
|
||||
|
||||
## pushCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId` 代码块 id
|
||||
- `{Object} payload`
|
||||
- `{CodeBlockContent | null} oldContent` 变更前的代码块内容;新增时为 `null`
|
||||
- `{CodeBlockContent | null} newContent` 变更后的代码块内容;删除时为 `null`
|
||||
- `{ChangeRecord[]} changeRecords` 可选;form 端 propPath/value 变更列表,撤销/重做时若有则按 propPath 局部更新;缺省(或空数组)才退化为整内容替换
|
||||
- `{string}` historyDescription 可选;人类可读描述,用于历史面板展示;不影响 undo/redo 行为
|
||||
- `{HistoryOpSource}` source 可选;操作途径,用于历史面板展示与埋点;不影响 undo/redo 行为
|
||||
|
||||
::: details 查看 CodeBlockStepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#CodeBlockStepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{CodeBlockStepValue | null}` 入栈失败(未传 id)时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
推入一条代码块变更记录。与页面 / 节点完全无关,按 `codeBlockId` 维度独立一份 `UndoRedo` 栈,
|
||||
栈实例存放在 `historyService.state.codeBlockState[codeBlockId]`。
|
||||
|
||||
入栈成功后会触发 `code-block-history-change` 事件。
|
||||
|
||||
::: tip
|
||||
`codeBlockService.setCodeDslByIdSync` 与 `codeBlockService.deleteCodeDslByIds` 内部已经
|
||||
自动调用本方法,业务代码通常无需手动调用。
|
||||
:::
|
||||
|
||||
## undoCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId`
|
||||
|
||||
- **返回:**
|
||||
- `{CodeBlockStepValue | null}` 栈不存在或已无可撤销记录时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
撤销指定代码块的最近一次变更。成功时会触发 `code-block-history-change` 事件。
|
||||
拿到 step 后由调用方根据 `step.oldContent` 写回 `codeBlockService`(本方法不会自动回放)。
|
||||
|
||||
## redoCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId`
|
||||
|
||||
- **返回:**
|
||||
- `{CodeBlockStepValue | null}` 栈不存在或已无可重做记录时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
重做指定代码块的下一次变更。成功时会触发 `code-block-history-change` 事件。
|
||||
|
||||
## canUndoCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId`
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
指定代码块当前是否可撤销。栈不存在时返回 `false`。
|
||||
|
||||
## canRedoCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId`
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
指定代码块当前是否可重做。栈不存在时返回 `false`。
|
||||
|
||||
## pushDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId` 数据源 id
|
||||
- `{Object} payload`
|
||||
- `{DataSourceSchema | null} oldSchema` 变更前的数据源 schema;新增时为 `null`
|
||||
- `{DataSourceSchema | null} newSchema` 变更后的数据源 schema;删除时为 `null`
|
||||
- `{ChangeRecord[]} changeRecords` 可选;form 端 propPath/value 变更列表,撤销/重做时若有则按 propPath 局部更新;缺省(或空数组)才退化为整 schema 替换
|
||||
- `{string}` historyDescription 可选;人类可读描述,用于历史面板展示;不影响 undo/redo 行为
|
||||
- `{HistoryOpSource}` source 可选;操作途径,用于历史面板展示与埋点;不影响 undo/redo 行为
|
||||
|
||||
::: details 查看 DataSourceStepValue 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#DataSourceStepValue{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#HistoryOpSource{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{DataSourceStepValue | null}` 入栈失败(未传 id)时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
推入一条数据源变更记录。与页面 / 节点完全无关,按 `dataSourceId` 维度独立一份 `UndoRedo` 栈,
|
||||
栈实例存放在 `historyService.state.dataSourceState[dataSourceId]`。
|
||||
|
||||
入栈成功后会触发 `data-source-history-change` 事件。
|
||||
|
||||
::: tip
|
||||
`dataSourceService.add` / `update` / `remove` 内部已经自动调用本方法,业务代码通常无需手动调用。
|
||||
:::
|
||||
|
||||
## undoDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId`
|
||||
|
||||
- **返回:**
|
||||
- `{DataSourceStepValue | null}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
撤销指定数据源的最近一次变更。成功时会触发 `data-source-history-change` 事件。
|
||||
拿到 step 后由调用方根据 `step.oldSchema` 写回 `dataSourceService`(本方法不会自动回放)。
|
||||
|
||||
## redoDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId`
|
||||
|
||||
- **返回:**
|
||||
- `{DataSourceStepValue | null}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
重做指定数据源的下一次变更。成功时会触发 `data-source-history-change` 事件。
|
||||
|
||||
## canUndoDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId`
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
指定数据源当前是否可撤销。栈不存在时返回 `false`。
|
||||
|
||||
## canRedoDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId`
|
||||
|
||||
- **返回:**
|
||||
- `{boolean}`
|
||||
|
||||
- **详情:**
|
||||
|
||||
指定数据源当前是否可重做。栈不存在时返回 `false`。
|
||||
|
||||
## markSaved
|
||||
|
||||
- **详情:**
|
||||
|
||||
标记「整份 DSL 已保存」:把页面 / 代码块 / 数据源所有栈当前游标所在的记录都标记为已保存(`saved = true`)。
|
||||
|
||||
同一栈内任意时刻最多保留一条已保存记录(标记前会清除该栈内全部旧标记);某个栈处于「全部已撤销」(cursor 为 0)时不会留下已保存记录,从 IndexedDB 恢复时其游标会回到 0。
|
||||
|
||||
通常在 DSL 整体落库(保存到后端 / 本地)成功后调用,配合 [`restoreFromIndexedDB`](#restorefromindexeddb) 把游标恢复到此处。仅保存了其中一类时请改用更细粒度的 `markPageSaved` / `markCodeBlockSaved` / `markDataSourceSaved`。
|
||||
|
||||
调用后会触发 `mark-saved` 事件(`{ kind: 'all' }`)。
|
||||
|
||||
## markPageSaved
|
||||
|
||||
- **参数:**
|
||||
- `{Id} pageId` 可选;缺省为当前活动页
|
||||
|
||||
- **详情:**
|
||||
|
||||
标记指定页面(缺省当前活动页)历史栈的当前记录为已保存,仅影响该页面自己的栈。触发 `mark-saved` 事件(`{ kind: 'page', id }`)。
|
||||
|
||||
## markCodeBlockSaved
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId`
|
||||
|
||||
- **详情:**
|
||||
|
||||
标记指定代码块历史栈的当前记录为已保存,仅影响该代码块自己的栈。触发 `mark-saved` 事件(`{ kind: 'code-block', id }`)。
|
||||
|
||||
## markDataSourceSaved
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId`
|
||||
|
||||
- **详情:**
|
||||
|
||||
标记指定数据源历史栈的当前记录为已保存,仅影响该数据源自己的栈。触发 `mark-saved` 事件(`{ kind: 'data-source', id }`)。
|
||||
|
||||
## clearPage
|
||||
|
||||
- **参数:**
|
||||
- `{Id} pageId` 可选;缺省为当前活动页
|
||||
|
||||
- **详情:**
|
||||
|
||||
清空指定页面(缺省当前活动页)的历史记录栈。仅删除撤销/重做记录,不会改动当前 DSL;清空后该页将无法再撤销/重做之前的操作。清空当前活动页时会同步刷新 `canUndo` / `canRedo` 并触发 `change` 事件。
|
||||
|
||||
## clearCodeBlock
|
||||
|
||||
- **参数:**
|
||||
- `{Id} codeBlockId` 可选;缺省清空全部代码块
|
||||
|
||||
- **详情:**
|
||||
|
||||
清空代码块历史记录栈:传入 `codeBlockId` 仅清空该代码块,缺省清空全部代码块。仅删除撤销/重做记录,不会改动代码块本身。
|
||||
|
||||
## clearDataSource
|
||||
|
||||
- **参数:**
|
||||
- `{Id} dataSourceId` 可选;缺省清空全部数据源
|
||||
|
||||
- **详情:**
|
||||
|
||||
清空数据源历史记录栈:传入 `dataSourceId` 仅清空该数据源,缺省清空全部数据源。仅删除撤销/重做记录,不会改动数据源本身。
|
||||
|
||||
## saveToIndexedDB
|
||||
|
||||
- **参数:**
|
||||
- `{HistoryPersistOptions} options` 可选
|
||||
|
||||
::: details 查看 HistoryPersistOptions / PersistedHistoryState 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#HistoryPersistOptions{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#PersistedHistoryState{ts}
|
||||
|
||||
<<< @/../packages/editor/src/utils/undo-redo.ts#SerializedUndoRedo{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<PersistedHistoryState>}` 写入成功的快照对象
|
||||
|
||||
- **详情:**
|
||||
|
||||
把当前内存中的全部历史栈(页面 / 代码块 / 数据源)连同各自游标、容量序列化后写入本地 IndexedDB。
|
||||
|
||||
- 最终库名为 `${dbName}-${当前 DSL app id}`,按应用隔离;
|
||||
- `key` 用于在同一 store 下区分不同记录,缺省为 `default`;
|
||||
- 历史记录里可能包含函数(代码块内容 / 节点事件等),内部使用 `serialize-javascript` 序列化为字符串后写入,恢复时再用 `parseDSL` 还原,因此可安全持久化函数 / `Map` 等;
|
||||
- 不支持 IndexedDB 的环境(如 SSR)会 reject。
|
||||
|
||||
写入成功后触发 `save-to-indexed-db` 事件。
|
||||
|
||||
::: warning
|
||||
`beforeunload` / `pagehide` 阶段浏览器不会等待异步 IndexedDB 事务提交,单纯依赖卸载时写入可能丢失最近一次编辑。建议在历史变更时(防抖)即调用本方法持久化,确保刷新后能完整恢复。
|
||||
:::
|
||||
|
||||
## restoreFromIndexedDB
|
||||
|
||||
- **参数:**
|
||||
- `{HistoryPersistOptions} options` 可选
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<PersistedHistoryState | null>}` 找不到记录时返回 `null`
|
||||
|
||||
- **详情:**
|
||||
|
||||
从本地 IndexedDB 读取此前保存的历史快照并重建全部撤销/重做栈。
|
||||
|
||||
- 每个栈都会按 `listMaxSize` 裁剪并还原游标;
|
||||
- 若某个栈存在已保存记录(见 `markSaved`),其游标会被定位到「最近一条已保存记录」之后,使恢复后的状态与落库的 DSL 对齐;
|
||||
- 会整体覆盖当前内存中的历史状态,并把活动页恢复为快照中的 `pageId`;
|
||||
- 找不到对应记录时返回 `null` 且不改动当前状态;不支持 IndexedDB 的环境会 reject。
|
||||
|
||||
成功后触发 `restore-from-indexed-db` 与 `change` 事件。
|
||||
|
||||
## destroy
|
||||
|
||||
- **详情:**
|
||||
|
||||
销毁
|
||||
|
||||
|
||||
@ -9,7 +9,25 @@
|
||||
- **默认值:** `{}`
|
||||
|
||||
|
||||
- **类型:** [MApp](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/schema/src/index.ts?plain=1#L66-L73)[]
|
||||
- **类型:** `MApp[]`
|
||||
|
||||
::: details 查看 MApp 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#NodeType{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockDSL{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceDeps{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -49,7 +67,13 @@ const dsl = ref({
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** [ComponentGroup](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/editor/src/type.ts#L355)
|
||||
- **类型:** `ComponentGroup[]`
|
||||
|
||||
::: details 查看 ComponentGroup 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#ComponentGroup{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#ComponentItem{ts}
|
||||
:::
|
||||
|
||||
::: tip
|
||||
icon使用的是[element-plus icon](https://element-plus.org/zh-CN/component/icon.html)
|
||||
@ -128,7 +152,11 @@ const componentGroupList = ref([
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** [DatasourceTypeOption](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/editor/src/type.ts#L589)
|
||||
- **类型:** `DatasourceTypeOption[]`
|
||||
|
||||
::: details 查看 DatasourceTypeOption 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#DatasourceTypeOption{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -169,7 +197,21 @@ const datasourceTypeList = ref([
|
||||
}
|
||||
```
|
||||
|
||||
- **类型:** [SideBarData](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L258-L265)
|
||||
- **类型:** `SideBarData`
|
||||
|
||||
::: details 查看 SideBarData 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#SideBarData{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#SideItem{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#SideItemKey{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#SideComponent{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#MenuComponent{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#Services{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -218,7 +260,7 @@ icon使用的是[element-plus icon](https://element-plus.org/zh-CN/component/ico
|
||||
|
||||
顶部工具栏
|
||||
|
||||
系统提供了几个常用功能: `'/' | 'delete' | 'undo' | 'redo' | 'zoom-in' | 'zoom-out' | 'zoom' | 'guides' | 'rule' | 'scale-to-original' | 'scale-to-fit'`
|
||||
系统提供了几个常用功能: `'/' | 'delete' | 'undo' | 'redo' | 'zoom-in' | 'zoom-out' | 'zoom' | 'guides' | 'rule' | 'scale-to-original' | 'scale-to-fit' | 'history-list'`
|
||||
|
||||
'/': 分隔符
|
||||
|
||||
@ -242,13 +284,29 @@ icon使用的是[element-plus icon](https://element-plus.org/zh-CN/component/ico
|
||||
|
||||
'scale-to-fit': 缩放以适应
|
||||
|
||||
'history-list': 历史记录面板(按 页面 / 数据源 / 代码块 三个 tab 展示操作历史,相邻同目标修改自动合并,支持点击跳转、回到初始状态、单步回滚及差异对比,详见[历史记录面板](/guide/advanced/history-list.md))
|
||||
|
||||
- **默认值:**
|
||||
|
||||
```js
|
||||
{ left: [], center: [], right: [] }
|
||||
```
|
||||
|
||||
- **类型:** [MenuBarData](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L235-L242)
|
||||
- **类型:** `MenuBarData`
|
||||
|
||||
::: details 查看 MenuBarData 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#MenuBarData{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#ColumnLayout{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#MenuItem{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#MenuButton{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#MenuComponent{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#Services{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -296,7 +354,15 @@ const menu = ref({
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** ([MenuButton](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L168-L195) | [MenuComponent](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L197-L210))[]
|
||||
- **类型:** `(MenuButton | MenuComponent)[]`
|
||||
|
||||
::: details 查看 MenuButton / MenuComponent 及关联类型定义
|
||||
<<< @/../packages/editor/src/type.ts#MenuButton{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#MenuComponent{ts}
|
||||
|
||||
<<< @/../packages/editor/src/type.ts#Services{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -330,7 +396,9 @@ const layerContentMenu = ref([
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** ([MenuButton](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L168-L195) | [MenuComponent](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/type.ts#L197-L210))[]
|
||||
- **类型:** `(MenuButton | MenuComponent)[]`
|
||||
|
||||
> 已在上面 [layerContentMenu](#layercontentmenu) 段落展开过相同类型,参考即可。
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -471,7 +539,19 @@ const renderFunction = async (stage) => {
|
||||
|
||||
- **默认值:** `{}`
|
||||
-
|
||||
- **类型:** Record<string, [FormConfig](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/form/src/schema.ts#L706)>
|
||||
- **类型:** `Record<string, FormConfig>`
|
||||
|
||||
::: details 查看 FormConfig 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItemConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChildConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicTypeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -552,7 +632,11 @@ const propsValues = {
|
||||
|
||||
- **默认值:** `{}`
|
||||
|
||||
- **类型:** Record<string, { events: [EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[]; methods: [EventOption](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/core/src/events.ts#L26-L29)[] }>
|
||||
- **类型:** `Record<string, { events: EventOption[]; methods: EventOption[] }>`
|
||||
|
||||
::: details 查看 EventOption 类型定义
|
||||
<<< @/../packages/core/src/utils.ts#EventOption{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -593,7 +677,23 @@ const eventMethodList = {
|
||||
|
||||
- **默认值:** `{}`
|
||||
|
||||
- **类型:** Record<string, Partial<[DataSourceSchema](https://github.com/Tencent/tmagic-editor/blob/5880dfbe15fcead63e9dc7c91900f8c4e7a574d8/packages/schema/src/index.ts#L221)>>
|
||||
- **类型:** `Record<string, Partial<DataSourceSchema>>`
|
||||
|
||||
::: details 查看 DataSourceSchema 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#DataSourceSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#DataSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MockSchema{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeBlockContent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#CodeParam{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#EventConfig{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#JsEngine{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -634,7 +734,9 @@ const datasourceValues = {
|
||||
|
||||
- **默认值:** `{}`
|
||||
|
||||
- **类型:** Record<string, [FormConfig](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/form/src/schema.ts#L706)>
|
||||
- **类型:** `Record<string, FormConfig>`
|
||||
|
||||
> 已在上面 [propsConfigs](#propsconfigs) 段落展开过 `FormConfig` 类型定义,参考即可。
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -675,7 +777,11 @@ const datasourceConfigs = {
|
||||
|
||||
- **默认值:** `{}`
|
||||
|
||||
- **类型:** ((config: [CustomizeMoveableOptionsCallbackConfig](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/stage/src/types.ts#L97-L109)) => MoveableOptions) | [MoveableOptions](https://daybrush.com/moveable/release/latest/doc/)
|
||||
- **类型:** `((config: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions) | `[`MoveableOptions`](https://daybrush.com/moveable/release/latest/doc/)
|
||||
|
||||
::: details 查看 CustomizeMoveableOptionsCallbackConfig 类型定义
|
||||
<<< @/../packages/stage/src/types.ts#CustomizeMoveableOptionsCallbackConfig{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -1114,6 +1220,28 @@ const guidesOptions = {
|
||||
</template>
|
||||
```
|
||||
|
||||
## disabledFlashTip
|
||||
|
||||
- **详情:**
|
||||
|
||||
禁用「非点击画布选中组件时的高亮闪烁提示」。
|
||||
|
||||
当组件不是通过点击画布选中(如从组件树、面包屑等外部方式选中)时,编辑器会在画布上对选中区域做一次高亮闪烁,帮助用户快速定位组件在画布中的位置。设置为 `true` 可关闭该提示。
|
||||
|
||||
注:选中页面(`magic-ui-page`)时不会触发闪烁。
|
||||
|
||||
- **默认值:** `false`
|
||||
|
||||
- **类型:** `boolean`
|
||||
|
||||
- **示例:**
|
||||
|
||||
```html
|
||||
<template>
|
||||
<m-editor :disabled-flash-tip="true"></m-editor>
|
||||
</template>
|
||||
```
|
||||
|
||||
## disabledStageOverlay
|
||||
|
||||
- **详情:**
|
||||
@ -1402,6 +1530,55 @@ const extendFormState = async (state) => {
|
||||
```
|
||||
:::
|
||||
|
||||
## historyListExtraTabs
|
||||
|
||||
- **详情:**
|
||||
|
||||
[历史记录面板](/guide/advanced/history-list.md) 的自定义扩展 tab。
|
||||
|
||||
业务方可借此在历史记录面板内置的「页面 / 数据源 / 代码块」三个 tab 之后追加自定义模块的历史 tab,例如某个自定义模块维护自己的操作历史时,可在面板中增加一个独立的 tab 来展示与回滚。
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** `HistoryListExtraTab[]`
|
||||
|
||||
::: details 查看 HistoryListExtraTab 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#HistoryListExtraTab{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```html
|
||||
<template>
|
||||
<m-editor :menu="menu" :history-list-extra-tabs="historyListExtraTabs"></m-editor>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { markRaw } from 'vue';
|
||||
|
||||
import MyModuleHistoryTab from './MyModuleHistoryTab.vue';
|
||||
|
||||
const historyListExtraTabs = [
|
||||
{
|
||||
name: 'my-module',
|
||||
// label 支持字符串或函数,函数形式便于展示动态数量
|
||||
label: () => '我的模块',
|
||||
component: markRaw(MyModuleHistoryTab),
|
||||
// 传入内容组件的 props
|
||||
props: { foo: 'bar' },
|
||||
// 内容组件的事件监听
|
||||
listeners: {
|
||||
goto: (cursor) => console.log(cursor),
|
||||
},
|
||||
},
|
||||
];
|
||||
</script>
|
||||
```
|
||||
|
||||
::: tip
|
||||
内容组件内部可自行通过 `useServices()` 获取 `historyService` 等服务来读取与回滚自定义模块的历史。
|
||||
:::
|
||||
|
||||
## pageBarSortOptions
|
||||
|
||||
- **详情:**
|
||||
@ -1412,7 +1589,11 @@ const extendFormState = async (state) => {
|
||||
|
||||
- **默认值:** `undefined`
|
||||
|
||||
- **类型:** [PageBarSortOptions](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/type.ts)
|
||||
- **类型:** `PageBarSortOptions`
|
||||
|
||||
::: details 查看 PageBarSortOptions 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#PageBarSortOptions{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
|
||||
@ -47,11 +47,23 @@
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)} config
|
||||
- {`FormConfig`} config
|
||||
- `{string}` labelWidth 表单项 label 宽度,默认 `'80px'`
|
||||
|
||||
::: details 查看 FormConfig 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItemConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChildConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicTypeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)>}
|
||||
- {Promise<`FormConfig`>}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -60,7 +72,11 @@
|
||||
## setPropsConfigs
|
||||
|
||||
- **参数:**
|
||||
- {Record<string, [FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864) | [PropsFormConfigFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/editor/src/type.ts#L721)>} configs
|
||||
- {Record<string, `FormConfig` | `PropsFormConfigFunction`>} configs
|
||||
|
||||
::: details 查看 PropsFormConfigFunction 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#PropsFormConfigFunction{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -75,7 +91,7 @@
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 组件类型
|
||||
- {[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)} config 属性表单配置DSL
|
||||
- {`FormConfig`} config 属性表单配置DSL
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -91,10 +107,26 @@
|
||||
- **参数:**
|
||||
- `{string}` type 组件类型
|
||||
- `{Object}` data 可选参数
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210) | null} node 当前节点
|
||||
- {`MNode` | null} node 当前节点
|
||||
|
||||
::: details 查看 MNode 及关联类型定义
|
||||
<<< @/../packages/schema/src/index.ts#MNode{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MComponent{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MIteratorContainer{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPage{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MApp{ts}
|
||||
|
||||
<<< @/../packages/schema/src/index.ts#MPageFragment{ts}
|
||||
:::
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)>}
|
||||
- {Promise<`FormConfig`>}
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -103,7 +135,7 @@
|
||||
## setPropsValues
|
||||
|
||||
- **参数:**
|
||||
- {Record<string, [MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>} values
|
||||
- {Record<string, `MNode`>} values
|
||||
|
||||
- **返回:**
|
||||
- `{void}`
|
||||
@ -116,7 +148,7 @@
|
||||
|
||||
- **参数:**
|
||||
- `{string}` type 组件类型
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} value 组件初始值
|
||||
- {`MNode`} value 组件初始值
|
||||
|
||||
- **返回:**
|
||||
- `{Promise<void>}`
|
||||
@ -134,7 +166,7 @@
|
||||
- `{Object}` defaultValue 组件默认值,可选
|
||||
|
||||
- **返回:**
|
||||
- {Promise<[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)>} 合并默认配置后的节点对象
|
||||
- {Promise<`MNode`>} 合并默认配置后的节点对象
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -159,11 +191,11 @@
|
||||
- **[扩展支持](../../guide/editor-expand#行为扩展):** 是
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} config
|
||||
- {`MNode`} config
|
||||
- `{boolean}` force 是否强制设置新ID,默认 `true`
|
||||
|
||||
- **返回:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)} 处理后的节点
|
||||
- {`MNode`} 处理后的节点
|
||||
|
||||
- **详情:**
|
||||
|
||||
@ -186,8 +218,8 @@
|
||||
## replaceRelateId
|
||||
|
||||
- **参数:**
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} originConfigs 原始组件配置
|
||||
- {[MNode](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/schema/src/index.ts#L210)[]} targetConfigs 待替换的组件配置
|
||||
- {`MNode`[]} originConfigs 原始组件配置
|
||||
- {`MNode`[]} targetConfigs 待替换的组件配置
|
||||
- `{TargetOptions}` collectorOptions 依赖收集器配置
|
||||
|
||||
- **返回:**
|
||||
@ -222,15 +254,11 @@
|
||||
|
||||
销毁propsService
|
||||
|
||||
## use
|
||||
|
||||
使用中间件的方式扩展方法,上述方法中标记有`扩展支持: 是`的方法都支持使用use扩展
|
||||
|
||||
## usePlugin
|
||||
|
||||
- **详情:**
|
||||
|
||||
相对于[use](#use), usePlugin支持更加灵活更加细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
usePlugin支持灵活细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
|
||||
每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值
|
||||
|
||||
@ -239,3 +267,4 @@
|
||||
- **详情:**
|
||||
|
||||
删掉当前设置的所有扩展
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
|
||||
- **详情:** 编辑器顶部菜单栏
|
||||
|
||||
- **默认:** [NavMenu.vue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/layouts/NavMenu.vue)
|
||||
- **默认:** [NavMenu.vue](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/NavMenu.vue)
|
||||
|
||||
- **插槽 Props:**
|
||||
- `editorService`: editorService 实例
|
||||
@ -64,7 +64,7 @@
|
||||
|
||||
- **详情:** 左边栏
|
||||
|
||||
- **默认:** [Sidebar.vue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/layouts/sidebar/Sidebar.vue)
|
||||
- **默认:** [Sidebar.vue](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/sidebar/Sidebar.vue)
|
||||
|
||||
- **插槽 Props:**
|
||||
- `editorService`: editorService 实例
|
||||
@ -259,7 +259,7 @@
|
||||
|
||||
- **详情:** 编辑器中间区域
|
||||
|
||||
- **默认:** [Workspace.vue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/layouts/workspace/Workspace.vue)
|
||||
- **默认:** [Workspace.vue](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/workspace/Workspace.vue)
|
||||
|
||||
- **插槽 Props:**
|
||||
- `editorService`: editorService 实例
|
||||
@ -268,7 +268,7 @@
|
||||
|
||||
- **详情:** 画布
|
||||
|
||||
- **默认:** [Stage.vue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/layouts/workspace/Stage.vue)
|
||||
- **默认:** [Stage.vue](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/workspace/Stage.vue)
|
||||
|
||||
## stage-top
|
||||
|
||||
@ -380,7 +380,7 @@
|
||||
|
||||
- **详情:** 当前没有页面时,编辑器中间区域
|
||||
|
||||
- **默认:** [AddPageBox.vue](https://github.com/Tencent/tmagic-editor/blob/239b5d3efeae916a8cf3e3566d88063ecccc0553/packages/editor/src/layouts/AddPageBox.vue)
|
||||
- **默认:** [AddPageBox.vue](https://github.com/Tencent/tmagic-editor/blob/master/packages/editor/src/layouts/AddPageBox.vue)
|
||||
|
||||
- **插槽 Props:**
|
||||
- `editorService`: editorService 实例
|
||||
|
||||
@ -231,28 +231,11 @@ import { storageService } from '@tmagic/editor';
|
||||
storageService.destroy();
|
||||
```
|
||||
|
||||
## use
|
||||
|
||||
使用中间件的方式扩展方法,上述方法中标记有`扩展支持: 是`的方法都支持使用use扩展
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { storageService } from '@tmagic/editor';
|
||||
|
||||
storageService.use({
|
||||
getItem(key, options, next) {
|
||||
console.log('获取存储项:', key);
|
||||
return next();
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## usePlugin
|
||||
|
||||
- **详情:**
|
||||
|
||||
相对于[use](#use), usePlugin支持更加灵活更加细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
usePlugin支持灵活细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
|
||||
每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值
|
||||
|
||||
|
||||
28
docs/api/editor/uiServiceEvents.md
Normal file
28
docs/api/editor/uiServiceEvents.md
Normal file
@ -0,0 +1,28 @@
|
||||
# uiService事件
|
||||
|
||||
## state-change
|
||||
|
||||
- **详情:** UI 状态发生变化时触发,[uiService.set()](./uiServiceMethods.md#set) 在写入的新值与旧值不同时触发
|
||||
|
||||
- **事件回调函数:** `(name: keyof UiState, value: UiState[typeof name], preValue: UiState[typeof name]) => void`
|
||||
|
||||
::: details 查看 UiState 类型定义
|
||||
<<< @/../packages/editor/src/type.ts#UiState{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { uiService } from '@tmagic/editor';
|
||||
|
||||
uiService.on('state-change', (name, value, preValue) => {
|
||||
console.log(`${name} 从`, preValue, '变为', value);
|
||||
});
|
||||
|
||||
uiService.set('zoom', 1.5);
|
||||
```
|
||||
|
||||
:::tip
|
||||
- 新值与旧值相同时不会触发该事件
|
||||
- 通过 `set('stageRect', value)` 修改画布尺寸时,内部会走 `setStageRect` 逻辑并可能联动更新 `zoom`,但不会触发 `state-change` 事件
|
||||
:::
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
- **详情:**
|
||||
|
||||
设置UI服务的状态
|
||||
设置UI服务的状态。新值与旧值不同时会触发 [`state-change`](./uiServiceEvents.md#state-change) 事件
|
||||
|
||||
可用的状态键:
|
||||
- `uiSelectMode`: UI选择模式
|
||||
@ -31,6 +31,7 @@
|
||||
- `showPageListButton`: 是否显示页面列表按钮
|
||||
- `hideSlideBar`: 是否隐藏侧边栏
|
||||
- `sideBarItems`: 侧边栏项目
|
||||
- `sideBarActiveTabName`: 当前激活的侧边栏面板
|
||||
- `navMenuRect`: 导航菜单尺寸
|
||||
- `frameworkRect`: 框架尺寸
|
||||
|
||||
@ -179,29 +180,11 @@ import { uiService } from '@tmagic/editor';
|
||||
uiService.destroy();
|
||||
```
|
||||
|
||||
## use
|
||||
|
||||
使用中间件的方式扩展方法,上述方法中标记有`扩展支持: 是`的方法都支持使用use扩展
|
||||
|
||||
- **示例:**
|
||||
|
||||
```js
|
||||
import { uiService } from '@tmagic/editor';
|
||||
|
||||
uiService.use({
|
||||
async zoom(value, next) {
|
||||
console.log('缩放前:', uiService.get('zoom'));
|
||||
await next();
|
||||
console.log('缩放后:', uiService.get('zoom'));
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## usePlugin
|
||||
|
||||
- **详情:**
|
||||
|
||||
相对于[use](#use), usePlugin支持更加灵活更加细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
usePlugin支持灵活细致的扩展, 上述方法中标记有`扩展支持: 是`的方法都支持使用usePlugin扩展
|
||||
|
||||
每个支持扩展的方法都支持定制before、after两个hook来干预原有方法的行为,before可以用于修改传入参数,after可以用于修改返回的值
|
||||
|
||||
|
||||
@ -6,7 +6,19 @@
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** [FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)
|
||||
- **类型:** `FormConfig`
|
||||
|
||||
::: details 查看 FormConfig 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItemConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChildConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicTypeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
|
||||
- **详情:** 提交表单,先执行校验,校验通过后清空 `changeRecords` 并返回当前表单值
|
||||
|
||||
- **相关:** 如果你想脱离组件树以函数方式完成一次表单提交,参见 [`submitForm` 函数](./submit-form.md)
|
||||
|
||||
## changeHandler
|
||||
|
||||
- **签名:** `(prop: string, value: any, eventData?: ContainerChangeEventData) => void`
|
||||
|
||||
@ -6,7 +6,19 @@
|
||||
|
||||
- **默认值:** `[]`
|
||||
|
||||
- **类型:** [FormConfig](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L864)
|
||||
- **类型:** `FormConfig`
|
||||
|
||||
::: details 查看 FormConfig 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItemConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChildConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicTypeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
:::
|
||||
|
||||
- **示例:**
|
||||
|
||||
@ -73,6 +85,44 @@
|
||||
|
||||
- **类型:** `boolean`
|
||||
|
||||
## showDiff
|
||||
|
||||
- **详情:**
|
||||
|
||||
自定义“是否展示对比内容”的判断函数(仅在 `isCompare === true` 时生效)。
|
||||
|
||||
- 不传:使用默认逻辑 `!isEqual(curValue, lastValue)`(基于 lodash `isEqual`);
|
||||
- 传函数:完全以函数返回值为准,返回 `true` 才展示前后两份对比内容。
|
||||
|
||||
该 prop 通过 `formState` 透传到所有层级的 Container 中,调用方只需在 MForm 这一层传一次即可对整棵表单生效。
|
||||
|
||||
典型场景:某些字段语义上相等但结构不同(例如 `code-select` 字段中 `''` 与 `{ hookType: 'code', hookData: [] }` 应视为相等),调用方在此处显式声明,避免被 `isEqual` 误判为差异。
|
||||
|
||||
- **类型:** `(data: { curValue: any; lastValue: any; config: FormItemConfig }) => boolean`
|
||||
|
||||
- **示例:**
|
||||
|
||||
```html
|
||||
<template>
|
||||
<m-form :config="config" :is-compare="true" :last-values="lastValues" :show-diff="showDiff"></m-form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
const showDiff = ({ curValue, lastValue, config }) => {
|
||||
if (config?.type === 'code-select') {
|
||||
// 业务侧自定义:双方都是“空形态”视为相等,不展示对比
|
||||
const isEmpty = (v) =>
|
||||
v === '' || v === undefined || v === null ||
|
||||
(typeof v === 'object' && v.hookType === 'code' && Array.isArray(v.hookData) && v.hookData.length === 0);
|
||||
if (isEmpty(curValue) && isEmpty(lastValue)) return false;
|
||||
}
|
||||
return !isEqual(curValue, lastValue);
|
||||
};
|
||||
</script>
|
||||
```
|
||||
|
||||
## parentValues
|
||||
|
||||
- **详情:** 父级表单值
|
||||
|
||||
218
docs/api/form/submit-form.md
Normal file
218
docs/api/form/submit-form.md
Normal file
@ -0,0 +1,218 @@
|
||||
# submitForm 函数
|
||||
|
||||
以命令式方式调用 `MForm` 组件完成一次表单校验/提交,类似 `ElMessage` 的用法。
|
||||
|
||||
调用时函数内部会临时挂载一个不可见的 `MForm` 实例,把入参作为 props 透传给它,等待初始化完成后调用其 `submitForm` 方法。校验通过则 `resolve` 表单值,校验失败则 `reject` 错误信息,最后自动卸载实例并清理 DOM。
|
||||
|
||||
适用于一些没有合适的容器、但又需要复用 `MForm` 校验逻辑的场景,例如:
|
||||
|
||||
- 通过快捷菜单/命令面板触发一次性表单
|
||||
- 在脚本/服务层完成一次表单值校验后再发请求
|
||||
- 把 `config` 配置当作"可执行的校验规则"使用
|
||||
|
||||
## 签名
|
||||
|
||||
```ts
|
||||
function submitForm(options: SubmitFormOptions): Promise<any>;
|
||||
```
|
||||
|
||||
## 参数
|
||||
|
||||
`options` 与 `MForm` 组件的 props 基本对齐,额外提供了 `native`、`returnChangeRecords`、`appContext`、`timeout` 等参数。
|
||||
|
||||
| 名称 | 类型 | 默认值 | 说明 |
|
||||
| ---------------------- | ------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------- |
|
||||
| `config` | `FormConfig` | — | 必填,表单配置 |
|
||||
| `initValues` | `Record<string, any>` | `{}` | 表单初始值 |
|
||||
| `lastValues` | `Record<string, any>` | `{}` | 需对比的值(开启对比模式时传入) |
|
||||
| `isCompare` | `boolean` | `false` | 是否开启对比模式 |
|
||||
| `parentValues` | `Record<string, any>` | `{}` | 父级 values,透传给字段的回调 |
|
||||
| `labelWidth` | `string` | `'200px'` | label 宽度 |
|
||||
| `disabled` | `boolean` | `false` | 是否禁用 |
|
||||
| `height` | `string` | `'auto'` | 表单高度 |
|
||||
| `stepActive` | `string \| number` | `1` | 步骤表单当前激活步骤 |
|
||||
| `size` | `'small' \| 'default' \| 'large'` | — | 组件尺寸 |
|
||||
| `inline` | `boolean` | `false` | 是否行内表单 |
|
||||
| `labelPosition` | `string` | `'right'` | label 对齐方式 |
|
||||
| `keyProp` | `string` | `'__key'` | 配置项的唯一 key |
|
||||
| `popperClass` | `string` | — | 弹层 className |
|
||||
| `preventSubmitDefault` | `boolean` | — | 是否阻止表单原生 submit |
|
||||
| `extendState` | `(state: FormState) => Record<string, any> \| Promise<Record<string, any>>` | — | 扩展 `formState` |
|
||||
| `native` | `boolean` | `false` | 透传给 `Form.submitForm`。`true` 时返回内部响应式 `values`,否则返回 `cloneDeep(toRaw(values))` |
|
||||
| `returnChangeRecords` | `boolean` | `false` | `true` 时 resolve 结果为 `{ values, changeRecords }`,携带表单变更记录;否则仅 resolve `values` |
|
||||
| `appContext` | `AppContext \| null` | `null` | 父级 Vue 应用上下文。需要继承全局组件、指令、provide 等时传入,常通过 `app._context` 或 `getCurrentInstance()?.appContext` 获取 |
|
||||
| `timeout` | `number` | `10000` | 等待表单初始化的最长时间(毫秒)。超时将以错误 reject。设为 `<= 0` 时关闭超时兜底 |
|
||||
|
||||
## 返回值
|
||||
|
||||
- `校验通过` — `Promise<any>` resolve 当前表单值(`native` 决定是否克隆);当 `returnChangeRecords` 为 `true` 时,resolve `{ values, changeRecords }`
|
||||
- `校验失败` — `Promise<any>` reject 一个 `Error`,`message` 中包含逐条字段错误信息(格式 `${text} -> ${message}`,多条用 `<br>` 分隔)
|
||||
- `初始化超时` — `Promise<any>` reject `Error('submitForm timeout after ${timeout}ms: form is not initialized.')`
|
||||
|
||||
无论成功或失败,函数都会在最后自动 `unmount` 内部 app 并移除挂载用的 DOM 容器,无需调用方手动清理。
|
||||
|
||||
::: tip 关于 changeRecords
|
||||
`changeRecords` 记录的是表单挂载后发生的字段变更(由各字段的 `change` 事件累积而来)。在 `submitForm` 这种命令式、无用户交互的场景下,通常为空数组;只有在 `extendState` 或字段联动等逻辑中触发了变更时才会有内容。`MForm` 内部的 `submitForm` 在校验通过后会清空变更记录,因此本函数会在调用前先对其做快照再返回。
|
||||
:::
|
||||
|
||||
## 基础用法
|
||||
|
||||
```ts
|
||||
import { submitForm } from '@tmagic/form';
|
||||
|
||||
try {
|
||||
const values = await submitForm({
|
||||
config: [
|
||||
{
|
||||
type: 'text',
|
||||
name: 'username',
|
||||
text: '用户名',
|
||||
rules: [{ required: true, message: '请输入用户名' }],
|
||||
},
|
||||
],
|
||||
initValues: { username: '' },
|
||||
});
|
||||
console.log('提交成功', values);
|
||||
} catch (e) {
|
||||
console.error('校验失败', e);
|
||||
}
|
||||
```
|
||||
|
||||
## 同时获取变更记录(changeRecords)
|
||||
|
||||
设置 `returnChangeRecords: true` 后,resolve 的结果会从单纯的 `values` 变为 `{ values, changeRecords }`:
|
||||
|
||||
```ts
|
||||
import { submitForm } from '@tmagic/form';
|
||||
|
||||
const { values, changeRecords } = await submitForm({
|
||||
config: [{ type: 'text', name: 'username', text: '用户名' }],
|
||||
initValues: { username: 'foo' },
|
||||
returnChangeRecords: true,
|
||||
});
|
||||
|
||||
console.log(values); // { username: 'foo' }
|
||||
console.log(changeRecords); // ChangeRecord[]
|
||||
```
|
||||
|
||||
## 在组件中继承父级应用上下文
|
||||
|
||||
`MForm` 内部使用 `@tmagic/design` 的组件(背后可能是 `element-plus` 或 `tdesign`),需要宿主应用先完成相应的 `app.use(...)` 安装。在 `submitForm` 这种脱离常规组件树的命令式调用中,可通过 `appContext` 把父级应用上下文带过去:
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { getCurrentInstance } from 'vue';
|
||||
|
||||
import { submitForm } from '@tmagic/form';
|
||||
|
||||
const { appContext } = getCurrentInstance()!;
|
||||
|
||||
const onClick = async () => {
|
||||
const values = await submitForm({
|
||||
config: [{ type: 'text', name: 'text', text: '文本' }],
|
||||
initValues: { text: 'hello' },
|
||||
appContext,
|
||||
});
|
||||
console.log(values);
|
||||
};
|
||||
</script>
|
||||
```
|
||||
|
||||
也可以在初始化 app 时把上下文缓存下来,再在任意位置复用:
|
||||
|
||||
```ts
|
||||
import { createApp } from 'vue';
|
||||
import ElementPlus from 'element-plus';
|
||||
import MagicForm, { type SubmitFormOptions, submitForm as rawSubmitForm } from '@tmagic/form';
|
||||
|
||||
import App from './App.vue';
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(ElementPlus);
|
||||
app.use(MagicForm);
|
||||
app.mount('#app');
|
||||
|
||||
export const submitForm = (options: Omit<SubmitFormOptions, 'appContext'>) =>
|
||||
rawSubmitForm({ ...options, appContext: app._context });
|
||||
```
|
||||
|
||||
## 处理校验错误
|
||||
|
||||
校验失败时 reject 的 `Error.message` 已经把出错字段拼好,可以直接展示到用户:
|
||||
|
||||
```ts
|
||||
import { tMagicMessage } from '@tmagic/design';
|
||||
|
||||
try {
|
||||
const values = await submitForm({ config, initValues });
|
||||
await save(values);
|
||||
} catch (e: any) {
|
||||
tMagicMessage.error({
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: e.message,
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## 运行环境
|
||||
|
||||
`submitForm` 内部依赖 `document` / `window` 来挂载临时 Vue 实例,因此**只能在浏览器或具备 DOM 环境的运行时中使用**。
|
||||
|
||||
| 环境 | 是否可用 | 说明 |
|
||||
| ----------------------------------------------- | -------- | --------------------------------------------------------------------------------- |
|
||||
| 浏览器 / Electron 渲染进程 / 浏览器扩展 | ✅ | 直接可用 |
|
||||
| Vitest / Jest + `happy-dom` / `jsdom` | ✅ | 项目自身的单测就跑在这种环境下 |
|
||||
| 纯 Node.js / Bun / Deno(无 DOM polyfill) | ❌ | 模块顶层就会读 `document`,会抛 `document is not defined` |
|
||||
| Node.js + 手动注入 `happy-dom` / `jsdom` | ⚠️ | 可用,需要在 import `@tmagic/form` **之前**完成全局变量注入;校验行为不一定与浏览器完全一致 |
|
||||
|
||||
### 在 Node.js 中使用(需要先准备 DOM)
|
||||
|
||||
下面是一个在 Node 脚本里调用 `submitForm` 的完整例子,使用 [`happy-dom`](https://github.com/capricorn86/happy-dom) 作为 DOM polyfill:
|
||||
|
||||
```ts
|
||||
// scripts/check-form.ts
|
||||
import { Window } from 'happy-dom';
|
||||
|
||||
const window = new Window();
|
||||
Object.assign(globalThis, {
|
||||
window,
|
||||
document: window.document,
|
||||
navigator: window.navigator,
|
||||
HTMLElement: window.HTMLElement,
|
||||
});
|
||||
|
||||
// 注意:DOM polyfill 必须先注入到 globalThis,再用动态 import
|
||||
// 加载业务模块,否则 @tmagic/design 等模块顶层执行时就会读 document
|
||||
const { createApp } = await import('vue');
|
||||
const ElementPlus = (await import('element-plus')).default;
|
||||
const MagicForm = (await import('@tmagic/form')).default;
|
||||
const { submitForm } = await import('@tmagic/form');
|
||||
|
||||
const parentApp = createApp({ render: () => null });
|
||||
parentApp.use(ElementPlus);
|
||||
parentApp.use(MagicForm);
|
||||
|
||||
const values = await submitForm({
|
||||
config: [{ type: 'text', name: 'username', text: '用户名' }],
|
||||
initValues: { username: 'foo' },
|
||||
appContext: parentApp._context,
|
||||
});
|
||||
|
||||
console.log(values);
|
||||
```
|
||||
|
||||
::: warning 注意
|
||||
- DOM polyfill 必须在 **import 业务模块之前** 注入到 `globalThis`,否则模块顶层执行时仍会失败
|
||||
- 在 `happy-dom` / `jsdom` 中,`element-plus` 的部分 `validate()` 行为不一定能 1:1 复现真实浏览器(例如某些场景下必填规则可能不触发),建议关键校验使用自定义 `validator` 函数确保稳定
|
||||
- 如果只是想在 Node 端做一次纯校验,更稳妥的做法是直接复用 [`async-validator`](https://github.com/yiminghe/async-validator)(element-plus 内部用的就是它),绕开整个 Vue 渲染层
|
||||
:::
|
||||
|
||||
## 类型定义
|
||||
|
||||
::: details 查看 `SubmitFormOptions` 类型定义
|
||||
<<< @/../packages/form/src/submitForm.ts#SubmitFormOptions{ts}
|
||||
:::
|
||||
|
||||
::: details 查看 `SubmitFormResult` 类型定义
|
||||
<<< @/../packages/form/src/submitForm.ts#SubmitFormResult{ts}
|
||||
:::
|
||||
@ -1,7 +1,30 @@
|
||||
# 表单对比
|
||||
tmagic-form可以支持两个版本的表单值对比,如果有容器嵌套,将在tab标签页展示对应tab下存在的差异数,便于在复杂嵌套表单场景下直观的看到差异情况
|
||||
|
||||
## 使用方法
|
||||
在初始化表单时,需要传入当前版本的表单值,上一版本的表单值,以及表单配置,具体可参见[Form Playground](https://tencent.github.io/tmagic-editor/playground/index.html#/form)的demo演示
|
||||
在初始化表单时,开启对比模式 `is-compare`,并传入当前版本的表单值(`init-values`)、上一版本的表单值(`last-values`)以及表单配置,具体可参见[Form Playground](https://tencent.github.io/tmagic-editor/playground/index.html#/form)的demo演示。
|
||||
|
||||
```html
|
||||
<m-form
|
||||
:config="config"
|
||||
:is-compare="true"
|
||||
:init-values="curValues"
|
||||
:last-values="lastValues"
|
||||
></m-form>
|
||||
```
|
||||
|
||||
相关属性详见 Form 组件 props:
|
||||
|
||||
- [`isCompare`](/api/form/form-props.html#iscompare):是否开启对比模式;
|
||||
- [`lastValues`](/api/form/form-props.html#lastvalues):需对比的上一版本表单值;
|
||||
- [`showDiff`](/api/form/form-props.html#showdiff):自定义「是否展示对比内容」的判断函数,用于规避语义相等但结构不同导致的误判。
|
||||
|
||||
## 对比模式下的字段行为
|
||||
对比模式下,表单仅做只读展示:增删、复制、排序、导入、编辑等写操作按钮会被隐藏。对于由列表或嵌套子表单组成的复合字段(如 `event-select`、`code-select`、`code-select-col`),表单会按索引对齐前后值,逐项展示新增 / 删除 / 修改的高亮差异,而不会渲染出两套独立组件。
|
||||
|
||||
## 应用场景
|
||||
编辑器的[历史记录面板](/guide/advanced/history-list.md)即基于该能力,对历史步骤的前后值做表单形式的差异对比。
|
||||
|
||||
## 效果展示
|
||||
<img src="https://vip.image.video.qpic.cn/vupload/20230301/c626071677661813135.png" alt="表单对比"/>
|
||||
|
||||
|
||||
@ -33,7 +33,29 @@
|
||||
| ----------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| formTitle | 弹窗标题 | string | — | — |
|
||||
| codeOptions | 代码编辑器配置项 | object | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CodeLinkConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#CodeLinkConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -33,6 +33,28 @@
|
||||
| ----------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| notEditable | 是否不可编辑代码块(disable控制是否可选择) | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| notEditable | 是否不可编辑代码块(disable控制是否可选择) | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CodeSelectColConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#CodeSelectColConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -30,6 +30,28 @@ CodeSelect 组件支持:
|
||||
| --------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| className | 自定义类名 | string | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CodeSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#CodeSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -47,14 +47,36 @@
|
||||
| ------------- | -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| language | 代码语言 | string | javascript/typescript/json等 | — |
|
||||
| height | 编辑器高度 | string | — | — |
|
||||
| parse | 是否解析代码 | boolean | — | false |
|
||||
| options | 编辑器配置项 | object | — | — |
|
||||
| autosize | 自动调整大小配置 | object | — | — |
|
||||
| mFormItemType | 传入代码编辑器的自定义类型 | string | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CodeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#CodeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## autosize Attributes
|
||||
|
||||
|
||||
@ -33,6 +33,28 @@
|
||||
| ------------ | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| parentFields | 父级字段 | string[] | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CondOpSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#CondOpSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -55,13 +55,35 @@
|
||||
| ------------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| value | 返回值类型 | string | key/value | — |
|
||||
| checkStrictly | 是否严格遵守父子节点不互相关联 | boolean / Function | — | — |
|
||||
| dataSourceFieldType | 允许选择的字段类型 | DataSourceFieldType[] | — | — |
|
||||
| fieldConfig | 自定义字段配置 | ChildConfig | — | — |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceFieldSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceFieldSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## value说明
|
||||
|
||||
|
||||
@ -22,5 +22,27 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceFieldsConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceFieldsConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -22,5 +22,27 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceInputConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceInputConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -33,6 +33,28 @@
|
||||
| ----------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceMethodSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceMethodSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -22,5 +22,27 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceMethodsConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceMethodsConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -22,5 +22,27 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceMocksConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceMocksConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -45,11 +45,35 @@
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| dataSourceType | 数据源类型过滤 | string | base/http等 | — |
|
||||
| value | 返回值类型 | string | id/value | — |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| notEditable | 是否不可编辑数据源(disable控制是否可选择) | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DataSourceSelect 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DataSourceSelect{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
## value说明
|
||||
|
||||
|
||||
@ -33,7 +33,29 @@
|
||||
| ------------ | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| titlePrefix | 标题前缀 | string | — | — |
|
||||
| parentFields | 父级字段 | string[] / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| parentFields | 父级字段 | string[] / `FilterFunction` | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DisplayCondsConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#DisplayCondsConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
| ---------------------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| src | 事件来源 | string | datasource/component | — |
|
||||
| labelWidth | 标签宽度 | string | — | — |
|
||||
| eventNameConfig | 事件名称表单配置 | FormItem | — | — |
|
||||
@ -43,7 +43,29 @@
|
||||
| compActionConfig | 联动组件动作配置 | FormItem | — | — |
|
||||
| codeActionConfig | 联动代码配置 | FormItem | — | — |
|
||||
| dataSourceActionConfig | 联动数据源配置 | FormItem | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 EventSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#EventSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## src说明
|
||||
|
||||
|
||||
@ -35,6 +35,28 @@
|
||||
| -------- | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| advanced | 是否支持高级模式(代码编辑) | boolean | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 KeyValueConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#KeyValueConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -22,8 +22,30 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 PageFragmentSelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#PageFragmentSelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## 使用说明
|
||||
|
||||
|
||||
@ -22,8 +22,30 @@
|
||||
| -------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 UISelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/editor.ts#UISelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## 使用说明
|
||||
|
||||
|
||||
@ -423,16 +423,40 @@ options 支持传入函数,可根据表单其他字段动态生成选项列表
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| multiple | 是否多选 | boolean | — | false |
|
||||
| emitPath | 在选中节点改变时,是否返回由该节点所在的各级菜单的值所组成的数组,若设置 false,则只返回该节点的值 | boolean | — | true |
|
||||
| checkStrictly | 是否严格的遵守父子节点不互相关联 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | false |
|
||||
| valueSeparator | 合并成字符串时的分隔符 | string / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| checkStrictly | 是否严格的遵守父子节点不互相关联 | boolean / `FilterFunction` | — | false |
|
||||
| valueSeparator | 合并成字符串时的分隔符 | string / `FilterFunction` | — | — |
|
||||
| popperClass | 弹出内容的自定义类名 | string | — | — |
|
||||
| remote | 是否为远程搜索 | boolean | — | false |
|
||||
| options | 选项数据源 | Array / Function | — | — |
|
||||
| option | 远程选项配置 | Object | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CascaderConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#CascaderConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
## options item
|
||||
|
||||
|
||||
@ -154,12 +154,36 @@ options 支持函数形式,可根据表单状态动态生成选项。
|
||||
|------|------|------|--------|--------|
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| activeValue | 选中时的值 | string / number | — | true(filter 为 'number' 时默认 1) |
|
||||
| inactiveValue | 未选中时的值 | string / number | — | false(filter 为 'number' 时默认 0) |
|
||||
| useLabel | 是否使用外部 label 显示 | boolean | — | false |
|
||||
| filter | 值过滤器 | 'number' / Function | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 CheckboxConfig / CheckboxGroupConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#CheckboxConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#CheckboxGroupConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## CheckboxGroup Attributes
|
||||
|
||||
@ -167,9 +191,9 @@ options 支持函数形式,可根据表单状态动态生成选项。
|
||||
|------|------|------|--------|--------|
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | false |
|
||||
| options | 选项列表 | Array / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| options | 选项列表 | Array / `FilterFunction` | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
## options item
|
||||
|
||||
|
||||
@ -69,9 +69,31 @@
|
||||
|------|------|------|--------|--------|
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| defaultValue | 默认颜色值 | string | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/master/packages/form-schema/src/base.ts) | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 ColorPickConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ColorPickConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## 颜色格式说明
|
||||
|
||||
|
||||
@ -99,10 +99,34 @@
|
||||
| name | 绑定值的字段名 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| format | 显示在输入框中的格式 | string | 见[日期格式](#日期格式) | YYYY/MM/DD |
|
||||
| valueFormat | 绑定值的格式。不指定则绑定值为 Date 对象 | string | 见[日期格式](#日期格式) | YYYY/MM/DD |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DateConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#DateConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
## TypeScript 定义
|
||||
|
||||
|
||||
@ -41,9 +41,31 @@ type为'daterange'
|
||||
| name | 绑定值(数组形式) | string | — | — |
|
||||
| names | 绑定值(拆分为两个字段) | string[] | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| dateFormat | 日期格式 | string | — | YYYY/MM/DD |
|
||||
| timeFormat | 时间格式 | string | — | HH:mm:ss |
|
||||
| valueFormat | 绑定值的格式 | string | — | YYYY/MM/DD HH:mm:ss |
|
||||
| defaultTime | 默认时间 | Date[] | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DaterangeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#DaterangeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -101,8 +101,32 @@
|
||||
| name | 绑定值的字段名 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| format | 显示在输入框中的格式 | string | 见[日期格式](#日期格式) | YYYY/MM/DD HH:mm:ss |
|
||||
| valueFormat | 绑定值的格式 | string | 见[日期格式](#日期格式) | YYYY/MM/DD HH:mm:ss |
|
||||
| defaultTime | 选择日期后的默认时间值 | Date | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | — |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | — |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DateTimeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#DateTimeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -2,16 +2,6 @@
|
||||
|
||||
用于显示,不可编辑
|
||||
|
||||
## TS 定义
|
||||
|
||||
```typescript
|
||||
interface Display extends FormItem {
|
||||
type: "display";
|
||||
}
|
||||
```
|
||||
|
||||
点击查看[FormItem](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90)的定义
|
||||
|
||||
## 基础用法
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
@ -33,3 +23,12 @@ interface Display extends FormItem {
|
||||
| ---- | -------- | ------ | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DisplayConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#DisplayConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -50,3 +50,12 @@
|
||||
| name | 字段名 | string | — |
|
||||
| label | 标签名 | string | — |
|
||||
| defaultValue | 默认值 | any | — |
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 DynamicFieldConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#DynamicFieldConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -2,16 +2,6 @@
|
||||
|
||||
改值体现于最终提交的表单中,用于例如编辑记录的id这种场景中
|
||||
|
||||
## TS 定义
|
||||
|
||||
```typescript
|
||||
interface Hidden extends FormItem {
|
||||
type: "hidden";
|
||||
}
|
||||
```
|
||||
|
||||
点击查看[FormItem](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90)的定义
|
||||
|
||||
## 基础用法
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
@ -30,3 +20,12 @@ interface Hidden extends FormItem {
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||
| ---- | ------ | ------ | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 HiddenConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#HiddenConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -2,28 +2,6 @@
|
||||
|
||||
用于显示,不可编辑
|
||||
|
||||
## TS 定义
|
||||
|
||||
```typescript
|
||||
interface Link extends FormItem {
|
||||
type: "link";
|
||||
href?: string | typeof LinkHrefFunction;
|
||||
css?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
disabledCss?: {
|
||||
[key: string]: string | number;
|
||||
};
|
||||
formTitle?: string;
|
||||
formWidth?: number | string;
|
||||
displayText?: string | typeof LinkDisplayTextFunction;
|
||||
form: FormConfig | typeof LinkFormFunction;
|
||||
fullscreen?: boolean;
|
||||
}
|
||||
```
|
||||
|
||||
点击查看[FormItem](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90)的定义
|
||||
|
||||
## 基础用法
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
@ -63,3 +41,12 @@ interface Link extends FormItem {
|
||||
| ---- | -------- | ------ | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 LinkConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#LinkConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -23,6 +23,28 @@ type为'number-range'
|
||||
| --------- | ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值(数组形式 [min, max]) | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| clearable | 是否可清空 | boolean | — | true |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 NumberRangeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#NumberRangeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -58,9 +58,31 @@ disabled 属性接受一个 Boolean,设置为 true 即可禁用整个组件,
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| min | 设置计数器允许的最小值 | number | — | -Infinity |
|
||||
| max | 设置计数器允许的最大值 | number | — | Infinity |
|
||||
| step | 计数器步长 | number | — | 1 |
|
||||
| tooltip | 输入框提示信息 | string | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 NumberConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#NumberConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -2,23 +2,6 @@
|
||||
|
||||
在一组备选项中进行单选
|
||||
|
||||
## TS 定义
|
||||
|
||||
```typescript
|
||||
interface RadioGroup extends FormItem {
|
||||
type: "radio-group";
|
||||
childType?: "default" | "button";
|
||||
options: {
|
||||
value: any;
|
||||
text?: string;
|
||||
icon?: any;
|
||||
tooltip?: string;
|
||||
}[];
|
||||
}
|
||||
```
|
||||
|
||||
点击查看[FormItem](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90)的定义
|
||||
|
||||
## 基础用法
|
||||
|
||||
由于选项默认可见,不宜过多,若选项过多,建议使用 Select 选择器。
|
||||
@ -68,10 +51,34 @@ interface RadioGroup extends FormItem {
|
||||
| --------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- | ------- |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| childType | 子项展示形式 | string | default / button | default |
|
||||
| options | 选项 | Array | — | - |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler ](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FormItem / FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 RadioGroupConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#RadioGroupConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## options item
|
||||
|
||||
|
||||
@ -188,16 +188,40 @@ app.use(MagicForm, {
|
||||
| name | 绑定值 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| multiple | 是否多选 | boolean | — | false |
|
||||
| valueKey | 作为 value 唯一标识的键名,绑定值为对象类型时必填 | string | — | value |
|
||||
| allowCreate | 是否允许用户创建新条目 | boolean | — | false |
|
||||
| remote | 是否为远程搜索 | boolean | — | false |
|
||||
| group | 是否选择分组 | boolean | — | false |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler ](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
| options | 选项 | Array | — | - |
|
||||
| option | 选项 | Object | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 SelectConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#SelectConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
## options item
|
||||
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||
|
||||
@ -46,6 +46,20 @@
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||||
| -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | ------ |
|
||||
| name | 绑定值 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [Function](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| active-value | switch 打开时的值 | boolean / string / number | — | true |
|
||||
| inactive-value | switch 关闭时的值 | boolean / string / number | — | false |
|
||||
|
||||
::: details 查看 FilterFunction 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 SwitchConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#SwitchConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -119,14 +119,40 @@ Input输入框的type为'text', 是type的默认值,所以可以不配置
|
||||
| name | 绑定值 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| clearable | 是否可清空 | boolean | — | true |
|
||||
| tooltip | 输入时显示内容 | string / [ToolTipConfigType](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90) | — | — |
|
||||
| tooltip | 输入时显示内容 | string / `ToolTipConfigType` | — | — |
|
||||
| trim | 是否去掉首尾空格 | boolean | — | false |
|
||||
| filter | 过滤值 | string / Function | number | - |
|
||||
| prepend | 前置内容 | string | — | - |
|
||||
| append | 后置内容 | string / Object | — | - |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler / ToolTipConfigType 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ToolTipConfigType{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 TextConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#TextConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
## append Attributes
|
||||
|
||||
|
||||
@ -38,8 +38,30 @@
|
||||
| name | 绑定值 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| trim | 是否去掉首尾空格 | boolean | — | false |
|
||||
| filter | 过滤值 | string / Function | number | - |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler ](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 TextareaConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#TextareaConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -38,4 +38,20 @@
|
||||
| name | 绑定值 | string | — | — |
|
||||
| placeholder | 输入框占位文本 | string | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [Function](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L90) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
|
||||
::: details 查看 FilterFunction 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 TimeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#TimeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#Input{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -41,8 +41,30 @@ type为'timerange'
|
||||
| name | 绑定值(数组形式) | string | — | — |
|
||||
| names | 绑定值(拆分为两个字段) | string[] | — | — |
|
||||
| text | 表单标签 | string | — | — |
|
||||
| disabled | 是否禁用 | boolean / [FilterFunction](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L195) | — | false |
|
||||
| disabled | 是否禁用 | boolean / `FilterFunction` | — | false |
|
||||
| format | 显示格式 | string | — | HH:mm:ss |
|
||||
| valueFormat | 绑定值的格式 | string | — | HH:mm:ss |
|
||||
| defaultTime | 默认时间 | Date[] | — | — |
|
||||
| onChange | 值变化时触发的函数 | [OnChangeHandler](https://github.com/Tencent/tmagic-editor/blob/cce8b63fc3618b5b811aa33c703de21c22be8a6a/packages/form-schema/src/base.ts#L30) | — | - |
|
||||
| onChange | 值变化时触发的函数 | `OnChangeHandler` | — | - |
|
||||
|
||||
::: details 查看 FilterFunction / OnChangeHandler 及关联类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#FilterFunction{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandler{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#OnChangeHandlerData{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#ChangeRecord{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormValue{ts}
|
||||
:::
|
||||
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 TimerangeConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#TimerangeConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
@ -1,5 +1,36 @@
|
||||
# 布局
|
||||
|
||||
## 配置类型
|
||||
|
||||
::: details 查看 ContainerCommonConfig / RowConfig / TabConfig / TabPaneConfig / FieldsetConfig / PanelConfig / StepConfig / FlexLayoutConfig / GroupListConfig / TableConfig / TableColumnConfig / TableGroupListCommonConfig 配置类型定义
|
||||
<<< @/../packages/form-schema/src/base.ts#ContainerCommonConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#RowConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#TabConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#TabPaneConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FieldsetConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#PanelConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#StepConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FlexLayoutConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#GroupListConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#TableConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#TableColumnConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#TableGroupListCommonConfig{ts}
|
||||
|
||||
<<< @/../packages/form-schema/src/base.ts#FormItem{ts}
|
||||
|
||||
:::
|
||||
|
||||
## 基础用法
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
@ -104,6 +135,18 @@
|
||||
}]
|
||||
}]"></demo-block>
|
||||
|
||||
`legend` 除了支持字符串,也支持函数,函数返回值作为标题展示,可根据表单数据动态生成:
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
type: 'fieldset',
|
||||
labelWidth: '100px',
|
||||
legend: (mForm, { formValue }) => `当前值:${formValue.text || '空'}`,
|
||||
items: [{
|
||||
name: 'text',
|
||||
text: '配置1',
|
||||
}]
|
||||
}]"></demo-block>
|
||||
|
||||
### panel
|
||||
|
||||
<demo-block type="form" :config="[{
|
||||
|
||||
@ -30,7 +30,7 @@ tmagic-editor的联动,指这两种情况:
|
||||
当然我们也可以通过上述的参数传入,以及其他函数 API 实现更多灵活的表单联动,具体参考[表单 API](../../form-config/relate)。
|
||||
|
||||
## 组件联动
|
||||
tmagic-editor在 @tmagic/core 中,实现了组件的事件绑定/分发机制。在组件渲染时,每个组件在 @tmagic/ui 中经过基础组件渲染时,会被基础组件注入公共方法的实现。如下对按钮配置了**点击使文本隐藏**的联动事件,那么在对应按钮被点击时,将会触发对应绑定文本的隐藏。
|
||||
tmagic-editor在 `@tmagic/core` 中,实现了组件的事件绑定/分发机制。在组件渲染时,每个组件在经过 `@tmagic/vue-container`(vue 端)或 `@tmagic/react-container`(react 端)等基础渲染组件渲染时,会被基础组件注入公共方法的实现。如下对按钮配置了**点击使文本隐藏**的联动事件,那么在对应按钮被点击时,将会触发对应绑定文本的隐藏。
|
||||
|
||||
<img src="https://image.video.qpic.cn/oa_88b7d-10_2117738923_1637238863127559">
|
||||
|
||||
|
||||
134
docs/guide/advanced/history-list.md
Normal file
134
docs/guide/advanced/history-list.md
Normal file
@ -0,0 +1,134 @@
|
||||
# 历史记录面板
|
||||
|
||||
编辑器内置了一个可视化的「历史记录面板」,用于查看与回溯编辑过程中产生的所有操作。相比顶部菜单栏只能「撤销 / 重做」相邻一步,历史记录面板提供了对整条历史栈的全局视角:可以按页面、数据源、代码块分类浏览,点击任意一步直接跳转,查看每一步的前后差异,甚至像 `git revert` 一样单独回滚某一步而不破坏后续操作。
|
||||
|
||||
## 开启面板
|
||||
|
||||
历史记录面板以一个内置菜单项 `'history-list'` 的形式提供,将它加入 [`menu`](/api/editor/props.html#menu) 配置即可在顶部工具栏出现一个时钟图标,点击展开面板:
|
||||
|
||||
```html
|
||||
<template>
|
||||
<m-editor :menu="menu"></m-editor>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const menu = ref({
|
||||
left: [],
|
||||
center: ['delete', 'undo', 'redo', '/', 'history-list'],
|
||||
right: [],
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
## 面板结构
|
||||
|
||||
面板分为三个 tab,分别对应三类可被历史记录追踪的对象,tab 标题后的数字为各自的分组数量:
|
||||
|
||||
| Tab | 内容 | 跳转 API |
|
||||
| --- | --- | --- |
|
||||
| 页面 | 当前活动页面的节点操作历史 | `editorService.gotoPageStep(cursor)` |
|
||||
| 数据源 | 按 `dataSource.id` 分组的数据源变更历史 | `dataSourceService.goto(id, cursor)` |
|
||||
| 代码块 | 按 `codeBlock.id` 分组的代码块变更历史 | `codeBlockService.goto(id, cursor)` |
|
||||
|
||||
### 相邻同目标自动合并
|
||||
|
||||
为了避免「连续微调同一个节点 / 数据源 / 代码块」时产生大量碎片化记录,面板会把**相邻的、针对同一目标的连续 `update`** 自动合并成一个分组:
|
||||
|
||||
- 页面 tab:连续修改同一节点(按节点 id 判定)的多步合并为一组,点击组头部可展开查看每一子步;
|
||||
- 数据源 / 代码块 tab:相邻的连续 `update` 按目标 id 合并;`add` / `remove` 始终独立成组(语义上是一次性事件)。
|
||||
|
||||
> 合并仅作用于展示与交互,不改变底层 undo/redo 栈的真实结构。
|
||||
|
||||
## 交互能力
|
||||
|
||||
每个分组 / 步骤支持以下操作:
|
||||
|
||||
### 1. 点击跳转
|
||||
|
||||
点击任意一条记录,编辑器会跳转到「应用至该步完成」的状态。其本质是把对应栈的游标(cursor)移动到 `step.index + 1`,由 service 层的 undo/redo 链路完成中间步骤的批量正向 / 反向应用。
|
||||
|
||||
### 2. 回到初始状态
|
||||
|
||||
每个 tab 列表底部提供「回到初始状态」入口,等价于把对应栈游标移到 `0`(所有真实步骤全部撤销)。
|
||||
|
||||
### 3. 单步回滚(类 git revert)
|
||||
|
||||
对于历史中间的某一步,可以单独「回滚」它,而保留它之后的所有操作。该行为不会倒带游标,而是把目标步骤的修改**反向应用为一次全新的操作**并压入栈顶,因此不会破坏既有历史结构:
|
||||
|
||||
- 页面:`editorService.revertPageStep(index)`
|
||||
- 数据源:`dataSourceService.revert(id, index)`
|
||||
- 代码块:`codeBlockService.revert(id, index)`
|
||||
|
||||
如果业务侧在执行操作时已通过 `*AndGetHistoryId` 拿到了该条记录的 [uuid](/api/editor/editorServiceMethods.md#历史记录-uuid-与-andgethistoryid),也可以直接按 uuid 回滚(无需再关心 index / id,且 uuid 不会随栈内步骤增删而变化):
|
||||
|
||||
- 页面:`editorService.revertPageStepById(uuid)`
|
||||
- 数据源:`dataSourceService.revertById(uuid)`
|
||||
- 代码块:`codeBlockService.revertById(uuid)`
|
||||
|
||||
### 4. 差异对比
|
||||
|
||||
在前后值都存在的 `update` 步骤上提供「查看差异」入口,点击后弹出差异对话框。对话框支持两个维度的切换:
|
||||
|
||||
- **对比对象**
|
||||
- `与修改前对比`:该步骤修改前 vs 修改后(默认,体现这一步带来的变化);
|
||||
- `与当前对比`:该步骤修改后 vs 编辑器中的最新值(用于确认「这一步之后是否又被改动过」,当前值缺失时禁用)。
|
||||
- **展示形态**
|
||||
- `表单对比`:以属性表单形式逐字段对比,可读性更好(基于 [表单对比](/form-config/compare.md) 能力);
|
||||
- `源码对比`:以 JSON 源码做整体 diff(基于 monaco diff 编辑器),可以看到表单未覆盖到的字段。
|
||||
|
||||
::: tip
|
||||
表单对比依赖 `@tmagic/form` 的对比模式(`isCompare` / `lastValues`)。对于 `event-select`、`code-select`、`code-select-col` 等由列表或嵌套子表单组成的复合字段,表单会逐项展示新增 / 删除 / 修改的高亮差异,并在对比模式下隐藏「添加 / 删除 / 编辑」等写操作按钮,仅保留只读展示。
|
||||
:::
|
||||
|
||||
## 扩展自定义 tab
|
||||
|
||||
内置的三个 tab 之外,业务方可以通过 Editor 的 [`historyListExtraTabs`](/api/editor/props.html#historylistextratabs) 在面板中追加自定义的历史 tab,追加在「页面 / 数据源 / 代码块」之后。适用于某个自定义模块维护自己的操作历史,需要在历史记录面板中独立展示与回滚的场景。
|
||||
|
||||
```html
|
||||
<template>
|
||||
<m-editor :menu="menu" :history-list-extra-tabs="historyListExtraTabs"></m-editor>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { markRaw } from 'vue';
|
||||
|
||||
import MyModuleHistoryTab from './MyModuleHistoryTab.vue';
|
||||
|
||||
const historyListExtraTabs = [
|
||||
{
|
||||
name: 'my-module',
|
||||
// label 支持字符串或函数,函数形式便于展示动态数量
|
||||
label: () => `我的模块 (${getMyModuleHistory().length})`,
|
||||
component: markRaw(MyModuleHistoryTab),
|
||||
props: { foo: 'bar' },
|
||||
listeners: {
|
||||
goto: (cursor) => console.log(cursor),
|
||||
},
|
||||
},
|
||||
];
|
||||
</script>
|
||||
```
|
||||
|
||||
每个扩展 tab 的字段说明:
|
||||
|
||||
| 字段 | 必填 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `name` | 是 | tab 唯一标识,作为内部 `TMagicTabs` 的 `name` |
|
||||
| `label` | 是 | tab 显示文案,支持字符串或返回字符串的函数(便于展示动态数量) |
|
||||
| `component` | 是 | tab 内容区渲染的组件 |
|
||||
| `props` | 否 | 传入内容组件的 props |
|
||||
| `listeners` | 否 | 内容组件的事件监听 |
|
||||
|
||||
> 内容组件内部可自行通过 `useServices()` 拿到 `historyService` 等服务,读取并回滚自定义模块自己维护的历史。
|
||||
|
||||
## 自定义对比判断
|
||||
|
||||
差异对话框中的「表单对比」最终透传到 `MForm`,你可以通过 Editor 顶层注入的 `extendFormState` 让对比表单拿到完整业务上下文,从而让依赖上下文的 `display` / `disabled` 等 `filterFunction` 正常工作。
|
||||
|
||||
若某些字段语义上相等但结构不同(例如 `code-select` 字段中 `''` 与 `{ hookType: 'code', hookData: [] }` 应视为相等),可借助 `@tmagic/form` 的 [`showDiff`](/api/form/form-props.html#showdiff) 自定义判断函数避免被误判为差异。
|
||||
|
||||
## 相关 API
|
||||
|
||||
历史面板的数据均来自 `historyService` 暴露的聚合方法,详见 [historyService 方法](/api/editor/historyServiceMethods.md)。
|
||||
@ -1,5 +1,5 @@
|
||||
# 页面渲染
|
||||
tmagic-editor的页面渲染,是通过在载入编辑器中保存的 DSL 配置,通过 ui 渲染器渲染页面。在容器布局原理里我们提到过,容器和组件在配置中呈树状结构,所以渲染页面的时候,渲染器会递归配置内容,从而渲染出页面所有组件。
|
||||
tmagic-editor的页面渲染,是通过在载入编辑器中保存的 DSL 配置,通过基础渲染组件(vue 下为 `@tmagic/vue-container`,react 下为 `@tmagic/react-container`)渲染页面。在容器布局原理里我们提到过,容器和组件在配置中呈树状结构,所以渲染页面的时候,渲染器会递归配置内容,从而渲染出页面所有组件。
|
||||
|
||||
<img src="https://vfiles.gtimg.cn/vupload/20211009/f4d3031633778551251.png">
|
||||
|
||||
@ -25,7 +25,7 @@ export default {
|
||||
```
|
||||
|
||||
## 组件渲染
|
||||
所有tmagic-editor组件,都通过一个tmagic-editor基础组件来渲染。这个基础组件会识别当前渲染组件的类型。如果当前渲染组件是普通组件(包括ui中提供的基础组件和业务开发的业务组件),则直接渲染;如果当前渲染组件是容器,则回到[容器渲染](#容器渲染)逻辑中。
|
||||
所有tmagic-editor组件,都通过一个tmagic-editor基础组件来渲染。这个基础组件会识别当前渲染组件的类型。如果当前渲染组件是普通组件(包括 `vue-components` / `react-components` 中提供的基础组件和业务开发的业务组件),则直接渲染;如果当前渲染组件是容器,则回到[容器渲染](#容器渲染)逻辑中。
|
||||
|
||||
基础组件的具体形式为:
|
||||
```vue
|
||||
@ -59,6 +59,6 @@ export default defineComponent({
|
||||
```
|
||||
|
||||
## 渲染器示例
|
||||
在tmagic-editor的示例项目中,我们提供了三个版本的 @tmagic/ui。可以参考对应前端框架的渲染器实现。
|
||||
- [vue 渲染器](https://github.com/Tencent/tmagic-editor/blob/master/vue-components/container/src/Container.vue)
|
||||
- [react 渲染器](https://github.com/Tencent/tmagic-editor/blob/master/react-components/container/src/Container.tsx)
|
||||
在tmagic-editor的示例项目中,我们针对 vue 和 react 分别提供了基础渲染组件的实现,可以参考对应前端框架的渲染器实现。
|
||||
- [vue 渲染器(`@tmagic/vue-container`)](https://github.com/Tencent/tmagic-editor/blob/master/vue-components/container/src/Container.vue)
|
||||
- [react 渲染器(`@tmagic/react-container`)](https://github.com/Tencent/tmagic-editor/blob/master/react-components/container/src/Container.tsx)
|
||||
@ -1,23 +0,0 @@
|
||||
# @tmagic/ui
|
||||
在前面[页面渲染](../advanced/page)中提到的 UI 渲染器,就是包含在 @tmagic/ui 中的渲染器组件。
|
||||
|
||||
tmagic-editor的设计是希望发布的页面支持多个前端框架,即各个业务方可以根据自己熟悉的语言来开发组件、发布页面。也可以通过 [实现一个 runtime](../runtime.html) 的方式,来实现一个自己的 @tmagic/ui。
|
||||
|
||||
所以tmagic-editor的设计中,针对每个前端框架,都需要有一个对应的 @tmagic/ui 来承担渲染器职责。同时,也需要一个使用和 @tmagic/ui 相同前端框架的 runtime 用来加载 vue-components 和业务组件,具体 runtime 概念,可以参考[页面发布](../publish)。
|
||||
|
||||
我们以项目代码中提供的 vue 版本的 vue-components 作为示例介绍其中包含的内容(参考 `vue-components/` 目录下的源码)。
|
||||
|
||||
## 渲染器
|
||||
在 vue 中,实现渲染器的具体形式参考[页面渲染](../advanced/page)中描述的[容器渲染](../advanced/page.html#容器渲染)和[组件渲染](../advanced/page.html#组件渲染)。
|
||||
|
||||
## 基础组件
|
||||
在 vue-components 中,我们提供了几个基础组件,可以在项目源码中找到对应内容。
|
||||
|
||||
- page tmagic-editor的页面基础
|
||||
- container tmagic-editor的容器渲染器
|
||||
- Component.vue tmagic-editor的组件渲染器
|
||||
- button/text 基础组件示例
|
||||
|
||||
其中 page/container/Component 是 UI 的基础,是每个框架的 UI 都应该实现的。
|
||||
|
||||
button/text 其实就是一个组件开发的示例,具体组件开发相关规范可以参考[组件开发](../component)。
|
||||
@ -1,6 +1,15 @@
|
||||
# 快速开始
|
||||
|
||||
tmagic-editor的编辑器我们已经封装成一个 npm 包,可以直接安装使用。编辑器是使用 vue3 开发的(仅支持vue3),但使用编辑器的业务(runtime)可以不限框架,可以用 vue2、react 等开发业务组件。
|
||||
tmagic-editor 的编辑器已经封装成 npm 包,可以直接安装使用。编辑器使用 Vue 3 开发(**仅支持 Vue 3**),但承载真实业务的 runtime 不限框架,可以使用 Vue 2、Vue 3、React 等开发业务组件。
|
||||
|
||||
整个项目结构由两部分组成:
|
||||
|
||||
- **admin-client**(编辑器 / 管理端):基于 `@tmagic/editor`,加载 runtime iframe、提供拖拽/属性配置/发布等能力。
|
||||
- **runtime**(运行时):负责解析 DSL 并渲染页面,分为编辑器内嵌的 `playground` 和线上发布使用的 `page` 两个产物。
|
||||
|
||||
> 仓库 [`playground/`](https://github.com/Tencent/tmagic-editor/tree/master/playground) 与 [`runtime/vue/`](https://github.com/Tencent/tmagic-editor/tree/master/runtime/vue) 就是一份完整可运行的最小实践,本节内容均与之对齐,可以对照阅读源码。
|
||||
|
||||
## 使用脚手架创建(推荐)
|
||||
|
||||
::: code-group
|
||||
|
||||
@ -11,220 +20,423 @@ $ npm create tmagic@latest
|
||||
```bash [pnpm]
|
||||
$ pnpm create tmagic
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
按照提示操作可以创建`6`种项目:
|
||||
按照交互式提示,可以创建以下 `6` 种项目:
|
||||
|
||||
* runtime:运行时(DSL渲染)
|
||||
* admin-client:管理端(编辑器)
|
||||
* components:组件库(组件/插件/数据源)
|
||||
* component:组件
|
||||
* data-source:数据源
|
||||
* plugin:插件
|
||||
| 类型 | 说明 |
|
||||
| -------------- | ------------------------------ |
|
||||
| `runtime` | 运行时(DSL 渲染) |
|
||||
| `admin-client` | 管理端(编辑器) |
|
||||
| `components` | 组件库(组件 / 插件 / 数据源) |
|
||||
| `component` | 单个组件 |
|
||||
| `data-source` | 单个数据源 |
|
||||
| `plugin` | 单个插件 |
|
||||
|
||||
至少需要一个runtime与admin-client后,就可以运行起一个最简单的项目了。
|
||||
|
||||
后续还需要新增组件、插件、数据源等,可以继续添加后面几种类型的项目。
|
||||
|
||||
新增好一个组件/插件/数据源后可以到runtime/tmagic.config.ts中配置到packages中
|
||||
最少需要一个 `runtime` 加一个 `admin-client`,就能跑起一个完整的可视化搭建流程。后续可以再陆续创建组件、插件、数据源;新建好后到 `runtime/tmagic.config.ts` 的 `packages` 中注册即可,参考[组件开发](./component.md) 与[页面发布 § @tmagic/cli](./publish.md#tmagic-cli)。
|
||||
|
||||
## 手动安装
|
||||
|
||||
node.js >= 18
|
||||
::: tip 环境要求
|
||||
|
||||
可以通过[Vite](https://cn.vitejs.dev/) 或 [Vue CLI](https://cli.vuejs.org/zh/)快速创建项目。
|
||||
- Node.js `^20.19.0 || >=22.12.0`
|
||||
- 推荐使用 [Vite](https://cn.vitejs.dev/);如果使用 [Vue CLI](https://cli.vuejs.org/zh/) 需要在 `vue.config.js` 中加上 `transpileDependencies: [/@tmagic/]`
|
||||
:::
|
||||
|
||||
> 使用Vue CLI生成的项目需要在vue.config.js中加上配置:transpileDependencies: [/@tmagic/]
|
||||
### 1. 安装编辑器依赖
|
||||
|
||||
`@tmagic/editor` 把内部使用到的 UI 组件抽象到了 `@tmagic/design`,通过 **adapter** 的形式接入具体的 UI 组件库。我们提供了:
|
||||
|
||||
- [`@tmagic/element-plus-adapter`](https://github.com/Tencent/tmagic-editor/tree/master/packages/element-plus-adapter):接入 [Element Plus](https://element-plus.org/)
|
||||
- [`@tmagic/tdesign-vue-next-adapter`](https://github.com/Tencent/tmagic-editor/tree/master/packages/tdesign-vue-next-adapter):接入 [TDesign Vue Next](https://tdesign.tencent.com/vue-next/overview)
|
||||
|
||||
任选其一即可,下面以 Element Plus 为例:
|
||||
|
||||
```bash
|
||||
$ npm install @tmagic/editor -S
|
||||
$ npm install @tmagic/editor @tmagic/core @tmagic/element-plus-adapter element-plus -S
|
||||
```
|
||||
|
||||
由于在实际应用中项目常常会用到例如[element-plus](https://element-plus.org/)、[tdesign-vue-next](https://tdesign.tencent.com/vue-next/overview)等UI组件库。为了能让使用者能够选择不同UI库,[@tmagic/editor](https://github.com/Tencent/tmagic-editor/tree/master/packages/editor)将其中使用到的UI组件封装到[@tmagic/design](https://github.com/Tencent/tmagic-editor/tree/master/packages/design)中,然后通过不同的adapter来指定使用具体的对应的UI库,我们提供了[@tmagic/element-plus-adapter](https://github.com/Tencent/tmagic-editor/tree/master/packages/element-plus-adapter)来支持[element-plus](https://element-plus.org/),所以还需要安装相关的依赖。
|
||||
|
||||
```bash
|
||||
$ npm install @tmagic/element-plus-adapter element-plus -S
|
||||
```
|
||||
|
||||
editor 中还包含了[monaco-editor](https://microsoft.github.io/monaco-editor/),所以还需安装monaco-editor,可以参考 monaco-editor 的[配置指引](https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md)。
|
||||
`@tmagic/editor` 内部使用了 [monaco-editor](https://microsoft.github.io/monaco-editor/) 作为代码编辑器,需要额外安装并按照官方[配置指引](https://github.com/microsoft/monaco-editor/blob/main/docs/integrate-esm.md)注入 worker:
|
||||
|
||||
```bash
|
||||
$ npm install monaco-editor -S
|
||||
```
|
||||
|
||||
## 快速上手
|
||||
### 2. 引入 @tmagic/editor
|
||||
|
||||
## 引入 @tmagic/editor
|
||||
参考 [`playground/src/main.ts`](https://github.com/Tencent/tmagic-editor/blob/master/playground/src/main.ts),在入口文件中按以下顺序完成 Monaco worker、UI 库样式、editor 样式与 adapter 的注入:
|
||||
|
||||
在 main.js 中写入以下内容:
|
||||
```ts
|
||||
import { createApp } from "vue";
|
||||
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
|
||||
import CssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker";
|
||||
import HtmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker";
|
||||
import JsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
|
||||
import TsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker";
|
||||
|
||||
```js
|
||||
import { createApp } from 'vue';
|
||||
import ElementPlus from 'element-plus';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import editorPlugin from "@tmagic/editor";
|
||||
import MagicElementPlusAdapter from "@tmagic/element-plus-adapter";
|
||||
|
||||
import editorPlugin from '@tmagic/editor';
|
||||
import MagicElementPlusAdapter from '@tmagic/element-plus-adapter';
|
||||
import App from "./App.vue";
|
||||
|
||||
import App from './App.vue';
|
||||
import "element-plus/dist/index.css";
|
||||
import "@tmagic/editor/dist/style.css";
|
||||
|
||||
import 'element-plus/dist/index.css';
|
||||
import '@tmagic/editor/dist/style.css';
|
||||
// @ts-ignore
|
||||
globalThis.MonacoEnvironment = {
|
||||
getWorker(_: any, label: string) {
|
||||
if (label === "json") return new JsonWorker();
|
||||
if (["css", "scss", "less"].includes(label)) return new CssWorker();
|
||||
if (["html", "handlebars", "razor"].includes(label))
|
||||
return new HtmlWorker();
|
||||
if (["typescript", "javascript"].includes(label)) return new TsWorker();
|
||||
return new EditorWorker();
|
||||
},
|
||||
};
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(ElementPlus, {
|
||||
locale: zhCn,
|
||||
});
|
||||
app.use(editorPlugin, MagicElementPlusAdapter);
|
||||
app.mount('#app');
|
||||
createApp(App).use(editorPlugin, MagicElementPlusAdapter).mount("#app");
|
||||
```
|
||||
|
||||
以上代码便完成了 @tmagic/editor 的引入。需要注意的是,样式文件需要单独引入。
|
||||
::: tip 切换 UI 适配器
|
||||
playground 通过 `sessionStorage` 来切换 adapter,参考实现:
|
||||
|
||||
可以参考我们提供的[Playground](https://github.com/Tencent/tmagic-editor/blob/master/playground/src/main.ts)示例实现代码
|
||||
```ts
|
||||
const adapter =
|
||||
sessionStorage.getItem("tmagic-playground-ui-adapter") || "element-plus";
|
||||
const adapterModule =
|
||||
adapter === "tdesign-vue-next"
|
||||
? import("@tmagic/tdesign-vue-next-adapter")
|
||||
: import("@tmagic/element-plus-adapter");
|
||||
```
|
||||
|
||||
## 使用 m-editor 组件
|
||||
:::
|
||||
|
||||
在 App.vue 中写入以下内容:
|
||||
::: tip 常见报错
|
||||
|
||||
```html
|
||||
1. `Preprocessor dependency "sass" not found.` —— 安装 sass:`npm i sass -D`
|
||||
2. `Uncaught ReferenceError: global is not defined` —— Vite 项目需要在 `vite.config.ts` 中加上:
|
||||
|
||||
```ts
|
||||
// vite 8以下版本
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
define: { global: 'globalThis' },
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
```ts
|
||||
// vite 8及以上
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
### 3. 渲染 m-editor
|
||||
|
||||
在 `App.vue` 中渲染 `<TMagicEditor />`(即 `m-editor` 组件),最少需要传入 `v-model`、`runtime-url`、`component-group-list`、`props-configs`、`props-values` 五个核心属性:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<m-editor
|
||||
v-model="dsl"
|
||||
:menu="menu"
|
||||
:runtime-url="runtimeUrl"
|
||||
:props-configs="propsConfigs"
|
||||
:props-values="propsValues"
|
||||
:component-group-list="componentGroupList"
|
||||
>
|
||||
</m-editor>
|
||||
<div class="editor-app">
|
||||
<TMagicEditor
|
||||
v-model="value"
|
||||
ref="editor"
|
||||
:menu="menu"
|
||||
:runtime-url="runtimeUrl"
|
||||
:props-configs="propsConfigs"
|
||||
:props-values="propsValues"
|
||||
:event-method-list="eventMethodList"
|
||||
:datasource-configs="datasourceConfigs"
|
||||
:datasource-values="datasourceValues"
|
||||
:datasource-event-method-list="datasourceEventMethodList"
|
||||
:component-group-list="componentGroupList"
|
||||
:default-selected="defaultSelected"
|
||||
:stage-rect="stageRect"
|
||||
:auto-scroll-into-view="true"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, ref } from "vue";
|
||||
<script lang="ts" setup>
|
||||
import { ref, shallowRef } from "vue";
|
||||
import type { MApp } from "@tmagic/core";
|
||||
import { TMagicEditor } from "@tmagic/editor";
|
||||
|
||||
export default defineComponent({
|
||||
name: "App",
|
||||
import componentGroupList from "./configs/componentGroupList";
|
||||
import dsl from "./configs/dsl";
|
||||
import { useEditorRes } from "./composables/use-editor-res";
|
||||
|
||||
setup() {
|
||||
return {
|
||||
menu: ref({
|
||||
left: [
|
||||
// 顶部左侧菜单按钮
|
||||
],
|
||||
center: [
|
||||
// 顶部中间菜单按钮
|
||||
],
|
||||
right: [
|
||||
// 顶部右侧菜单按钮
|
||||
],
|
||||
}),
|
||||
const editor = shallowRef<InstanceType<typeof TMagicEditor>>();
|
||||
const value = ref<MApp>(dsl);
|
||||
const defaultSelected = ref(dsl.items[0].id);
|
||||
const stageRect = ref({ width: 375, height: 817 });
|
||||
|
||||
dsl: ref({
|
||||
// 初始化页面数据
|
||||
}),
|
||||
const { VITE_RUNTIME_PATH } = import.meta.env;
|
||||
const runtimeUrl = `${VITE_RUNTIME_PATH}/playground/index.html`;
|
||||
|
||||
runtimeUrl: "/runtime/vue/playground/index.html",
|
||||
const {
|
||||
propsValues,
|
||||
propsConfigs,
|
||||
eventMethodList,
|
||||
datasourceConfigs,
|
||||
datasourceValues,
|
||||
datasourceEventMethodList,
|
||||
} = useEditorRes();
|
||||
|
||||
propsConfigs: [
|
||||
// 组件属性列表
|
||||
],
|
||||
propsValues: [
|
||||
// 组件默认值
|
||||
],
|
||||
|
||||
componentGroupList: ref([
|
||||
// 组件列表
|
||||
]),
|
||||
};
|
||||
const menu = {
|
||||
left: [{ type: "text", text: "魔方" }],
|
||||
center: ["delete", "undo", "redo", "guides", "rule", "zoom"],
|
||||
right: [
|
||||
{
|
||||
type: "button",
|
||||
text: "保存",
|
||||
handler: () =>
|
||||
localStorage.setItem("magicDSL", JSON.stringify(value.value)),
|
||||
},
|
||||
});
|
||||
],
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.m-editor {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.editor-app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.editor-app .m-editor {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
关于 [@tmagic/editor](https://github.com/Tencent/tmagic-editor/tree/master/packages/editor) 组件,更多的属性配置详情请参考[编辑器 API](../api/editor/props.md)。
|
||||
完整的菜单/预览/键盘快捷键实现可以参考 [`playground/src/pages/Editor.vue`](https://github.com/Tencent/tmagic-editor/blob/master/playground/src/pages/Editor.vue)。
|
||||
|
||||
其中,**有四个需要注意的属性配置项**:`runtimeUrl` `propsValues` `propsConfigs` `componentGroupList`。这是能让我们的编辑器正常运行的关键。
|
||||
更多 prop 详见[编辑器 API](../api/editor/props.md),下文重点介绍最关键的 4 个:`runtimeUrl`、`componentGroupList`、`propsConfigs/propsValues`、初始 DSL(`v-model`)。
|
||||
|
||||
:::tip
|
||||
如果出现```Preprocessor dependency "sass" not found. Did you install it?```,那么需要install sass
|
||||
## runtimeUrl
|
||||
|
||||
```bash
|
||||
npm install sass -D
|
||||
```
|
||||
:::
|
||||
编辑器中央的模拟器画布是一个 `iframe`,`runtimeUrl` 就是这个 iframe 加载的地址,里面运行着一份 **playground runtime**,负责响应编辑器中组件的增删改查。
|
||||
|
||||
:::tip
|
||||
如果是使用vite构建工具,如果出现 ```Uncaught ReferenceError: global is not defined```,那么需要再vite.config.js中添加如下配置:
|
||||
playground 中通过 Vite proxy 把 runtime 服务(默认端口 `8078`)代理到了同一个域:
|
||||
|
||||
```js
|
||||
{
|
||||
optimizeDeps: {
|
||||
esbuildOptions: {
|
||||
define: {
|
||||
global: 'globalThis',
|
||||
},
|
||||
```ts
|
||||
server: {
|
||||
port: 8098,
|
||||
proxy: {
|
||||
'^/tmagic-editor/playground/runtime': {
|
||||
target: 'http://127.0.0.1:8078',
|
||||
changeOrigin: true,
|
||||
prependPath: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
:::
|
||||
|
||||
## runtimeUrl
|
||||
|
||||
该配置涉及到 [runtime 概念](runtime.md),tmagic-editor编辑器中心的模拟器画布,是一个 iframe(这里的 `runtimeUrl` 配置的,就是你提供的 iframe 的 url),其中渲染了一个 runtime,用来响应编辑器中的组件增删改等操作。
|
||||
:::tip
|
||||
可以使用`npm create tmagic` 来快速创建一个runtime项目。
|
||||
:::
|
||||
实际项目中可以使用 `npm create tmagic` 快速生成一个 runtime 项目,详见[RUNTIME](./runtime.md)。
|
||||
|
||||
## componentGroupList
|
||||
|
||||
`componentGroupList` 是指定左侧组件库内容的配置。此处定义了在编辑器组件库中有什么组件。在添加的时候通过组件 `type` 来确定 runtime 中要渲染什么组件。可以参考 [componentGroupList 配置](../api/editor/props.html#componentgrouplist)。
|
||||
`componentGroupList` 决定左侧组件库展示哪些组件分组。每个 item 通过 `type` 与 runtime 中注册的组件类型一一对应,添加到画布时编辑器会基于 `type` 通知 runtime 渲染对应组件。
|
||||
|
||||
## propsConfigs/propsValues
|
||||
```ts
|
||||
import {
|
||||
Files,
|
||||
FolderOpened,
|
||||
PictureFilled,
|
||||
SwitchButton,
|
||||
Tickets,
|
||||
} from "@element-plus/icons-vue";
|
||||
import type { ComponentGroup } from "@tmagic/editor";
|
||||
|
||||
`propsConfigs` `propsValues` 和 `componentGroupList` 中声明的组件是一一对应的,通过 `type` 来识别属于哪个组件,该配置涉及的内容,就是组件的表单配置描述,在[组件开发中](./component.md)会通过 formConfig 配置来声明这份内容。
|
||||
|
||||
`configs` 既可以通过 hardcode 方式写上每个组件的表单配置,也可以通过组件打包方式得到对应内容,然后通过异步加载来载入。比如:
|
||||
|
||||
```javascript
|
||||
setup() {
|
||||
asyncLoadJs(`/runtime/vue/assets/config.js`).then(() => {
|
||||
propsConfigs.value = window.magicPresetConfigs;
|
||||
});
|
||||
asyncLoadJs(`/runtime/vue/assets/value.js`).then(() => {
|
||||
propsValues.value = window.magicPresetValues;
|
||||
});
|
||||
}
|
||||
export default [
|
||||
{
|
||||
title: "示例容器",
|
||||
items: [
|
||||
{ icon: FolderOpened, text: "组", type: "container" },
|
||||
{ icon: FolderOpened, text: "蒙层", type: "overlay" },
|
||||
{ icon: Files, text: "迭代器容器", type: "iterator-container" },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "示例组件",
|
||||
items: [
|
||||
{ icon: Tickets, text: "文本", type: "text" },
|
||||
{ icon: SwitchButton, text: "按钮", type: "button" },
|
||||
{ icon: PictureFilled, text: "图片", type: "img" },
|
||||
],
|
||||
},
|
||||
// 也可以提供完整 schema 作为「组合」,添加时直接落入完整子树
|
||||
{
|
||||
title: "组合",
|
||||
items: [
|
||||
{
|
||||
icon: Tickets,
|
||||
text: "弹窗",
|
||||
data: {
|
||||
type: "overlay",
|
||||
name: "弹窗",
|
||||
style: {
|
||||
position: "fixed",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
top: 0,
|
||||
left: 0,
|
||||
},
|
||||
items: [
|
||||
/* ... */
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] as ComponentGroup[];
|
||||
```
|
||||
|
||||
::: tip 如何快速得到一个 configs/values
|
||||
上述的 runtime 产物中,dist 目录中即包含一个 entry 文件夹,在你的项目组件初始化之后,分别异步加载里面的config/index.umd.js、value/index.umd.js。并如上面代码中,赋值给 configs/values 即可。
|
||||
完整字段参考 [`componentGroupList`](../api/editor/props.md#componentgrouplist)。
|
||||
|
||||
## propsConfigs / propsValues
|
||||
|
||||
`propsConfigs` `propsValues` 与 `componentGroupList` 中声明的组件通过 `type` 一一对应:
|
||||
|
||||
- `propsConfigs[type]`:组件**右侧表单**的配置描述(在组件中 `formConfig` 字段提供)。
|
||||
- `propsValues[type]`:组件被添加到画布时的**初始默认值**(在组件中 `initValue` 字段提供)。
|
||||
|
||||
这些内容会通过 `@tmagic/cli` 在 runtime 构建时打包出对应的 UMD 文件,编辑器异步加载即可。playground 中的真实做法([`use-editor-res.ts`](https://github.com/Tencent/tmagic-editor/blob/master/playground/src/pages/composables/use-editor-res.ts)):
|
||||
|
||||
```ts
|
||||
import { ref } from "vue";
|
||||
import { asyncLoadJs } from "@tmagic/editor";
|
||||
|
||||
const { VITE_ENTRY_PATH } = import.meta.env;
|
||||
|
||||
export const useEditorRes = () => {
|
||||
const propsValues = ref<Record<string, any>>({});
|
||||
const propsConfigs = ref<Record<string, any>>({});
|
||||
const eventMethodList = ref<Record<string, any>>({});
|
||||
const datasourceConfigs = ref<Record<string, any>>({});
|
||||
const datasourceValues = ref<Record<string, any>>({});
|
||||
const datasourceEventMethodList = ref<Record<string, any>>({
|
||||
base: { events: [], methods: [] },
|
||||
});
|
||||
|
||||
asyncLoadJs(`${VITE_ENTRY_PATH}/config/index.umd.cjs`).then(() => {
|
||||
propsConfigs.value = (globalThis as any).magicPresetConfigs;
|
||||
});
|
||||
asyncLoadJs(`${VITE_ENTRY_PATH}/value/index.umd.cjs`).then(() => {
|
||||
propsValues.value = (globalThis as any).magicPresetValues;
|
||||
});
|
||||
asyncLoadJs(`${VITE_ENTRY_PATH}/event/index.umd.cjs`).then(() => {
|
||||
eventMethodList.value = (globalThis as any).magicPresetEvents;
|
||||
});
|
||||
asyncLoadJs(`${VITE_ENTRY_PATH}/ds-config/index.umd.cjs`).then(() => {
|
||||
datasourceConfigs.value = (globalThis as any).magicPresetDsConfigs;
|
||||
});
|
||||
asyncLoadJs(`${VITE_ENTRY_PATH}/ds-value/index.umd.cjs`).then(() => {
|
||||
datasourceValues.value = (globalThis as any).magicPresetDsValues;
|
||||
});
|
||||
|
||||
return {
|
||||
propsValues,
|
||||
propsConfigs,
|
||||
eventMethodList,
|
||||
datasourceConfigs,
|
||||
datasourceValues,
|
||||
datasourceEventMethodList,
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
::: tip 怎样得到这些 UMD 文件?
|
||||
在 runtime 项目中执行 `npm run build:libs`(参考 [`runtime/vue/package.json`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/package.json)),会在 `dist/entry/` 下生成 `config/value/event/ds-config/ds-value` 五个目录的 UMD 文件,全局变量分别为 `magicPresetConfigs` `magicPresetValues` `magicPresetEvents` `magicPresetDsConfigs` `magicPresetDsValues`。
|
||||
:::
|
||||
|
||||
## 更多
|
||||
如果是在调试期,也可以直接 hardcode 一份 `propsConfigs` / `propsValues`,比如:
|
||||
|
||||
通过上述步骤,可以快速得到一个初始化的简单编辑器。
|
||||
```ts
|
||||
const propsConfigs = ref({
|
||||
text: [{ name: "text", text: "文案" }],
|
||||
button: [{ name: "text", text: "按钮文案" }],
|
||||
});
|
||||
|
||||
除了上述内容外,文档的其他章节中,也会更深入的描述整个tmagic-editor的设计理念和实现细节。同时你也可以查看我们的[项目源码](https://github.com/Tencent/tmagic-editor),从源码提供的 playground 和 runtime 示例来开发和理解tmagic-editor。
|
||||
const propsValues = ref({
|
||||
text: { text: "一段文字" },
|
||||
button: { text: "按钮" },
|
||||
});
|
||||
```
|
||||
|
||||
## v-model:DSL 初始值
|
||||
|
||||
`v-model` 绑定的是整个页面的 [DSL](./advanced/js-schema.md),最简的初始 DSL 长这样:
|
||||
|
||||
```ts
|
||||
import { type MApp, NodeType } from "@tmagic/core";
|
||||
|
||||
const dsl: MApp = {
|
||||
id: "1",
|
||||
name: "demo",
|
||||
type: NodeType.ROOT,
|
||||
items: [
|
||||
{
|
||||
type: NodeType.PAGE,
|
||||
id: "page_1",
|
||||
name: "index",
|
||||
layout: "absolute",
|
||||
style: { position: "relative", width: "100%", height: "100%" },
|
||||
items: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
完整含数据源、代码块、事件联动的 DSL 示例见 [`playground/src/configs/dsl.ts`](https://github.com/Tencent/tmagic-editor/blob/master/playground/src/configs/dsl.ts)。
|
||||
|
||||
::: tip 持久化与历史记录
|
||||
playground 用 `localStorage` + `serialize-javascript` 做了一个本地持久化方案,并在保存后调用 `editor.editorService.resetModifiedNodeId()` 重置修改状态,可以直接复用。
|
||||
:::
|
||||
|
||||
## 进阶:编辑器服务与插件
|
||||
|
||||
`@tmagic/editor` 提供了多组 **service**(`editorService` / `propsService` / `historyService` / `uiService` …)和 **插件机制**,可以非侵入式扩展行为。例如 playground 中:
|
||||
|
||||
```ts
|
||||
import { editorService, propsService } from "@tmagic/editor";
|
||||
|
||||
editorService.usePlugin({
|
||||
beforeDoAdd: (config, parent) => {
|
||||
if (config.type === "overlay") {
|
||||
// 蒙层始终插入到当前 page 下,并钉到 (0, 0)
|
||||
config.style = { ...config.style, left: 0, top: 0 };
|
||||
return [config, editorService.get("page")];
|
||||
}
|
||||
return [config, parent];
|
||||
},
|
||||
});
|
||||
|
||||
propsService.usePlugin({
|
||||
beforeFillConfig: (config) => [config, "100px"],
|
||||
});
|
||||
```
|
||||
|
||||
更多扩展能力见[编辑器扩展](./editor-expand.md)与各 service 的 [API 文档](../api/editor/props.md)。
|
||||
|
||||
## 下一步
|
||||
|
||||
- [基础概念](./conception.md):编辑器 / 模拟器 / runtime / DSL 的关系
|
||||
- [RUNTIME](./runtime.md):实现并打包一个 runtime
|
||||
- [组件开发](./component.md):自定义业务组件
|
||||
- [页面发布](./publish.md):基于 `@tmagic/cli` 的产物结构与发布流程
|
||||
- [Playground 源码](https://github.com/Tencent/tmagic-editor/tree/master/playground):与本节示例完全对应
|
||||
|
||||
通过 `pnpm bootstrap && pnpm pg` 即可在仓库本地启动这份 playground,自由调试。
|
||||
|
||||
@ -18,7 +18,7 @@ runtime 的概念,是理解tmagic-editor项目页运行的重要概念,runti
|
||||
各个 runtime 的作用除了作为不同场景下的渲染环境,同时也是不同环境的打包构建载体。tmagic-editor示例代码中的打包就是基于 runtime 进行的。
|
||||
|
||||
### 业务相关
|
||||
由于 runtime 是页面渲染的承载环境,其中会加载 @tmagic/ui 以及各个业务组件,业务发布项目页也是基于 runtime,所以在 runtime 中实现业务方的自定义逻辑是最合适的。runtime 可以提供一些全局 API,供业务组件调用。我们可以把下面的模拟器中的 runtime 视为一个业务方runtime。
|
||||
由于 runtime 是页面渲染的承载环境,其中会加载 `@tmagic/vue-container`(或 `@tmagic/react-container`)等基础渲染组件以及各个业务组件,业务发布项目页也是基于 runtime,所以在 runtime 中实现业务方的自定义逻辑是最合适的。runtime 可以提供一些全局 API,供业务组件调用。我们可以把下面的模拟器中的 runtime 视为一个业务方runtime。
|
||||
|
||||
tmagic-editor提供了三个版本的 runtime 示例,可以参考:
|
||||
- [vue runtime](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue)
|
||||
|
||||
@ -1,29 +1,328 @@
|
||||
# RUNTIME
|
||||
本章详细介绍如何深入理解tmagic-editor的打包,以及如何根据需求定制,修改tmagic-editor的页面打包发布方案。页面发布、打包相关的定制化开发,需要使用tmagic-editor的业务方,搭建好基于开源tmagic-editor的管理平台、存储服务等配套设施。
|
||||
|
||||
本章详细介绍 tmagic-editor 中 runtime 的概念、目录结构与实现方式。所有内容均与开源仓库 [`runtime/vue/`](https://github.com/Tencent/tmagic-editor/tree/master/runtime/vue) 一一对应,可以对照阅读。
|
||||
|
||||
## runtime 是什么
|
||||
|
||||
runtime是用来解析DSL的执行环境,用于渲染 DSL 呈现页面。
|
||||
**runtime 是用来解析 DSL 的执行环境**。编辑器只负责生成 DSL,最终把它**渲染成可见页面**的工作交给 runtime。
|
||||
|
||||
编辑器生成出来的DSL需要通过 runtime 来渲染。
|
||||
在一份完整的 tmagic-editor 项目中,runtime 同时承担两个角色:
|
||||
|
||||
## 实现一个 runtime
|
||||
| 角色 | 入口 | 用途 |
|
||||
| --- | --- | --- |
|
||||
| **page** | `runtime/vue/page/` | 线上发布产物,加载 `window.magicDSL` 渲染真实页面 |
|
||||
| **playground** | `runtime/vue/playground/` | 编辑器中央 iframe 加载的画布,响应增删改并渲染所见即所得 |
|
||||
|
||||
:::tip
|
||||
可以使用`npm create tmagic` 来快速创建一个runtime项目。
|
||||
两者共用同一份组件、插件、数据源代码,只在入口(`main.ts` / `App.vue`)上有差异。
|
||||
|
||||
::: tip
|
||||
DSL、playground 与 editor 之间的通信原理可以前往[教程](/guide/tutorial/)继续了解。
|
||||
:::
|
||||
|
||||
创建出来的项目会包含page、playground两个目录。
|
||||
## 创建 runtime 项目
|
||||
|
||||
::: tip
|
||||
推荐用 `npm create tmagic@latest` / `pnpm create tmagic` 快速生成 runtime 模板,按提示选择 `runtime` 即可。
|
||||
:::
|
||||
|
||||
生成的项目结构如下(与 [`runtime/vue/`](https://github.com/Tencent/tmagic-editor/tree/master/runtime/vue) 完全一致):
|
||||
|
||||
```bash
|
||||
.
|
||||
├── page
|
||||
├── playground
|
||||
runtime/vue
|
||||
├── page/ # 线上 page 入口
|
||||
│ ├── App.vue
|
||||
│ ├── index.html
|
||||
│ ├── main.ts
|
||||
│ └── utils/
|
||||
├── playground/ # 编辑器内 iframe 入口
|
||||
│ ├── App.vue
|
||||
│ ├── index.html
|
||||
│ └── main.ts
|
||||
├── public/
|
||||
├── scripts/ # build 脚本(res / page / playground / all)
|
||||
├── tmagic.config.ts # @tmagic/cli 配置:声明组件、插件、数据源
|
||||
├── tmagic.config.local.ts# 本地覆盖配置(可选)
|
||||
└── vite.config.ts # 多入口构建:page + playground
|
||||
```
|
||||
|
||||
page用于生产环境
|
||||
## tmagic.config.ts:声明组件 / 插件 / 数据源
|
||||
|
||||
playground用于编辑器中
|
||||
`tmagic.config.ts` 是 [@tmagic/cli](./publish.md#tmagic-cli) 的入口,它会扫描 `packages` 列表,生成 `.tmagic/comp-entry.ts` 等 5 个入口文件,runtime 只需要从这些入口里 `import` 即可:
|
||||
|
||||
:::tip
|
||||
想要了解DSL的解析以及runtime与编辑器的通信,可以前往[教程](/guide/tutorial/)
|
||||
```ts
|
||||
import { defineConfig } from '@tmagic/cli';
|
||||
|
||||
export default defineConfig({
|
||||
componentFileAffix: '.vue',
|
||||
// 是否使用 vite + 异步组件,详见 page/main.ts 中的 defineAsyncComponent
|
||||
dynamicImport: true,
|
||||
npmConfig: {
|
||||
client: 'pnpm',
|
||||
keepPackageJsonClean: true,
|
||||
},
|
||||
packages: [
|
||||
{
|
||||
// key 为组件 type,需要与编辑器中 componentGroupList 的 type 对应
|
||||
button: '@tmagic/vue-button',
|
||||
container: '@tmagic/vue-container',
|
||||
img: '@tmagic/vue-img',
|
||||
'iterator-container': '@tmagic/vue-iterator-container',
|
||||
overlay: '@tmagic/vue-overlay',
|
||||
page: '@tmagic/vue-page',
|
||||
'page-fragment': '@tmagic/vue-page-fragment',
|
||||
'page-fragment-container': '@tmagic/vue-page-fragment-container',
|
||||
qrcode: '@tmagic/vue-qrcode',
|
||||
text: '@tmagic/vue-text',
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
`tmagic.config.local.ts` 用于本地覆盖(不会被提交),常见用法是把线上 npm 包临时替换为本地组件目录调试。
|
||||
|
||||
执行 `npm run tmagic`(即 `tmagic entry`)后,runtime 根目录下会生成:
|
||||
|
||||
```bash
|
||||
.tmagic/
|
||||
├── comp-entry.ts # page 同步组件入口
|
||||
├── async-comp-entry.ts # page 异步组件入口(dynamicImport 时使用)
|
||||
├── config-entry.ts # 编辑器右侧表单配置
|
||||
├── value-entry.ts # 组件初始值
|
||||
├── event-entry.ts # 组件事件 / 方法列表
|
||||
├── plugin-entry.ts # 插件入口
|
||||
├── datasource-entry.ts # 同步数据源入口
|
||||
└── async-datasource-entry.ts # 异步数据源入口
|
||||
```
|
||||
|
||||
> 详细产物说明见[页面发布 § @tmagic/cli](./publish.md#tmagic-cli)。
|
||||
|
||||
## playground runtime 实现
|
||||
|
||||
playground 是编辑器中央 iframe 加载的画布,最关键的逻辑就是把编辑器派发的 DSL 变更同步到本地 Vue 状态并触发重新渲染。
|
||||
|
||||
`@tmagic/vue-runtime-help` 提供的 `useEditorDsl` Hook 已经帮我们实现了与编辑器的通信(`onRuntimeReady` / `updateRootConfig` / `updatePageId` / `add` / `update` / `remove` 等);只需要在入口里:
|
||||
|
||||
1. 创建 `TMagicApp` 实例,注册组件、数据源、插件;
|
||||
2. 通过 `provide('app', app)` 把实例注入子组件;
|
||||
3. 在 `App.vue` 里使用 `useEditorDsl()` + `useComponent('page')` 渲染页面。
|
||||
|
||||
完整的 [`runtime/vue/playground/main.ts`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/playground/main.ts):
|
||||
|
||||
```ts
|
||||
import { createApp } from 'vue';
|
||||
import TMagicApp, { DataSourceManager, DeepObservedData } from '@tmagic/core';
|
||||
|
||||
import App from './App.vue';
|
||||
|
||||
import '@tmagic/core/resetcss.css';
|
||||
|
||||
DataSourceManager.registerObservedData(DeepObservedData);
|
||||
|
||||
Promise.all([
|
||||
import('../.tmagic/comp-entry'),
|
||||
import('../.tmagic/plugin-entry'),
|
||||
import('../.tmagic/datasource-entry'),
|
||||
]).then(([components, plugins, dataSources]) => {
|
||||
const vueApp = createApp(App);
|
||||
|
||||
const app = new TMagicApp({
|
||||
ua: window.navigator.userAgent,
|
||||
platform: 'editor',
|
||||
});
|
||||
|
||||
if (app.env.isWeb) {
|
||||
app.setDesignWidth(window.document.documentElement.getBoundingClientRect().width);
|
||||
}
|
||||
|
||||
Object.entries(components.default).forEach(([type, component]: [string, any]) => {
|
||||
app.registerComponent(type, component);
|
||||
});
|
||||
|
||||
Object.entries(dataSources.default).forEach(([type, ds]: [string, any]) => {
|
||||
DataSourceManager.register(type, ds);
|
||||
});
|
||||
|
||||
Object.values(plugins.default).forEach((plugin: any) => {
|
||||
vueApp.use(plugin, { app });
|
||||
});
|
||||
|
||||
window.appInstance = app;
|
||||
vueApp.config.globalProperties.app = app;
|
||||
vueApp.provide('app', app);
|
||||
|
||||
vueApp.mount('#app');
|
||||
});
|
||||
```
|
||||
|
||||
[`playground/App.vue`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/playground/App.vue) 出乎意料地短:
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<component v-if="pageConfig" :is="pageComponent" :key="pageConfig.id" :config="pageConfig"></component>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { useComponent, useEditorDsl } from '@tmagic/vue-runtime-help';
|
||||
|
||||
const { pageConfig } = useEditorDsl();
|
||||
const pageComponent = useComponent('page');
|
||||
</script>
|
||||
```
|
||||
|
||||
::: tip 关键点
|
||||
- `platform: 'editor'` 告知 `@tmagic/core` 进入编辑模式;
|
||||
- `useEditorDsl()` 内部已经调用 `window.magic?.onRuntimeReady({...})`,把 add/update/remove 等回调挂载到全局,编辑器通过 `iframe.contentWindow.magic` 触发;
|
||||
- 当 DSL 变化时,`pageConfig` 自动更新;当页面 DOM 渲染完成,`useEditorDsl` 会调用 `magic.onPageElUpdate(...)` 把页面元素同步给编辑器,让选中框能够吸附。
|
||||
:::
|
||||
|
||||
## page runtime 实现(线上发布)
|
||||
|
||||
[`runtime/vue/page/main.ts`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/page/main.ts) 与 playground 的差别在于:
|
||||
|
||||
1. 不需要响应编辑器消息,直接读取 `window.magicDSL`(或 `localPreview` 模式下从 `localStorage` 读取);
|
||||
2. 使用 `defineAsyncComponent` + 异步入口,按需加载组件,**减小首屏体积**;
|
||||
3. 数据源走 `registerDataSourceOnDemand`,只注册当前 DSL 用到的;
|
||||
4. 注入 `request` 与 `userRender` 等业务侧 API 给组件复用。
|
||||
|
||||
```ts
|
||||
import { createApp, defineAsyncComponent, resolveDirective, withDirectives } from 'vue';
|
||||
|
||||
import TMagicApp, { DataSourceManager, DeepObservedData, getUrlParam, registerDataSourceOnDemand } from '@tmagic/core';
|
||||
|
||||
import components from '../.tmagic/async-comp-entry';
|
||||
import asyncDataSources from '../.tmagic/async-datasource-entry';
|
||||
import plugins from '../.tmagic/plugin-entry';
|
||||
|
||||
import request, { service } from './utils/request';
|
||||
import AppComponent from './App.vue';
|
||||
import { getLocalConfig } from './utils';
|
||||
|
||||
import '@tmagic/core/resetcss.css';
|
||||
|
||||
DataSourceManager.registerObservedData(DeepObservedData);
|
||||
|
||||
const vueApp = createApp(AppComponent);
|
||||
vueApp.use(request);
|
||||
|
||||
const dsl = ((getUrlParam('localPreview') ? getLocalConfig() : window.magicDSL) || [])[0] || {};
|
||||
|
||||
const app = new TMagicApp({
|
||||
ua: window.navigator.userAgent,
|
||||
config: dsl,
|
||||
request: service,
|
||||
curPage: getUrlParam('page'),
|
||||
useMock: Boolean(getUrlParam('useMock')),
|
||||
});
|
||||
|
||||
app.setDesignWidth(app.env.isWeb ? window.document.documentElement.getBoundingClientRect().width : 375);
|
||||
|
||||
Object.entries(components).forEach(([type, component]: [string, any]) => {
|
||||
app.registerComponent(type, defineAsyncComponent(component));
|
||||
});
|
||||
|
||||
Object.values(plugins).forEach((plugin: any) => {
|
||||
vueApp.use(plugin, { app });
|
||||
});
|
||||
|
||||
registerDataSourceOnDemand(dsl, asyncDataSources).then((dataSources) => {
|
||||
Object.entries(dataSources).forEach(([type, ds]: [string, any]) => {
|
||||
DataSourceManager.register(type, ds);
|
||||
});
|
||||
|
||||
vueApp.config.globalProperties.app = app;
|
||||
vueApp.provide('app', app);
|
||||
vueApp.mount('#app');
|
||||
});
|
||||
```
|
||||
|
||||
[`page/App.vue`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/page/App.vue) 用 `useDsl()`(注意不是 `useEditorDsl`):
|
||||
|
||||
```vue
|
||||
<template>
|
||||
<component :is="pageComponent" :config="pageConfig as MPage"></component>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { MPage } from '@tmagic/core';
|
||||
import { useComponent, useDsl } from '@tmagic/vue-runtime-help';
|
||||
|
||||
const { pageConfig, app } = useDsl();
|
||||
const pageComponent = useComponent('page');
|
||||
</script>
|
||||
```
|
||||
|
||||
## vite 多入口构建
|
||||
|
||||
`runtime/vue` 通过单个 vite 工程构建出两份产物([`vite.config.ts`](https://github.com/Tencent/tmagic-editor/blob/master/runtime/vue/vite.config.ts)):
|
||||
|
||||
```ts
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
input: {
|
||||
page: path.resolve(__dirname, './page/index.html'),
|
||||
playground: path.resolve(__dirname, './playground/index.html'),
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
加上 `package.json` 中提供的 build 脚本:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"tmagic": "tmagic entry",
|
||||
"dev": "vite --force",
|
||||
"build": "rimraf ./dist && node scripts/build.mjs --type=all",
|
||||
"build:libs": "node scripts/build.mjs --type=res",
|
||||
"build:page": "node scripts/build.mjs --type=page",
|
||||
"build:playground": "node scripts/build.mjs --type=playground"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
最常用的两个:
|
||||
|
||||
- `npm run build:libs`:构建 **编辑器侧**用到的 `config / value / event / ds-config / ds-value` 五份 UMD 资源(输出到 `dist/entry/`),编辑器通过 `asyncLoadJs` 异步加载(参考[快速开始 § propsConfigs / propsValues](./index.md#propsconfigs-propsvalues))。
|
||||
- `npm run build`:同时产出 `playground/index.html`、`page/index.html` 与 `entry/`,可以一份产物覆盖编辑器、预览、线上三种场景。
|
||||
|
||||
## @tmagic/vue-runtime-help 常用 Hook
|
||||
|
||||
| Hook | 作用 |
|
||||
| --- | --- |
|
||||
| `useEditorDsl()` | playground 入口使用,建立与编辑器通信、维护当前页面 `pageConfig` |
|
||||
| `useDsl()` | page 入口使用,从 `window.magicDSL` 中读取并维护 `pageConfig` |
|
||||
| `useComponent(type)` | 通过组件 type 解析出已注册的 Vue 组件(找不到时会回退到 `magic-ui-${type}`) |
|
||||
| `useApp()` | 取出注入的 `TMagicApp` 实例 |
|
||||
| `useComponentStatus()` | 获取组件在编辑器中的展示/禁用状态 |
|
||||
|
||||
::: tip
|
||||
React runtime 的实现思路完全一致,对应包是 [`@tmagic/react-runtime-help`](https://github.com/Tencent/tmagic-editor/tree/master/runtime/react-runtime-help),可以参照本节自行迁移。
|
||||
:::
|
||||
|
||||
## 跨域
|
||||
|
||||
playground 是被编辑器以 iframe 形式加载的,开发期需要保证 runtime 服务允许跨域。仓库里的做法是用 Vite 的 proxy 把 runtime 反代到 playground 同域:
|
||||
|
||||
```ts
|
||||
// playground/vite.config.ts
|
||||
server: {
|
||||
port: 8098,
|
||||
proxy: {
|
||||
'^/tmagic-editor/playground/runtime': {
|
||||
target: 'http://127.0.0.1:8078',
|
||||
changeOrigin: true,
|
||||
prependPath: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
如果编辑器和 runtime 跨域部署,需要在 runtime 服务侧返回 `Access-Control-Allow-Origin`,并保证 iframe 的 `postMessage` 同源策略允许双方通信。
|
||||
|
||||
## 进一步阅读
|
||||
|
||||
- [基础概念](./conception.md):编辑器、模拟器、runtime 的关系
|
||||
- [组件开发](./component.md):组件四件套(component / form-config / init-value / event)
|
||||
- [页面发布](./publish.md):page.html 注入 DSL 的发布流程
|
||||
- [教程](./tutorial/index.md):从零实现一份 runtime,理解 magic API 与 DSL 解析
|
||||
|
||||
@ -1,12 +1,26 @@
|
||||
# 3.[DSL](../conception.md#dsl) 解析渲染
|
||||
|
||||
tmagic 提供了 vue/react 两个版本的解析渲染组件,可以直接使用
|
||||
tmagic 提供了 vue/react 两个版本的解析渲染组件,可以直接使用。基础渲染组件以 container 为核心,配合 page、button、img、text 等多个独立的 npm 包,分别发布在 `vue-components/` 与 `react-components/` 下:
|
||||
|
||||
[@tmagic/ui](https://www.npmjs.com/package/@tmagic/ui)
|
||||
vue 版本:
|
||||
|
||||
[@tmagic/ui-react](https://www.npmjs.com/package/@tmagic/ui-react)
|
||||
- [@tmagic/vue-container](https://www.npmjs.com/package/@tmagic/vue-container)
|
||||
- [@tmagic/vue-page](https://www.npmjs.com/package/@tmagic/vue-page)
|
||||
- [@tmagic/vue-button](https://www.npmjs.com/package/@tmagic/vue-button)
|
||||
- [@tmagic/vue-img](https://www.npmjs.com/package/@tmagic/vue-img)
|
||||
- [@tmagic/vue-text](https://www.npmjs.com/package/@tmagic/vue-text)
|
||||
- 其他:`@tmagic/vue-overlay`、`@tmagic/vue-qrcode`、`@tmagic/vue-page-fragment`、`@tmagic/vue-page-fragment-container`、`@tmagic/vue-iterator-container`
|
||||
|
||||
接下来是以vue为基础,来讲述如何实现一个[@tmagic/ui](https://www.npmjs.com/package/@tmagic/ui)
|
||||
react 版本:
|
||||
|
||||
- [@tmagic/react-container](https://www.npmjs.com/package/@tmagic/react-container)
|
||||
- [@tmagic/react-page](https://www.npmjs.com/package/@tmagic/react-page)
|
||||
- [@tmagic/react-button](https://www.npmjs.com/package/@tmagic/react-button)
|
||||
- [@tmagic/react-img](https://www.npmjs.com/package/@tmagic/react-img)
|
||||
- [@tmagic/react-text](https://www.npmjs.com/package/@tmagic/react-text)
|
||||
- 其他:`@tmagic/react-overlay`、`@tmagic/react-qrcode`、`@tmagic/react-page-fragment`、`@tmagic/react-page-fragment-container`、`@tmagic/react-iterator-container`
|
||||
|
||||
接下来是以 vue 为基础,来讲述如何实现一个类似 [@tmagic/vue-container](https://www.npmjs.com/package/@tmagic/vue-container) 的渲染器
|
||||
|
||||
## 准备工作
|
||||
|
||||
|
||||
@ -349,6 +349,43 @@ export default {
|
||||
lib: 'always',
|
||||
},
|
||||
],
|
||||
/**
|
||||
* 禁止匿名 default class / default function 导出
|
||||
* @reason 匿名 default 导出在 dts 聚合(rolldown / api-extractor / vue-tsc 等)时会被命名为
|
||||
* `export_default`,导致跨包继承链在 .vue / .tsx 文件下解析失败,
|
||||
* 父类成员(如 EventEmitter 的 on/off)无法被 ts-plugin 推断出来。
|
||||
* 必须使用具名形式:先 `export class Foo {}` 再 `export default Foo;`,
|
||||
* 或 `export default class Foo {}`,确保类型聚合后保留原标识符。
|
||||
*
|
||||
* 注:此处需要重申 base.mjs 中已有的 no-restricted-syntax 选择器
|
||||
* (ForIn / Labeled / With),否则在 .ts/.tsx 下会被本规则整体覆盖。
|
||||
*/
|
||||
'no-restricted-syntax': [
|
||||
'error',
|
||||
{
|
||||
selector: 'ExportDefaultDeclaration > ClassDeclaration[id=null]',
|
||||
message:
|
||||
'禁止匿名 default class 导出。请改为具名形式(如 `export default class Foo extends Bar {}`),否则聚合 dts 会丢失类型信息,导致跨包继承的成员(on/off/emit 等)无法被推断。',
|
||||
},
|
||||
{
|
||||
selector: 'ExportDefaultDeclaration > FunctionDeclaration[id=null]',
|
||||
message:
|
||||
'禁止匿名 default function 导出。请改为具名形式(如 `export default function foo() {}`),便于 dts 聚合保留原标识符与跨包类型推断。',
|
||||
},
|
||||
{
|
||||
selector: 'ForInStatement',
|
||||
message:
|
||||
'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
|
||||
},
|
||||
{
|
||||
selector: 'LabeledStatement',
|
||||
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
|
||||
},
|
||||
{
|
||||
selector: 'WithStatement',
|
||||
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
|
||||
},
|
||||
],
|
||||
/**
|
||||
* 在类型注释周围需要一致的间距
|
||||
*/
|
||||
|
||||
14
package.json
14
package.json
@ -1,9 +1,9 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "tmagic",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"packageManager": "pnpm@10.32.1",
|
||||
"packageManager": "pnpm@10.33.4",
|
||||
"scripts": {
|
||||
"bootstrap": "pnpm i && pnpm build",
|
||||
"clean:top": "rimraf */**/dist */**/types */dist coverage dwt* temp packages/cli/lib",
|
||||
@ -66,18 +66,18 @@
|
||||
"prettier": "^3.8.3",
|
||||
"recast": "^0.23.11",
|
||||
"rimraf": "^3.0.2",
|
||||
"rolldown": "^1.0.0",
|
||||
"rolldown-plugin-dts": "^0.25.0",
|
||||
"rolldown": "^1.0.1",
|
||||
"rolldown-plugin-dts": "^0.25.1",
|
||||
"sass-embedded": "^1.99.0",
|
||||
"semver": "^7.7.3",
|
||||
"serialize-javascript": "^7.0.0",
|
||||
"shx": "^0.3.4",
|
||||
"typescript": "catalog:",
|
||||
"vite": "catalog:",
|
||||
"vitepress": "^1.6.4",
|
||||
"vitest": "^4.1.5",
|
||||
"vitepress": "^2.0.0-alpha.17",
|
||||
"vitest": "^4.1.6",
|
||||
"vue": "catalog:",
|
||||
"vue-tsc": "^3.2.8"
|
||||
"vue-tsc": "^3.2.9"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/cli",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/core",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
|
||||
@ -244,7 +244,7 @@ class App extends EventEmitter {
|
||||
node.data?.id &&
|
||||
node.eventKeys.has(`${String(name)}_${node.data.id}`)
|
||||
) {
|
||||
return this.eventHelper.emit(node.eventKeys.get(`${String(name)}_${node.data.id}`)!, node, ...otherArgs);
|
||||
this.eventHelper.emit(node.eventKeys.get(`${String(name)}_${node.data.id}`)!, node, ...otherArgs);
|
||||
}
|
||||
return super.emit(name, ...args);
|
||||
}
|
||||
|
||||
@ -134,7 +134,9 @@ export const transformStyle = (style: Record<string, any> | string, jsEngine: Js
|
||||
export const COMMON_EVENT_PREFIX = 'magic:common:events:';
|
||||
export const COMMON_METHOD_PREFIX = 'magic:common:actions:';
|
||||
|
||||
// #region EventOption
|
||||
export interface EventOption {
|
||||
label: string;
|
||||
value: string;
|
||||
}
|
||||
// #endregion EventOption
|
||||
|
||||
@ -431,6 +431,58 @@ describe('App 配置/方法/组件注册', () => {
|
||||
expect(typeof result).toBe('boolean');
|
||||
});
|
||||
|
||||
// 回归用例:节点配置了 events 时,eventHelper 派发不能短路掉 super.emit,
|
||||
// 即 app.on(name, cb) 注册的回调依然要被触发。
|
||||
test('emit: 节点已绑定 events 时,app.on 注册的监听器仍然会被调用', () => {
|
||||
const app = new App({
|
||||
config: {
|
||||
type: NodeType.ROOT,
|
||||
id: 'app',
|
||||
items: [
|
||||
{
|
||||
type: NodeType.PAGE,
|
||||
id: 'p1',
|
||||
items: [{ id: 'btn', type: 'button', events: [{ name: 'click', actions: [] }] }],
|
||||
},
|
||||
],
|
||||
} as any,
|
||||
});
|
||||
const node = app.getNode('btn')!;
|
||||
const cb = vi.fn();
|
||||
app.on('click', cb);
|
||||
|
||||
const result = app.emit('click', node, 'arg1');
|
||||
|
||||
expect(cb).toHaveBeenCalledTimes(1);
|
||||
expect(cb).toHaveBeenCalledWith(node, 'arg1');
|
||||
// EventEmitter.emit 在有 listener 时返回 true
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
test('emit: 未命中节点 eventKeys 时,app.on 注册的监听器正常被调用', () => {
|
||||
const app = new App({
|
||||
config: {
|
||||
type: NodeType.ROOT,
|
||||
id: 'app',
|
||||
items: [
|
||||
{
|
||||
type: NodeType.PAGE,
|
||||
id: 'p1',
|
||||
items: [{ id: 'btn', type: 'button' }],
|
||||
},
|
||||
],
|
||||
} as any,
|
||||
});
|
||||
const node = app.getNode('btn')!;
|
||||
const cb = vi.fn();
|
||||
app.on('click', cb);
|
||||
|
||||
app.emit('click', node, 'arg1');
|
||||
|
||||
expect(cb).toHaveBeenCalledTimes(1);
|
||||
expect(cb).toHaveBeenCalledWith(node, 'arg1');
|
||||
});
|
||||
|
||||
test('destroy 清理所有资源', () => {
|
||||
const app = new App({
|
||||
config: {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/data-source",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
|
||||
@ -241,7 +241,7 @@ export const registerDataSourceOnDemand = async (
|
||||
dsl: MApp,
|
||||
dataSourceModules: Record<string, () => Promise<AsyncDataSourceResolveResult>>,
|
||||
) => {
|
||||
const { dataSourceMethodsDeps = {}, dataSourceCondDeps = {}, dataSourceDeps = {}, dataSources = [] } = dsl;
|
||||
const { dataSourceMethodDeps = {}, dataSourceCondDeps = {}, dataSourceDeps = {}, dataSources = [] } = dsl;
|
||||
|
||||
const dsModuleMap: Record<string, () => Promise<AsyncDataSourceResolveResult>> = {};
|
||||
|
||||
@ -253,7 +253,7 @@ export const registerDataSourceOnDemand = async (
|
||||
}
|
||||
|
||||
if (!Object.keys(dep).length) {
|
||||
dep = dataSourceMethodsDeps[ds.id] || {};
|
||||
dep = dataSourceMethodDeps[ds.id] || {};
|
||||
}
|
||||
|
||||
if (Object.keys(dep).length && dataSourceModules[ds.type]) {
|
||||
|
||||
@ -377,7 +377,7 @@ describe('registerDataSourceOnDemand', () => {
|
||||
],
|
||||
dataSourceDeps: { a: { node1: { name: 'n', keys: ['x'] } } },
|
||||
dataSourceCondDeps: { c: { node2: { name: 'n', keys: ['y'] } } },
|
||||
dataSourceMethodsDeps: {},
|
||||
dataSourceMethodDeps: {},
|
||||
};
|
||||
const httpModule = { default: class HttpDS {} };
|
||||
const mockModule = { default: class MockDS {} };
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/dep",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
|
||||
@ -127,10 +127,38 @@ export default class Watcher {
|
||||
deep = false,
|
||||
type?: DepTargetType | string,
|
||||
) {
|
||||
this.collectByCallback(nodes, type, ({ node, target }) => {
|
||||
this.removeTargetDep(target, node);
|
||||
this.collectItem(node, target, depExtendedData, deep);
|
||||
});
|
||||
const targets = this.getCollectableTargets(type);
|
||||
|
||||
if (!targets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 整棵树只遍历一次、在每个属性上检查所有 target,把结构遍历开销从 ×targets 降到 ×1(详见 collectItems)
|
||||
for (const node of nodes) {
|
||||
this.removeTargetsDep(targets, node);
|
||||
this.collectItems(node, targets, depExtendedData, deep);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本次需要参与收集的 target(过滤规则与 collectByCallback 一致)
|
||||
*
|
||||
* 注:供 editor 的 dep service / worker 跨包批量收集时复用,因此为 public。
|
||||
* @param type 强制收集指定类型的依赖
|
||||
*/
|
||||
public getCollectableTargets(type?: DepTargetType | string): Target[] {
|
||||
const targets: Target[] = [];
|
||||
traverseTarget(
|
||||
this.targetsList,
|
||||
(target) => {
|
||||
if (!type && !target.isCollectByDefault) {
|
||||
return;
|
||||
}
|
||||
targets.push(target);
|
||||
},
|
||||
type,
|
||||
);
|
||||
return targets;
|
||||
}
|
||||
|
||||
public collectByCallback(
|
||||
@ -195,53 +223,11 @@ export default class Watcher {
|
||||
this.clear(nodes, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集单个 target 的依赖,等价于 collectItems(node, [target], ...)
|
||||
*/
|
||||
public collectItem(node: TargetNode, target: Target, depExtendedData: DepExtendedData = {}, deep = false) {
|
||||
if (node[NODE_DISABLE_DATA_SOURCE_KEY] && DATA_SOURCE_TARGET_TYPES.has(target.type)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node[NODE_DISABLE_CODE_BLOCK_KEY] && target.type === DepTargetType.CODE_BLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
const collectTarget = (config: Record<string | number, any>, prop = '') => {
|
||||
const doCollect = (key: string, value: any) => {
|
||||
const keyIsItems = key === this.childrenProp;
|
||||
const fullKey = prop ? `${prop}.${key}` : key;
|
||||
|
||||
if (target.isTarget(fullKey, value)) {
|
||||
target.updateDep({
|
||||
id: node[this.idProp],
|
||||
name: `${node[this.nameProp] || node[this.idProp]}`,
|
||||
data: depExtendedData,
|
||||
key: fullKey,
|
||||
});
|
||||
} else if (!keyIsItems && Array.isArray(value)) {
|
||||
for (let i = 0, l = value.length; i < l; i++) {
|
||||
const item = value[i];
|
||||
if (isObject(item)) {
|
||||
collectTarget(item, `${fullKey}[${i}]`);
|
||||
}
|
||||
}
|
||||
} else if (isObject(value)) {
|
||||
collectTarget(value, fullKey);
|
||||
}
|
||||
|
||||
if (keyIsItems && deep && Array.isArray(value)) {
|
||||
for (const child of value) {
|
||||
this.collectItem(child, target, depExtendedData, deep);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
if (typeof value === 'undefined' || value === '') continue;
|
||||
|
||||
doCollect(key, value);
|
||||
}
|
||||
};
|
||||
|
||||
collectTarget(node);
|
||||
this.collectItems(node, [target], depExtendedData, deep);
|
||||
}
|
||||
|
||||
public removeTargetDep(target: Target, node: TargetNode, key?: string | number) {
|
||||
@ -252,4 +238,117 @@ export default class Watcher {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 removeTargetDep 等价,但一次子树递归同时处理多个 target,
|
||||
* 把删除阶段的结构遍历从 ×targets 降到 ×1。
|
||||
*
|
||||
* 注:供 editor 的 dep service 跨包批量删除时复用,因此为 public。
|
||||
*/
|
||||
public removeTargetsDep(targets: Target[], node: TargetNode, key?: string | number) {
|
||||
const id = node[this.idProp];
|
||||
for (const target of targets) {
|
||||
target.removeDep(id, key);
|
||||
}
|
||||
if (typeof key === 'undefined' && Array.isArray(node[this.childrenProp]) && node[this.childrenProp].length) {
|
||||
for (const item of node[this.childrenProp] as TargetNode[]) {
|
||||
this.removeTargetsDep(targets, item, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 与 collectItem 等价,但一次遍历同时处理多个 target(不含删除阶段)。
|
||||
*
|
||||
* 关键优化:原实现对每个 target 都完整遍历一遍节点树(O(targets × 树规模)),大页面 + 大量数据源时,
|
||||
* 结构遍历(Object.entries / 递归 / fullKey 字符串拼接)会被重复 targets 次。这里改为「整棵树只遍历一次,
|
||||
* 在每个属性上检查所有 target」,把结构遍历开销从 ×targets 降到 ×1,isTarget 调用次数不变,收集结果完全一致。
|
||||
*
|
||||
* 注:供 editor 的 dep service / worker 跨包批量收集时复用,因此为 public。
|
||||
*/
|
||||
public collectItems(node: TargetNode, targets: Target[], depExtendedData: DepExtendedData = {}, deep = false) {
|
||||
// 对应 collectItem 开头的 NODE_DISABLE_* 判断:被禁用的 target 在该节点及其子树都不收集
|
||||
const activeTargets = this.filterTargetsByNode(node, targets);
|
||||
|
||||
if (!activeTargets.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.collectTargetForTargets(node, node, '', activeTargets, depExtendedData, deep);
|
||||
}
|
||||
|
||||
private filterTargetsByNode(node: TargetNode, targets: Target[]): Target[] {
|
||||
const disableDataSource = Boolean(node[NODE_DISABLE_DATA_SOURCE_KEY]);
|
||||
const disableCodeBlock = Boolean(node[NODE_DISABLE_CODE_BLOCK_KEY]);
|
||||
|
||||
if (!disableDataSource && !disableCodeBlock) {
|
||||
return targets;
|
||||
}
|
||||
|
||||
return targets.filter((target) => {
|
||||
if (disableDataSource && DATA_SOURCE_TARGET_TYPES.has(target.type)) {
|
||||
return false;
|
||||
}
|
||||
if (disableCodeBlock && target.type === DepTargetType.CODE_BLOCK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private collectTargetForTargets(
|
||||
node: TargetNode,
|
||||
config: Record<string | number, any>,
|
||||
prop: string,
|
||||
targets: Target[],
|
||||
depExtendedData: DepExtendedData,
|
||||
deep: boolean,
|
||||
) {
|
||||
const id = node[this.idProp];
|
||||
const name = `${node[this.nameProp] || node[this.idProp]}`;
|
||||
|
||||
for (const [key, value] of Object.entries(config)) {
|
||||
if (typeof value === 'undefined' || value === '') continue;
|
||||
|
||||
const keyIsItems = key === this.childrenProp;
|
||||
const fullKey = prop ? `${prop}.${key}` : key;
|
||||
|
||||
// 在该属性上检查所有 target:命中的更新依赖;未命中的留待递归到更深层
|
||||
let notMatched: Target[] | null = null;
|
||||
for (let i = 0, l = targets.length; i < l; i++) {
|
||||
const target = targets[i];
|
||||
if (target.isTarget(fullKey, value, config)) {
|
||||
target.updateDep({
|
||||
id,
|
||||
name,
|
||||
data: depExtendedData,
|
||||
key: fullKey,
|
||||
});
|
||||
} else {
|
||||
(notMatched || (notMatched = [])).push(target);
|
||||
}
|
||||
}
|
||||
|
||||
// 对应原 doCollect 的 else-if 分支:仅未命中的 target 才继续往 value 内部递归
|
||||
if (notMatched) {
|
||||
if (!keyIsItems && Array.isArray(value)) {
|
||||
for (let i = 0, l = value.length; i < l; i++) {
|
||||
const item = value[i];
|
||||
if (isObject(item)) {
|
||||
this.collectTargetForTargets(node, item, `${fullKey}[${i}]`, notMatched, depExtendedData, deep);
|
||||
}
|
||||
}
|
||||
} else if (isObject(value)) {
|
||||
this.collectTargetForTargets(node, value, fullKey, notMatched, depExtendedData, deep);
|
||||
}
|
||||
}
|
||||
|
||||
// 对应原 doCollect 末尾的无条件子节点递归
|
||||
if (keyIsItems && deep && Array.isArray(value)) {
|
||||
for (const child of value) {
|
||||
this.collectItems(child, targets, depExtendedData, deep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,7 +15,7 @@ export enum DepTargetType {
|
||||
DATA_SOURCE_COND = 'data-source-cond',
|
||||
}
|
||||
|
||||
export type IsTarget = (key: string | number, value: any) => boolean;
|
||||
export type IsTarget = (key: string | number, value: any, data?: Record<string, any>) => boolean;
|
||||
|
||||
export interface TargetOptions {
|
||||
isTarget: IsTarget;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/design",
|
||||
"type": "module",
|
||||
"sideEffects": [
|
||||
|
||||
@ -43,8 +43,16 @@ const props = withDefaults(defineProps<PopoverProps>(), {
|
||||
visible: undefined,
|
||||
tabindex: 0,
|
||||
destroyOnClose: false,
|
||||
closeOnClickOutside: true,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 受控模式(传入了 visible)下点击外部收起时触发,便于配合 v-model:visible。 */
|
||||
'update:visible': [_visible: boolean];
|
||||
/** 点击 popover 及其衍生浮层以外的区域时触发。 */
|
||||
clickoutside: [_event: MouseEvent];
|
||||
}>();
|
||||
|
||||
const popoverVisible = ref(false);
|
||||
|
||||
const visibleWatch = watch(
|
||||
@ -179,6 +187,70 @@ if (props.trigger === 'hover' && typeof props.visible === 'undefined') {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* popover 内部触发、却挂载到 body(在 popper 之外)的浮层:弹窗、二次确认框、tooltip、
|
||||
* 下拉 / 日期选择等。点击它们属于 popover 内部交互,不应顺带把 popover 关闭。
|
||||
*
|
||||
* 由于 @tmagic/design 通过适配器支持 element-plus、tdesign 等多套 UI 库,这里同时列出
|
||||
* 两套库的浮层 class(class 名互不冲突,未命中的选择器无副作用),避免切换适配器后失效。
|
||||
*/
|
||||
const DEFAULT_CLICK_OUTSIDE_IGNORE = [
|
||||
// @tmagic/design 自身(与适配器无关)
|
||||
'.tmagic-design-dialog',
|
||||
// element-plus
|
||||
'.el-overlay',
|
||||
'.el-message-box',
|
||||
'.el-popper',
|
||||
'.el-select-dropdown',
|
||||
'.el-picker__popper',
|
||||
'.el-dropdown__popper',
|
||||
'.el-cascader__dropdown',
|
||||
// tdesign:弹窗 / 消息确认(DialogPlugin / MessagePlugin)与各类浮层(tooltip / select / dropdown / 日期选择等均挂在 .t-popup 内)
|
||||
'.t-dialog__ctx',
|
||||
'.t-dialog',
|
||||
'.t-message',
|
||||
'.t-popup',
|
||||
].join(',');
|
||||
|
||||
const clickOutsideIgnoreSelector = computed(() =>
|
||||
[DEFAULT_CLICK_OUTSIDE_IGNORE, props.clickOutsideIgnore].filter(Boolean).join(','),
|
||||
);
|
||||
|
||||
const handleClickOutside = (e: MouseEvent) => {
|
||||
if (props.disabled) return;
|
||||
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (!target) return;
|
||||
|
||||
// 点击 reference、popper 自身或衍生浮层时保持打开
|
||||
if (referenceElementRef.value?.contains(target)) return;
|
||||
if (popperElementRef.value?.contains(target)) return;
|
||||
if (target.closest(clickOutsideIgnoreSelector.value)) return;
|
||||
|
||||
emit('clickoutside', e);
|
||||
|
||||
// 非受控:直接收起;受控:通过 update:visible 通知父级(可配合 v-model:visible)
|
||||
if (typeof props.visible === 'undefined') {
|
||||
popoverVisible.value = false;
|
||||
} else {
|
||||
emit('update:visible', false);
|
||||
}
|
||||
};
|
||||
|
||||
const bindClickOutside = () => globalThis.document?.addEventListener('click', handleClickOutside);
|
||||
const unbindClickOutside = () => globalThis.document?.removeEventListener('click', handleClickOutside);
|
||||
|
||||
watch(popoverVisible, (visible) => {
|
||||
if (!props.closeOnClickOutside) return;
|
||||
|
||||
if (visible) {
|
||||
// 延后到「打开 popover 的这一次点击」冒泡结束后再监听,避免刚打开就被立即关闭
|
||||
nextTick(bindClickOutside);
|
||||
} else {
|
||||
unbindClickOutside();
|
||||
}
|
||||
});
|
||||
|
||||
const destroy = () => {
|
||||
if (!instanceRef.value) return;
|
||||
|
||||
@ -188,5 +260,6 @@ const destroy = () => {
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
destroy();
|
||||
unbindClickOutside();
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -32,6 +32,7 @@ export interface ButtonProps {
|
||||
circle?: boolean;
|
||||
icon?: any;
|
||||
variant?: string;
|
||||
bg?: boolean;
|
||||
}
|
||||
|
||||
export interface CardProps {
|
||||
@ -257,6 +258,13 @@ export interface PopoverProps {
|
||||
popperClass?: string;
|
||||
tabindex?: number;
|
||||
destroyOnClose?: boolean;
|
||||
/** 点击 popover 及其衍生浮层以外的区域时收起,默认开启。 */
|
||||
closeOnClickOutside?: boolean;
|
||||
/**
|
||||
* 追加的「点击不关闭」选择器,会与内置的弹窗 / 确认框 / 下拉等浮层选择器合并。
|
||||
* 用于 popover 内部触发、挂载到 body 之外的浮层不应顺带关闭 popover 的场景。
|
||||
*/
|
||||
clickOutsideIgnore?: string;
|
||||
}
|
||||
|
||||
export interface RadioProps {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.7.14-beta.1",
|
||||
"version": "1.8.0-beta.5",
|
||||
"name": "@tmagic/editor",
|
||||
"type": "module",
|
||||
"sideEffects": [
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
:disabled-page-fragment="disabledPageFragment"
|
||||
:page-bar-sort-options="pageBarSortOptions"
|
||||
:page-filter-function="pageFilterFunction"
|
||||
:hide-sidebar="hideSidebar"
|
||||
>
|
||||
<template #header>
|
||||
<slot name="header"></slot>
|
||||
@ -220,6 +221,7 @@ const stageOptions: StageOptions = {
|
||||
guidesOptions: props.guidesOptions,
|
||||
disabledMultiSelect: props.disabledMultiSelect,
|
||||
alwaysMultiSelect: props.alwaysMultiSelect,
|
||||
disabledFlashTip: props.disabledFlashTip,
|
||||
beforeDblclick: props.beforeDblclick,
|
||||
};
|
||||
|
||||
@ -229,6 +231,19 @@ provide('services', services);
|
||||
|
||||
provide('codeOptions', props.codeOptions);
|
||||
provide('stageOptions', stageOptions);
|
||||
/**
|
||||
* 把顶层 `extendFormState` 提供给非 PropsPanel 链路上的组件使用(例如历史差异对话框 HistoryDiffDialog
|
||||
* 内部的 CompareForm)。这样所有依赖业务上下文的表单 filterFunction 都能拿到一致的扩展状态,
|
||||
* 与 PropsPanel 通过 `:extend-state` 显式传入的方式保持等价。
|
||||
*/
|
||||
provide('extendFormState', props.extendFormState);
|
||||
|
||||
/**
|
||||
* 把历史记录面板的自定义扩展 tab 提供给深层的 HistoryListPanel(它挂在 NavMenu 中,
|
||||
* 以 markRaw component 形式渲染,无法直接通过 props 透传)。业务方可借此在历史记录
|
||||
* 面板内追加自定义模块的历史 tab。
|
||||
*/
|
||||
provide('historyListExtraTabs', props.historyListExtraTabs);
|
||||
|
||||
provide<EventBus>('eventBus', new EventEmitter());
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
<Teleport to="body">
|
||||
<TMagicDialog title="查看修改" v-model="difVisible" fullscreen destroy-on-close>
|
||||
<div style="display: flex; margin-bottom: 10px">
|
||||
<div style="flex: 1"><TMagicTag size="small" type="info">修改前</TMagicTag></div>
|
||||
<div style="flex: 1"><TMagicTag size="small" type="danger">修改前</TMagicTag></div>
|
||||
<div style="flex: 1"><TMagicTag size="small" type="success">修改后</TMagicTag></div>
|
||||
</div>
|
||||
|
||||
@ -63,14 +63,7 @@ import { computed, inject, nextTick, Ref, ref, useTemplateRef, watch } from 'vue
|
||||
|
||||
import type { CodeBlockContent } from '@tmagic/core';
|
||||
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
||||
import {
|
||||
type ContainerChangeEventData,
|
||||
defineFormConfig,
|
||||
defineFormItem,
|
||||
type FormConfig,
|
||||
MFormBox,
|
||||
type TableColumnConfig,
|
||||
} from '@tmagic/form';
|
||||
import { type ContainerChangeEventData, type FormConfig, MFormBox } from '@tmagic/form';
|
||||
|
||||
import FloatingBox from '@editor/components/FloatingBox.vue';
|
||||
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
||||
@ -78,6 +71,7 @@ import { useNextFloatBoxPosition } from '@editor/hooks/use-next-float-box-positi
|
||||
import { useServices } from '@editor/hooks/use-services';
|
||||
import { useWindowRect } from '@editor/hooks/use-window-rect';
|
||||
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
||||
import { getCodeBlockFormConfig } from '@editor/utils/code-block';
|
||||
import { getEditorConfig } from '@editor/utils/config';
|
||||
|
||||
defineOptions({
|
||||
@ -119,106 +113,23 @@ const diffChange = () => {
|
||||
difVisible.value = false;
|
||||
};
|
||||
|
||||
const defaultParamColConfig = defineFormItem<TableColumnConfig>({
|
||||
type: 'row',
|
||||
label: '参数类型',
|
||||
items: [
|
||||
{
|
||||
text: '参数类型',
|
||||
labelWidth: '70px',
|
||||
type: 'select',
|
||||
name: 'type',
|
||||
options: [
|
||||
{
|
||||
text: '数字',
|
||||
label: '数字',
|
||||
value: 'number',
|
||||
},
|
||||
{
|
||||
text: '字符串',
|
||||
label: '字符串',
|
||||
value: 'text',
|
||||
},
|
||||
{
|
||||
text: '组件',
|
||||
label: '组件',
|
||||
value: 'ui-select',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
const codeOptions = inject<Record<string, any>>('codeOptions', {});
|
||||
|
||||
const functionConfig = computed(
|
||||
() =>
|
||||
defineFormConfig([
|
||||
{
|
||||
text: '名称',
|
||||
name: 'name',
|
||||
rules: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
||||
},
|
||||
{
|
||||
text: '描述',
|
||||
name: 'desc',
|
||||
},
|
||||
{
|
||||
text: '执行时机',
|
||||
name: 'timing',
|
||||
type: 'select',
|
||||
options: () => {
|
||||
const options = [
|
||||
{ text: '初始化前', value: 'beforeInit' },
|
||||
{ text: '初始化后', value: 'afterInit' },
|
||||
];
|
||||
if (props.dataSourceType !== 'base') {
|
||||
options.push({ text: '请求前', value: 'beforeRequest' });
|
||||
options.push({ text: '请求后', value: 'afterRequest' });
|
||||
}
|
||||
return options;
|
||||
},
|
||||
display: () => props.isDataSource,
|
||||
},
|
||||
{
|
||||
type: 'table',
|
||||
border: true,
|
||||
text: '参数',
|
||||
enableFullscreen: false,
|
||||
enableToggleMode: false,
|
||||
name: 'params',
|
||||
dropSort: false,
|
||||
items: [
|
||||
{
|
||||
type: 'text',
|
||||
label: '参数名',
|
||||
name: 'name',
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
label: '描述',
|
||||
name: 'extra',
|
||||
},
|
||||
codeBlockService.getParamsColConfig() || defaultParamColConfig,
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'content',
|
||||
type: 'vs-code',
|
||||
options: inject('codeOptions', {}),
|
||||
autosize: { minRows: 10, maxRows: 30 },
|
||||
onChange: (_formState, code: string) => {
|
||||
try {
|
||||
// 检测js代码是否存在语法错误
|
||||
getEditorConfig('parseDSL')(code);
|
||||
|
||||
return code;
|
||||
} catch (error: any) {
|
||||
tMagicMessage.error(error.message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
},
|
||||
]) as FormConfig,
|
||||
/**
|
||||
* 代码块编辑表单配置。统一委托到 utils/code-block 的 `getCodeBlockFormConfig`,
|
||||
* 与 CompareForm 等其它使用方共享同一份 schema,避免双份维护。
|
||||
*
|
||||
* 这里以 computed 包裹是为了让 `props.isDataSource` / `props.dataSourceType` 变化时
|
||||
* "执行时机"字段的可见性与可选项实时刷新。
|
||||
*/
|
||||
const functionConfig = computed<FormConfig>(() =>
|
||||
getCodeBlockFormConfig({
|
||||
paramColConfig: codeBlockService.getParamsColConfig(),
|
||||
isDataSource: () => Boolean(props.isDataSource),
|
||||
dataSourceType: () => props.dataSourceType,
|
||||
codeOptions,
|
||||
editable: true,
|
||||
}),
|
||||
);
|
||||
|
||||
const parseContent = (content: any) => {
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
ref="form"
|
||||
:config="codeParamsConfig"
|
||||
:init-values="model"
|
||||
:last-values="lastValues"
|
||||
:is-compare="isCompare"
|
||||
:disabled="disabled"
|
||||
:size="size"
|
||||
:watch-props="false"
|
||||
@ -24,6 +26,10 @@ defineOptions({
|
||||
|
||||
const props = defineProps<{
|
||||
model: any;
|
||||
/** 对比模式下的历史值,透传给内部 MForm 用于逐项展示参数差异 */
|
||||
lastValues?: any;
|
||||
/** 是否开启对比模式 */
|
||||
isCompare?: boolean;
|
||||
size?: 'small' | 'default' | 'large';
|
||||
disabled?: boolean;
|
||||
name: string;
|
||||
|
||||
258
packages/editor/src/components/CompareForm.vue
Normal file
258
packages/editor/src/components/CompareForm.vue
Normal file
@ -0,0 +1,258 @@
|
||||
<template>
|
||||
<div class="m-editor-compare-form-wrapper" :style="wrapperStyle">
|
||||
<MForm
|
||||
v-if="config.length"
|
||||
ref="form"
|
||||
class="m-editor-compare-form"
|
||||
:config="config"
|
||||
:init-values="currentValues"
|
||||
:last-values="lastValuesProcessed"
|
||||
:is-compare="true"
|
||||
:disabled="true"
|
||||
:label-width="labelWidth"
|
||||
:extend-state="extendState"
|
||||
:show-diff="showDiff"
|
||||
></MForm>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, inject, type Ref, ref, type ShallowRef, useTemplateRef, watch, watchEffect } from 'vue';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
import { type CodeBlockContent, type DataSourceSchema, HookType, type MNode } from '@tmagic/core';
|
||||
import { type FormConfig, type FormState, type FormValue, MForm } from '@tmagic/form';
|
||||
|
||||
import { useServices } from '@editor/hooks/use-services';
|
||||
import type { CompareCategory, CompareFormLoadConfig } from '@editor/type';
|
||||
import { getCodeBlockFormConfig } from '@editor/utils/code-block';
|
||||
|
||||
defineOptions({
|
||||
name: 'MEditorCompareForm',
|
||||
});
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
/** 当前值(修改后的值) */
|
||||
value: Partial<MNode> | Partial<DataSourceSchema> | Partial<CodeBlockContent> | Record<string, any>;
|
||||
/** 用于对比的旧值(修改前的值) */
|
||||
lastValue?: Partial<MNode> | Partial<DataSourceSchema> | Partial<CodeBlockContent> | Record<string, any>;
|
||||
/**
|
||||
* 类型说明:
|
||||
* - `category` 为 `node` 时,`type` 为节点组件的类型,例如 'text'、'button'、'page'、'container' 等
|
||||
* - `category` 为 `data-source` 时,`type` 为数据源类型,例如 'base'、'http'
|
||||
* - `category` 为 `code-block` 时,`type` 可不传
|
||||
*/
|
||||
type?: string;
|
||||
/** 表单配置类别,决定从哪里取 FormConfig */
|
||||
category?: CompareCategory;
|
||||
/** 数据源代码块场景下的数据源类型(base/http),用于代码块表单中"执行时机"展示 */
|
||||
dataSourceType?: string;
|
||||
labelWidth?: string;
|
||||
/**
|
||||
* 外层容器高度。设置后表单内容超出时会在 CompareForm 内部出现滚动条,
|
||||
* 避免 dialog / 面板使用方需要自行处理滚动。可传任意 CSS 长度,例如 `60vh` / `400px` / `100%`。
|
||||
*/
|
||||
height?: string;
|
||||
/**
|
||||
* 用户自定义注入到 MForm.formState 的扩展字段,与 Editor 顶层的 `extendFormState`、
|
||||
* PropsPanel 的 `extend-state` 语义一致。表单 item 的 `display` / `disabled` 等
|
||||
* filterFunction 经常依赖这里注入的字段(如 stage、自定义业务上下文等),
|
||||
* 因此在差异对比场景下也需要透传,避免出现 `formState.xxx is undefined` 的运行时错误。
|
||||
*/
|
||||
extendState?: (_state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
||||
/**
|
||||
* 自定义 FormConfig 加载逻辑。传入后将接管内置的按 `category`(node/data-source/code-block)
|
||||
* 取配置逻辑,调用方可根据业务自行返回(或异步返回)表单配置。可通过
|
||||
* `ctx.defaultLoadConfig()` 复用默认结果再做二次加工。返回的 config 直接用于对比展示。
|
||||
*/
|
||||
loadConfig?: CompareFormLoadConfig;
|
||||
}>(),
|
||||
{
|
||||
category: 'node',
|
||||
labelWidth: '120px',
|
||||
},
|
||||
);
|
||||
|
||||
const { propsService, dataSourceService, codeBlockService, editorService } = useServices();
|
||||
const services = useServices();
|
||||
|
||||
const config = ref<FormConfig>([]);
|
||||
|
||||
/** vs-code 编辑器的 monaco 配置项,沿用 Editor 顶层 provide('codeOptions', ...) 的注入。 */
|
||||
const codeOptions = inject<Record<string, any>>('codeOptions', {});
|
||||
|
||||
/** 将代码块的 content 字段统一成字符串,便于在表单/对比中展示 */
|
||||
const normalizeCodeBlockValue = (
|
||||
v: Partial<CodeBlockContent> | Record<string, any> | undefined,
|
||||
): Record<string, any> => {
|
||||
if (!v) return {};
|
||||
const next: Record<string, any> = { ...v };
|
||||
if (next.content && typeof next.content !== 'string') {
|
||||
try {
|
||||
next.content = next.content.toString();
|
||||
} catch {
|
||||
next.content = '';
|
||||
}
|
||||
}
|
||||
return next;
|
||||
};
|
||||
|
||||
const currentValues = computed<FormValue>(() => {
|
||||
if (props.category === 'code-block') {
|
||||
return normalizeCodeBlockValue(props.value as Partial<CodeBlockContent>);
|
||||
}
|
||||
return (props.value || {}) as FormValue;
|
||||
});
|
||||
|
||||
const lastValuesProcessed = computed<FormValue>(() => {
|
||||
if (props.category === 'code-block') {
|
||||
return normalizeCodeBlockValue(props.lastValue as Partial<CodeBlockContent>);
|
||||
}
|
||||
return (props.lastValue || {}) as FormValue;
|
||||
});
|
||||
|
||||
/**
|
||||
* 外层包裹层的样式:当传入 `height` 时启用固定高度 + 内部滚动,
|
||||
* 这样滚动条会出现在 CompareForm 内部,避免父容器(如 Dialog)自身也产生滚动。
|
||||
*/
|
||||
const wrapperStyle = computed(() => {
|
||||
if (!props.height) return undefined;
|
||||
return {
|
||||
height: props.height,
|
||||
overflow: 'auto',
|
||||
} as Record<string, string>;
|
||||
});
|
||||
|
||||
/**
|
||||
* `code-select` 字段在历史数据中存在两种"语义为空"的形态:
|
||||
* - 字符串 `''`(旧数据 / 用户从未配置过钩子);
|
||||
* - `{ hookType: HookType.CODE, hookData: [] }`(CodeSelect.vue 在挂载时
|
||||
* 写入的默认结构,参见 packages/editor/src/fields/CodeSelect.vue 中
|
||||
* `props.model[props.name] = { hookType: HookType.CODE, hookData: [] }`)。
|
||||
*
|
||||
* 直接 `isEqual` 会把两者判为不等,从而在历史对比里对每个未配置过钩子的组件
|
||||
* 都展示一份"差异",体验很糟糕。这里把它们视为相等,跳过对比。
|
||||
*
|
||||
* 其它类型字段沿用 MForm/Container 的默认 `!isEqual` 判断逻辑。
|
||||
*/
|
||||
const isEmptyCodeSelectValue = (v: any): boolean => {
|
||||
if (v === '' || v === undefined || v === null) return true;
|
||||
if (Array.isArray(v) && v.length === 0) return true;
|
||||
return typeof v === 'object' && v.hookType === HookType.CODE && Array.isArray(v.hookData) && v.hookData.length === 0;
|
||||
};
|
||||
|
||||
const showDiff = ({ curValue, lastValue, config }: { curValue: any; lastValue: any; config: any }) => {
|
||||
if (config?.type === 'code-select') {
|
||||
// 双方都是"空形态",视为相等,不展示对比
|
||||
if (isEmptyCodeSelectValue(curValue) && isEmptyCodeSelectValue(lastValue)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return !isEqual(curValue, lastValue);
|
||||
};
|
||||
|
||||
const removeStyleDisplayConfig = (formConfig: FormConfig): FormConfig =>
|
||||
formConfig.map((item) => {
|
||||
if (!('type' in item)) return item;
|
||||
if (item?.type !== 'tab' || !Array.isArray(item.items)) return item;
|
||||
|
||||
return {
|
||||
...item,
|
||||
items: item.items.map((tabPane) => {
|
||||
if (tabPane?.title !== '样式' || !Array.isArray(tabPane.items)) return tabPane;
|
||||
|
||||
return {
|
||||
...tabPane,
|
||||
display: true,
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* 内置的默认 FormConfig 加载逻辑:按 `category` 从对应 service / 工具取配置。
|
||||
* 作为 ctx.defaultLoadConfig 透传给自定义 `loadConfig`,方便复用与二次加工。
|
||||
*/
|
||||
const defaultLoadConfig = async (): Promise<FormConfig> => {
|
||||
switch (props.category) {
|
||||
case 'node': {
|
||||
if (!props.type) {
|
||||
return [];
|
||||
}
|
||||
return removeStyleDisplayConfig(
|
||||
await propsService.getPropsConfig(props.type, { node: props.value as unknown as MNode }),
|
||||
);
|
||||
}
|
||||
case 'data-source': {
|
||||
return dataSourceService.getFormConfig(props.type || 'base');
|
||||
}
|
||||
case 'code-block': {
|
||||
return getCodeBlockFormConfig({
|
||||
paramColConfig: codeBlockService.getParamsColConfig(),
|
||||
// 通过传入 dataSourceType 间接表达"是数据源代码块"——在对比场景下 props.dataSourceType
|
||||
// 由调用方按 step 上下文显式传入,未传则视为普通代码块,「执行时机」字段隐藏。
|
||||
isDataSource: () => Boolean(props.dataSourceType),
|
||||
dataSourceType: () => props.dataSourceType,
|
||||
codeOptions,
|
||||
// 对比模式只读,不需要校验/语法检查
|
||||
editable: false,
|
||||
});
|
||||
}
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const loadConfig = async () => {
|
||||
if (props.loadConfig) {
|
||||
config.value = await props.loadConfig({
|
||||
category: props.category,
|
||||
type: props.type,
|
||||
dataSourceType: props.dataSourceType,
|
||||
defaultLoadConfig,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
config.value = await defaultLoadConfig();
|
||||
};
|
||||
|
||||
watch(
|
||||
[() => props.category, () => props.type, () => props.dataSourceType, () => props.loadConfig],
|
||||
() => {
|
||||
loadConfig();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const formRef = useTemplateRef<InstanceType<typeof MForm>>('form');
|
||||
|
||||
/**
|
||||
* 把 services / stage 注入 MForm 的 formState,避免 propsService 注入的表单配置中
|
||||
* 形如 `display: ({ services }) => services.uiService.get(...)` 的 filterFunction
|
||||
* 在执行时拿不到 `formState.services` 而报错。
|
||||
*
|
||||
* 与 props-panel/FormPanel.vue 中的注入方式保持一致:
|
||||
* - services:整个 useServices() 返回的服务集合;
|
||||
* - stage:当前 editorService.get('stage') 的最新值。
|
||||
*/
|
||||
const stage = computed(() => editorService.get('stage'));
|
||||
|
||||
watchEffect(() => {
|
||||
if (formRef.value) {
|
||||
formRef.value.formState.stage = stage.value;
|
||||
formRef.value.formState.services = services;
|
||||
}
|
||||
});
|
||||
|
||||
defineExpose<{
|
||||
form: ShallowRef<InstanceType<typeof MForm> | null>;
|
||||
config: Ref<FormConfig>;
|
||||
reload: () => Promise<void>;
|
||||
}>({
|
||||
form: formRef,
|
||||
config,
|
||||
reload: loadConfig,
|
||||
});
|
||||
</script>
|
||||
@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div
|
||||
v-if="display"
|
||||
ref="rootEl"
|
||||
class="menu-item"
|
||||
:class="`${data.type} ${data.className || ''}`"
|
||||
@click="clickHandler(data, $event)"
|
||||
@ -12,7 +13,7 @@
|
||||
|
||||
<template v-else-if="data.type === 'button'">
|
||||
<TMagicTooltip v-if="data.tooltip" effect="dark" placement="bottom-start" :content="data.tooltip">
|
||||
<TMagicButton size="small" link :disabled="disabled">
|
||||
<TMagicButton size="small" link :disabled="disabled" v-bind="data.buttonProps || {}">
|
||||
<template #icon v-if="data.icon">
|
||||
<MIcon :icon="data.icon"></MIcon>
|
||||
</template>
|
||||
@ -20,7 +21,7 @@
|
||||
</TMagicButton>
|
||||
</TMagicTooltip>
|
||||
|
||||
<TMagicButton v-else size="small" link :disabled="disabled" :title="data.text">
|
||||
<TMagicButton v-else size="small" link :disabled="disabled" :title="data.text" v-bind="data.buttonProps || {}">
|
||||
<template #icon v-if="data.icon">
|
||||
<MIcon :icon="data.icon"></MIcon>
|
||||
</template>
|
||||
@ -56,7 +57,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
import { computed, useTemplateRef } from 'vue';
|
||||
import { ArrowDown } from '@element-plus/icons-vue';
|
||||
|
||||
import {
|
||||
@ -93,6 +94,9 @@ const props = withDefaults(
|
||||
);
|
||||
const services = useServices();
|
||||
|
||||
const rootElRef = useTemplateRef<HTMLDivElement>('rootEl');
|
||||
const getElRef = () => rootElRef;
|
||||
|
||||
const disabled = computed(() => {
|
||||
if (typeof props.data === 'string') return false;
|
||||
if (props.data.type === 'component') return false;
|
||||
@ -145,4 +149,6 @@ const mouseupHandler = (item: MenuButton | MenuComponent, event: MouseEvent) =>
|
||||
buttonHandler(item, event);
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ getElRef });
|
||||
</script>
|
||||
|
||||
@ -15,6 +15,7 @@ import type {
|
||||
ComponentGroup,
|
||||
CustomContentMenuFunction,
|
||||
DatasourceTypeOption,
|
||||
HistoryListExtraTab,
|
||||
IsExpandableFunction,
|
||||
MenuBarData,
|
||||
MenuButton,
|
||||
@ -34,6 +35,8 @@ export interface EditorProps {
|
||||
datasourceList?: DatasourceTypeOption[];
|
||||
/** 左侧面板配置 */
|
||||
sidebar?: SideBarData;
|
||||
/** 是否隐藏左侧面板 */
|
||||
hideSidebar?: boolean;
|
||||
/** 顶部工具栏配置 */
|
||||
menu?: MenuBarData;
|
||||
/** 组件树右键菜单 */
|
||||
@ -84,6 +87,8 @@ export interface EditorProps {
|
||||
alwaysMultiSelect?: boolean;
|
||||
/** 禁用页面片 */
|
||||
disabledPageFragment?: boolean;
|
||||
/** 禁用「非点击画布选中组件时(如从图层树、面包屑等外部选中),对选中区域做高亮闪烁提示」,默认 false(即默认开启闪烁) */
|
||||
disabledFlashTip?: boolean;
|
||||
/** 禁用双击在浮层中单独编辑选中组件 */
|
||||
disabledStageOverlay?: boolean;
|
||||
/** 禁用属性配置面板右下角显示源码的按钮 */
|
||||
@ -123,6 +128,8 @@ export interface EditorProps {
|
||||
/** 组件树节点双击前的钩子函数,返回 false 则阻止默认的双击行为 */
|
||||
beforeLayerNodeDblclick?: (event: MouseEvent, data: TreeNodeData) => Promise<boolean | void> | boolean | void;
|
||||
extendFormState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
||||
/** 历史记录面板的自定义扩展 tab,追加在内置的页面/数据源/代码块 tab 之后 */
|
||||
historyListExtraTabs?: HistoryListExtraTab[];
|
||||
/** 页面顺序拖拽配置参数 */
|
||||
pageBarSortOptions?: PageBarSortOptions;
|
||||
/** 页面搜索函数 */
|
||||
@ -134,6 +141,7 @@ export const defaultEditorProps = {
|
||||
disabledMultiSelect: false,
|
||||
alwaysMultiSelect: false,
|
||||
disabledPageFragment: false,
|
||||
disabledFlashTip: false,
|
||||
disabledStageOverlay: false,
|
||||
containerHighlightClassName: CONTAINER_HIGHLIGHT_CLASS_NAME,
|
||||
containerHighlightDuration: 800,
|
||||
@ -143,6 +151,7 @@ export const defaultEditorProps = {
|
||||
disabledCodeBlock: false,
|
||||
componentGroupList: () => [],
|
||||
datasourceList: () => [],
|
||||
historyListExtraTabs: () => [],
|
||||
menu: () => ({ left: [], right: [] }),
|
||||
layerContentMenu: () => [],
|
||||
stageContentMenu: () => [],
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
<template>
|
||||
<MagicCodeEditor
|
||||
:height="config.height"
|
||||
:init-values="model[name]"
|
||||
:type="diffMode ? 'diff' : undefined"
|
||||
:init-values="diffMode ? (lastValues || {})[name] : model[name]"
|
||||
:modified-values="diffMode ? model[name] : undefined"
|
||||
:language="config.language"
|
||||
:options="{
|
||||
...config.options,
|
||||
readOnly: disabled,
|
||||
readOnly: diffMode ? true : disabled,
|
||||
}"
|
||||
:autosize="config.autosize"
|
||||
:parse="config.parse"
|
||||
@ -15,6 +17,8 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
|
||||
import type { CodeConfig, FieldProps } from '@tmagic/form';
|
||||
|
||||
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
||||
@ -27,10 +31,22 @@ const emit = defineEmits<{
|
||||
change: [value: string | any];
|
||||
}>();
|
||||
|
||||
withDefaults(defineProps<FieldProps<CodeConfig>>(), {
|
||||
const props = withDefaults(defineProps<FieldProps<CodeConfig>>(), {
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
/**
|
||||
* 对比模式判定:
|
||||
*
|
||||
* - 当 `isCompare === true` 时,由父级 `MFormContainer` 统一渲染一次本字段(不再渲染前后两份独立组件),
|
||||
* 并把 `model`(当前值)与 `lastValues`(历史值)一并传入;
|
||||
* - 此时本字段切换到 monaco 自带的 diff 编辑器(左侧旧、右侧新),相比"两个独立 monaco 实例"更直观,
|
||||
* 也避免了同一表单内重复实例化重型编辑器带来的开销。
|
||||
*
|
||||
* 仅当存在历史值(lastValues)且开启了对比模式时启用 diff,避免在 lastValues 缺失时退化为空对比。
|
||||
*/
|
||||
const diffMode = computed(() => Boolean(props.isCompare && props.lastValues));
|
||||
|
||||
const save = (v: string | any) => {
|
||||
emit('change', v);
|
||||
};
|
||||
|
||||
@ -4,11 +4,11 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, watch } from 'vue';
|
||||
import serialize from 'serialize-javascript';
|
||||
|
||||
import type { CodeLinkConfig, FieldProps, MLink } from '@tmagic/form';
|
||||
|
||||
import { getEditorConfig } from '@editor/utils/config';
|
||||
import { serializeConfig } from '@editor/utils/editor';
|
||||
|
||||
defineOptions({
|
||||
name: 'MFieldsCodeLink',
|
||||
@ -47,10 +47,7 @@ watch(
|
||||
() => props.model[props.name],
|
||||
(value) => {
|
||||
modelValue.form = {
|
||||
[props.name]: serialize(value, {
|
||||
space: 2,
|
||||
unsafe: true,
|
||||
}).replace(/"(\w+)":\s/g, '$1: '),
|
||||
[props.name]: serializeConfig(value),
|
||||
};
|
||||
},
|
||||
{
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
:size="size"
|
||||
:prop="prop"
|
||||
:disabled="disabled"
|
||||
:lastValues="lastValues"
|
||||
:is-compare="isCompareMode"
|
||||
:last-values="lastValues?.[name]"
|
||||
:model="model[name]"
|
||||
@change="changeHandler"
|
||||
>
|
||||
@ -38,6 +39,21 @@ const { dataSourceService, codeBlockService } = useServices();
|
||||
|
||||
const props = withDefaults(defineProps<FieldProps<CodeSelectConfig>>(), {});
|
||||
|
||||
/**
|
||||
* 对比模式判定:
|
||||
*
|
||||
* code-select 仅是对内部「钩子列表」group-list 的包裹,本身不渲染叶子字段。父级 `MFormContainer`
|
||||
* 已将其归入「自接管对比字段」(见 Container.vue 的 `SELF_DIFF_FIELD_TYPES`),即对比时只渲染一次
|
||||
* 本组件,并把当前值 `model` 与历史值 `lastValues` 一并传入,由本组件把 `is-compare`/`lastValues`
|
||||
* 透传给内部 MContainer,再由 group-list / code-select-col 等子级逐项展示前后差异。
|
||||
*
|
||||
* 注意:`model` 传入的是 `model[name]`(钩子值本身),因此 `lastValues` 也必须同层取 `lastValues[name]`,
|
||||
* 否则前后值的嵌套层级不一致会导致对比错位。
|
||||
*
|
||||
* 仅当存在历史值时才启用对比,避免 lastValues 缺失时退化为「全部新增」的空对比。
|
||||
*/
|
||||
const isCompareMode = computed(() => Boolean(props.isCompare && props.lastValues));
|
||||
|
||||
const codeConfig = computed<GroupListConfig>(() => ({
|
||||
type: 'group-list',
|
||||
name: 'hookData',
|
||||
|
||||
@ -2,7 +2,20 @@
|
||||
<div class="m-fields-code-select-col">
|
||||
<div class="code-select-container">
|
||||
<!-- 代码块下拉框 -->
|
||||
<!-- 对比模式下交由 MFormContainer 展示下拉框的前后差异(codeId 变化时高亮新旧代码块名),
|
||||
普通模式仍直接渲染 MSelect 以保留选择 / 写值逻辑 -->
|
||||
<MFormContainer
|
||||
v-if="isCompareMode"
|
||||
class="select"
|
||||
:config="selectConfig"
|
||||
:model="model"
|
||||
:last-values="lastValues"
|
||||
:is-compare="true"
|
||||
:size="size"
|
||||
:prop="prop"
|
||||
></MFormContainer>
|
||||
<MSelect
|
||||
v-else
|
||||
class="select"
|
||||
:config="selectConfig"
|
||||
:name="name"
|
||||
@ -12,9 +25,9 @@
|
||||
@change="onCodeIdChangeHandler"
|
||||
></MSelect>
|
||||
|
||||
<!-- 查看/编辑按钮 -->
|
||||
<!-- 查看/编辑按钮:对比模式为只读,不展示 -->
|
||||
<TMagicButton
|
||||
v-if="model[name] && hasCodeBlockSidePanel"
|
||||
v-if="!isCompareMode && model[name] && hasCodeBlockSidePanel"
|
||||
class="m-fields-select-action-button"
|
||||
:size="size"
|
||||
@click="editCode(model[name])"
|
||||
@ -29,6 +42,8 @@
|
||||
name="params"
|
||||
:key="model[name]"
|
||||
:model="model"
|
||||
:last-values="lastValues"
|
||||
:is-compare="isCompareMode"
|
||||
:size="size"
|
||||
:disabled="disabled"
|
||||
:params-config="paramsConfig"
|
||||
@ -52,6 +67,7 @@ import {
|
||||
filterFunction,
|
||||
type FormItemConfig,
|
||||
type FormState,
|
||||
MContainer as MFormContainer,
|
||||
MSelect,
|
||||
type SelectConfig,
|
||||
} from '@tmagic/form';
|
||||
@ -77,6 +93,18 @@ const props = withDefaults(defineProps<FieldProps<CodeSelectColConfig>>(), {
|
||||
disabled: false,
|
||||
});
|
||||
|
||||
/**
|
||||
* 对比模式判定:
|
||||
*
|
||||
* code-select-col 由「代码块下拉框 + 参数子表单」组成,属于复合字段。父级 `MFormContainer` 已将其
|
||||
* 归入「自接管对比字段」(见 Container.vue 的 `SELF_DIFF_FIELD_TYPES`),即对比时只渲染一次本组件,
|
||||
* 并把当前值 `model` 与历史值 `lastValues` 一并传入,由本组件把 `is-compare`/`lastValues` 透传给
|
||||
* 内部的下拉框(MFormContainer)与参数表单(CodeParams),逐项展示前后差异。
|
||||
*
|
||||
* 仅当存在历史值时才启用对比,避免 lastValues 缺失时退化为「全部新增」的空对比。
|
||||
*/
|
||||
const isCompareMode = computed(() => Boolean(props.isCompare && props.lastValues));
|
||||
|
||||
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
||||
|
||||
const hasCodeBlockSidePanel = computed(() =>
|
||||
|
||||
@ -72,7 +72,10 @@
|
||||
@change="onChangeHandler"
|
||||
></TMagicCascader>
|
||||
|
||||
<TMagicTooltip v-if="selectDataSourceId && hasDataSourceSidePanel" :content="notEditable ? '查看' : '编辑'">
|
||||
<TMagicTooltip
|
||||
v-if="selectDataSourceId && hasDataSourceSidePanel && !isCompare"
|
||||
:content="notEditable ? '查看' : '编辑'"
|
||||
>
|
||||
<TMagicButton class="m-fields-select-action-button" :size="size" @click="editHandler(selectDataSourceId)"
|
||||
><MIcon :icon="!notEditable ? Edit : View"></MIcon
|
||||
></TMagicButton>
|
||||
@ -133,6 +136,9 @@ const dataSources = computed(() => {
|
||||
const valueIsKey = computed(() => props.value === 'key');
|
||||
const notEditable = computed(() => filterFunction(mForm, props.notEditable, props));
|
||||
|
||||
/** 对比模式下隐藏查看/编辑操作按钮,仅保留只读展示。 */
|
||||
const isCompare = computed(() => Boolean(mForm?.isCompare));
|
||||
|
||||
const dataSourcesOptions = computed<SelectOption[]>(() =>
|
||||
dataSources.value.map((ds) => ({
|
||||
text: ds.title || ds.id,
|
||||
|
||||
@ -28,14 +28,15 @@
|
||||
></component>
|
||||
|
||||
<TMagicTooltip
|
||||
v-if="config.fieldConfig && !disabledDataSource"
|
||||
v-if="config.fieldConfig && !disabledDataSource && !mForm?.isCompare"
|
||||
:disabled="showDataSourceFieldSelect"
|
||||
content="选择数据源"
|
||||
>
|
||||
<TMagicButton
|
||||
:type="showDataSourceFieldSelect ? 'primary' : 'default'"
|
||||
:size="size"
|
||||
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
||||
:disabled="disabled"
|
||||
@click="onToggleDataSourceFieldSelectHandler"
|
||||
><MIcon :icon="Coin"></MIcon
|
||||
></TMagicButton>
|
||||
</TMagicTooltip>
|
||||
@ -185,4 +186,10 @@ const onChangeHandler = (value: string[], eventData?: ContainerChangeEventData)
|
||||
emit('change', [dsId], eventData);
|
||||
}
|
||||
};
|
||||
|
||||
const onToggleDataSourceFieldSelectHandler = () => {
|
||||
// 禁用或对比模式下禁止切换
|
||||
if (props.disabled || mForm?.isCompare) return;
|
||||
showDataSourceFieldSelect.value = !showDataSourceFieldSelect.value;
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="m-editor-data-source-fields">
|
||||
<MagicTable :data="model[name]" :columns="fieldColumns" :border="true"></MagicTable>
|
||||
<MagicTable :data="model[name]" :columns="displayColumns" :border="true"></MagicTable>
|
||||
|
||||
<div class="m-editor-data-source-fields-footer">
|
||||
<div v-if="!isCompare" class="m-editor-data-source-fields-footer">
|
||||
<TMagicButton size="small" :disabled="disabled" plain @click="newFromJsonHandler()">快速添加</TMagicButton>
|
||||
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
||||
</div>
|
||||
@ -47,7 +47,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { inject, Ref, ref } from 'vue';
|
||||
import { computed, inject, Ref, ref } from 'vue';
|
||||
|
||||
import type { DataSchema } from '@tmagic/core';
|
||||
import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
|
||||
@ -84,6 +84,10 @@ const emit = defineEmits<{
|
||||
}>();
|
||||
|
||||
const { uiService } = useServices();
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
|
||||
/** 对比模式下隐藏新增/编辑/删除等操作按钮,仅保留只读展示。 */
|
||||
const isCompare = computed(() => Boolean(mForm?.isCompare));
|
||||
|
||||
const fieldValues = ref<Record<string, any>>({});
|
||||
const fieldTitle = ref('');
|
||||
@ -176,6 +180,11 @@ const fieldColumns: ColumnConfig[] = [
|
||||
},
|
||||
];
|
||||
|
||||
/** 对比模式下移除「操作」列(编辑/删除按钮),仅保留只读列。 */
|
||||
const displayColumns = computed<ColumnConfig[]>(() =>
|
||||
isCompare.value ? fieldColumns.filter((col) => !col.actions) : fieldColumns,
|
||||
);
|
||||
|
||||
const dataSourceFieldsConfig: FormConfig = [
|
||||
{ name: 'index', type: 'hidden', filter: 'number', defaultValue: -1 },
|
||||
{
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
></MCascader>
|
||||
|
||||
<TMagicTooltip
|
||||
v-if="model[name] && isCustomMethod && hasDataSourceSidePanel"
|
||||
v-if="model[name] && isCustomMethod && hasDataSourceSidePanel && !isCompare"
|
||||
:content="notEditable ? '查看' : '编辑'"
|
||||
>
|
||||
<TMagicButton class="m-fields-select-action-button" :size="size" @click="editCodeHandler">
|
||||
@ -81,6 +81,9 @@ const hasDataSourceSidePanel = computed(() =>
|
||||
|
||||
const notEditable = computed(() => filterFunction(mForm, props.config.notEditable, props));
|
||||
|
||||
/** 对比模式下隐藏查看/编辑操作按钮,仅保留只读展示。 */
|
||||
const isCompare = computed(() => Boolean(mForm?.isCompare));
|
||||
|
||||
const dataSources = computed(() => dataSourceService.get('dataSources'));
|
||||
|
||||
const isCustomMethod = computed(() => {
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="m-editor-data-source-methods">
|
||||
<MagicTable :data="model[name]" :columns="methodColumns" :border="true"></MagicTable>
|
||||
<MagicTable :data="model[name]" :columns="displayColumns" :border="true"></MagicTable>
|
||||
|
||||
<div class="m-editor-data-source-methods-footer">
|
||||
<div v-if="!isCompare" class="m-editor-data-source-methods-footer">
|
||||
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="createCodeHandler"
|
||||
>添加</TMagicButton
|
||||
>
|
||||
@ -21,12 +21,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { nextTick, ref, useTemplateRef } from 'vue';
|
||||
import { computed, inject, nextTick, ref, useTemplateRef } from 'vue';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
|
||||
import type { CodeBlockContent } from '@tmagic/core';
|
||||
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
||||
import type { ContainerChangeEventData, DataSourceMethodsConfig, FieldProps } from '@tmagic/form';
|
||||
import type { ContainerChangeEventData, DataSourceMethodsConfig, FieldProps, FormState } from '@tmagic/form';
|
||||
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
||||
|
||||
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
||||
@ -42,6 +42,11 @@ const props = withDefaults(defineProps<FieldProps<DataSourceMethodsConfig>>(), {
|
||||
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
|
||||
/** 对比模式下隐藏新增/编辑/删除等操作按钮,仅保留只读展示。 */
|
||||
const isCompare = computed(() => Boolean(mForm?.isCompare));
|
||||
|
||||
const codeConfig = ref<Omit<CodeBlockContent, 'content'> & { content: string }>();
|
||||
const codeBlockEditorRef = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
|
||||
|
||||
@ -107,6 +112,11 @@ const methodColumns: ColumnConfig[] = [
|
||||
},
|
||||
];
|
||||
|
||||
/** 对比模式下移除「操作」列(编辑/删除按钮),仅保留只读列。 */
|
||||
const displayColumns = computed<ColumnConfig[]>(() =>
|
||||
isCompare.value ? methodColumns.filter((col) => !col.actions) : methodColumns,
|
||||
);
|
||||
|
||||
const createCodeHandler = () => {
|
||||
codeConfig.value = {
|
||||
name: '',
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<template>
|
||||
<div class="m-editor-data-source-fields">
|
||||
<MagicTable :data="model[name]" :columns="columns"></MagicTable>
|
||||
<MagicTable :data="model[name]" :columns="displayColumns"></MagicTable>
|
||||
|
||||
<div class="m-editor-data-source-fields-footer">
|
||||
<div v-if="!isCompare" class="m-editor-data-source-fields-footer">
|
||||
<TMagicButton size="small" type="primary" :disabled="disabled" plain @click="newHandler()">添加</TMagicButton>
|
||||
</div>
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { inject, Ref, ref } from 'vue';
|
||||
import { computed, inject, Ref, ref } from 'vue';
|
||||
|
||||
import type { MockSchema } from '@tmagic/core';
|
||||
import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
|
||||
@ -54,6 +54,11 @@ const props = withDefaults(defineProps<FieldProps<DataSourceMocksConfig>>(), {
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
const { uiService } = useServices();
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
|
||||
/** 对比模式下隐藏新增/编辑/删除等操作按钮,仅保留只读展示。 */
|
||||
const isCompare = computed(() => Boolean(mForm?.isCompare));
|
||||
|
||||
const width = defineModel<number>('width', { default: 670 });
|
||||
|
||||
const drawerTitle = ref('');
|
||||
@ -202,6 +207,11 @@ const columns: ColumnConfig[] = [
|
||||
},
|
||||
];
|
||||
|
||||
/** 对比模式下移除「操作」列(编辑/删除按钮),仅保留只读列。 */
|
||||
const displayColumns = computed<ColumnConfig[]>(() =>
|
||||
isCompare.value ? columns.filter((col) => !col.actions) : columns,
|
||||
);
|
||||
|
||||
const newHandler = () => {
|
||||
const isFirstRow = props.model[props.name].length === 0;
|
||||
formValues.value = {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user