@tmagic/editor 1.8.0-beta.1 → 1.8.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/Editor.vue_vue_type_script_setup_true_lang.js +11 -2
- package/dist/es/components/CodeBlockEditor.vue_vue_type_script_setup_true_lang.js +18 -110
- package/dist/es/components/CodeParams.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/es/components/CompareForm.js +5 -0
- package/dist/es/components/CompareForm.vue_vue_type_script_setup_true_lang.js +167 -0
- package/dist/es/fields/Code.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/fields/CodeSelect.vue_vue_type_script_setup_true_lang.js +18 -2
- package/dist/es/fields/CodeSelectCol.vue_vue_type_script_setup_true_lang.js +37 -6
- package/dist/es/fields/DataSourceFieldSelect/FieldSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/DataSourceFieldSelect/Index.vue_vue_type_script_setup_true_lang.js +2 -2
- package/dist/es/fields/DataSourceFields.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceMethodSelect.vue_vue_type_script_setup_true_name_true_lang.js +3 -1
- package/dist/es/fields/DataSourceMethods.vue_vue_type_script_setup_true_lang.js +15 -7
- package/dist/es/fields/DataSourceMocks.vue_vue_type_script_setup_true_lang.js +14 -6
- package/dist/es/fields/DataSourceSelect.vue_vue_type_script_setup_true_lang.js +3 -1
- package/dist/es/fields/EventSelect.vue_vue_type_script_setup_true_lang.js +58 -11
- package/dist/es/fields/KeyValue.vue_vue_type_script_setup_true_lang.js +11 -6
- package/dist/es/fields/UISelect.vue_vue_type_script_setup_true_lang.js +8 -5
- package/dist/es/hooks/use-code-block-edit.js +2 -2
- package/dist/es/hooks/use-stage.js +15 -7
- package/dist/es/index.js +3 -1
- package/dist/es/initService.js +6 -6
- package/dist/es/layouts/CodeEditor.vue_vue_type_script_setup_true_lang.js +4 -0
- package/dist/es/layouts/Framework.vue_vue_type_script_setup_true_lang.js +12 -7
- package/dist/es/layouts/NavMenu.vue_vue_type_script_setup_true_lang.js +8 -0
- package/dist/es/layouts/history-list/Bucket.js +5 -0
- package/dist/es/layouts/history-list/Bucket.vue_vue_type_script_setup_true_lang.js +84 -0
- package/dist/es/layouts/history-list/CodeBlockTab.js +5 -0
- package/dist/es/layouts/history-list/CodeBlockTab.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/es/layouts/history-list/DataSourceTab.js +5 -0
- package/dist/es/layouts/history-list/DataSourceTab.vue_vue_type_script_setup_true_lang.js +62 -0
- package/dist/es/layouts/history-list/GroupRow.js +5 -0
- package/dist/es/layouts/history-list/GroupRow.vue_vue_type_script_setup_true_lang.js +180 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.js +5 -0
- package/dist/es/layouts/history-list/HistoryDiffDialog.vue_vue_type_script_setup_true_lang.js +195 -0
- package/dist/es/layouts/history-list/HistoryListPanel.js +5 -0
- package/dist/es/layouts/history-list/HistoryListPanel.vue_vue_type_script_setup_true_lang.js +270 -0
- package/dist/es/layouts/history-list/InitialRow.js +5 -0
- package/dist/es/layouts/history-list/InitialRow.vue_vue_type_script_setup_true_lang.js +48 -0
- package/dist/es/layouts/history-list/PageTab.js +5 -0
- package/dist/es/layouts/history-list/PageTab.vue_vue_type_script_setup_true_lang.js +99 -0
- package/dist/es/layouts/history-list/composables.js +154 -0
- package/dist/es/layouts/sidebar/layer/use-node-status.js +1 -1
- package/dist/es/services/BaseService.js +31 -68
- package/dist/es/services/codeBlock.js +205 -8
- package/dist/es/services/componentList.js +2 -2
- package/dist/es/services/dataSource.js +217 -8
- package/dist/es/services/dep.js +21 -9
- package/dist/es/services/editor.js +350 -160
- package/dist/es/services/events.js +2 -2
- package/dist/es/services/history.js +407 -12
- package/dist/es/services/keybinding.js +2 -2
- package/dist/es/services/props.js +8 -8
- package/dist/es/services/stageOverlay.js +2 -2
- package/dist/es/services/storage.js +2 -2
- package/dist/es/services/ui.js +2 -2
- package/dist/es/style.css +347 -1
- package/dist/es/utils/code-block.js +122 -0
- package/dist/es/utils/content-menu.js +4 -5
- package/dist/es/utils/dep/worker.js +1 -1
- package/dist/es/utils/editor.js +2 -2
- package/dist/es/utils/undo-redo.js +20 -0
- package/dist/style.css +347 -1
- package/dist/tmagic-editor.umd.cjs +3165 -774
- package/package.json +7 -7
- package/src/Editor.vue +7 -0
- package/src/components/CodeBlockEditor.vue +20 -109
- package/src/components/CodeParams.vue +6 -0
- package/src/components/CompareForm.vue +225 -0
- package/src/editorProps.ts +2 -0
- package/src/fields/Code.vue +19 -3
- package/src/fields/CodeSelect.vue +17 -1
- package/src/fields/CodeSelectCol.vue +30 -2
- package/src/fields/DataSourceFieldSelect/FieldSelect.vue +7 -1
- package/src/fields/DataSourceFieldSelect/Index.vue +2 -2
- package/src/fields/DataSourceFields.vue +12 -3
- package/src/fields/DataSourceMethodSelect.vue +4 -1
- package/src/fields/DataSourceMethods.vue +14 -4
- package/src/fields/DataSourceMocks.vue +13 -3
- package/src/fields/DataSourceSelect.vue +4 -1
- package/src/fields/EventSelect.vue +57 -8
- package/src/fields/KeyValue.vue +17 -4
- package/src/fields/UISelect.vue +5 -2
- package/src/hooks/use-code-block-edit.ts +5 -2
- package/src/hooks/use-stage.ts +23 -7
- package/src/index.ts +1 -0
- package/src/layouts/CodeEditor.vue +15 -0
- package/src/layouts/Framework.vue +10 -5
- package/src/layouts/NavMenu.vue +9 -0
- package/src/layouts/history-list/Bucket.vue +99 -0
- package/src/layouts/history-list/CodeBlockTab.vue +61 -0
- package/src/layouts/history-list/DataSourceTab.vue +61 -0
- package/src/layouts/history-list/GroupRow.vue +207 -0
- package/src/layouts/history-list/HistoryDiffDialog.vue +212 -0
- package/src/layouts/history-list/HistoryListPanel.vue +271 -0
- package/src/layouts/history-list/InitialRow.vue +41 -0
- package/src/layouts/history-list/PageTab.vue +94 -0
- package/src/layouts/history-list/composables.ts +195 -0
- package/src/layouts/sidebar/layer/use-node-status.ts +9 -6
- package/src/services/BaseService.ts +35 -86
- package/src/services/codeBlock.ts +256 -5
- package/src/services/dataSource.ts +257 -6
- package/src/services/dep.ts +32 -9
- package/src/services/editor.ts +454 -171
- package/src/services/history.ts +452 -8
- package/src/services/props.ts +2 -2
- package/src/theme/history-list-panel.scss +423 -0
- package/src/theme/theme.scss +1 -0
- package/src/type.ts +179 -6
- package/src/utils/code-block.ts +150 -0
- package/src/utils/content-menu.ts +8 -5
- package/src/utils/dep/worker.ts +5 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/undo-redo.ts +23 -0
- package/types/index.d.ts +2105 -810
- package/dist/es/utils/compose.js +0 -44
- package/dist/es/utils/editor-history.js +0 -100
- package/src/utils/compose.ts +0 -52
- package/src/utils/editor-history.ts +0 -138
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2025 Tencent. All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
20
|
+
import { defineFormConfig, defineFormItem, type FormConfig, type TableColumnConfig } from '@tmagic/form';
|
|
21
|
+
|
|
22
|
+
import { getEditorConfig } from './config';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 代码块编辑表单配置的统一入口。
|
|
26
|
+
*
|
|
27
|
+
* 用于:
|
|
28
|
+
* - `CodeBlockEditor.vue`:作为代码块新增/编辑的表单结构;
|
|
29
|
+
* - `CompareForm.vue`:在历史差异对比中以"代码块"形态展示前后值。
|
|
30
|
+
*
|
|
31
|
+
* 通过参数控制两端的细微差异(是否启用必填校验 / vs-code onChange 校验 / dataSource 相关字段显示规则等),
|
|
32
|
+
* 避免两边同步两份相同的 schema 而造成漂移。
|
|
33
|
+
*/
|
|
34
|
+
export interface GetCodeBlockFormConfigOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 自定义 `params` 表格的"参数类型"列配置。优先级高于内置默认值;
|
|
37
|
+
* 通常由 `codeBlockService.getParamsColConfig()` 注入业务侧的扩展。
|
|
38
|
+
*/
|
|
39
|
+
paramColConfig?: TableColumnConfig;
|
|
40
|
+
/**
|
|
41
|
+
* 是否在「数据源代码块」语境下使用:
|
|
42
|
+
* - true:`执行时机` 字段会展示,`请求前 / 请求后` 选项仅在 `dataSourceType !== 'base'` 时出现;
|
|
43
|
+
* - false:`执行时机` 字段隐藏(普通代码块没有时机概念)。
|
|
44
|
+
*
|
|
45
|
+
* 注意这里以函数形式传入是为了让 `display` / `options` 在每次渲染时实时取值,
|
|
46
|
+
* 例如外部 `props.isDataSource` 切换或 `dataSourceType` 变更都能立即生效。
|
|
47
|
+
*/
|
|
48
|
+
isDataSource?: () => boolean;
|
|
49
|
+
/** 当 isDataSource 为 true 时使用:返回当前数据源类型(`base` / `http` / ...),决定时机选项是否包含请求前后。 */
|
|
50
|
+
dataSourceType?: () => string | undefined;
|
|
51
|
+
/** vs-code 编辑器的额外 monaco options。一般传 `inject('codeOptions', {})` 的结果。 */
|
|
52
|
+
codeOptions?: Record<string, any>;
|
|
53
|
+
/**
|
|
54
|
+
* 是否启用编辑态特性:
|
|
55
|
+
* - true(默认):`name` 字段加必填校验;vs-code 的 `onChange` 会调用 `parseDSL` 检查语法,出错时弹消息并抛错;
|
|
56
|
+
* - false:纯只读/对比场景,不加校验逻辑。
|
|
57
|
+
*/
|
|
58
|
+
editable?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 默认的"参数类型"列配置:数字 / 字符串 / 组件 三选一。 */
|
|
62
|
+
const defaultParamColConfig = () =>
|
|
63
|
+
defineFormItem<TableColumnConfig>({
|
|
64
|
+
type: 'row',
|
|
65
|
+
label: '参数类型',
|
|
66
|
+
items: [
|
|
67
|
+
{
|
|
68
|
+
text: '参数类型',
|
|
69
|
+
labelWidth: '70px',
|
|
70
|
+
type: 'select',
|
|
71
|
+
name: 'type',
|
|
72
|
+
options: [
|
|
73
|
+
{ text: '数字', label: '数字', value: 'number' },
|
|
74
|
+
{ text: '字符串', label: '字符串', value: 'text' },
|
|
75
|
+
{ text: '组件', label: '组件', value: 'ui-select' },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 生成代码块表单配置。返回的是普通对象数组,可直接传给 `<MForm :config>`;
|
|
83
|
+
* 如需响应式的 props 变化(如切换 dataSourceType),调用方在 `computed` 中再次调用本函数即可。
|
|
84
|
+
*/
|
|
85
|
+
export const getCodeBlockFormConfig = (options: GetCodeBlockFormConfigOptions = {}): FormConfig => {
|
|
86
|
+
const { paramColConfig, isDataSource, dataSourceType, codeOptions = {}, editable = true } = options;
|
|
87
|
+
|
|
88
|
+
return defineFormConfig([
|
|
89
|
+
{
|
|
90
|
+
text: '名称',
|
|
91
|
+
name: 'name',
|
|
92
|
+
...(editable ? { rules: [{ required: true, message: '请输入名称', trigger: 'blur' }] } : {}),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
text: '描述',
|
|
96
|
+
name: 'desc',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
text: '执行时机',
|
|
100
|
+
name: 'timing',
|
|
101
|
+
type: 'select',
|
|
102
|
+
options: () => {
|
|
103
|
+
const list = [
|
|
104
|
+
{ text: '初始化前', value: 'beforeInit' },
|
|
105
|
+
{ text: '初始化后', value: 'afterInit' },
|
|
106
|
+
];
|
|
107
|
+
if (dataSourceType?.() !== 'base') {
|
|
108
|
+
list.push({ text: '请求前', value: 'beforeRequest' });
|
|
109
|
+
list.push({ text: '请求后', value: 'afterRequest' });
|
|
110
|
+
}
|
|
111
|
+
return list;
|
|
112
|
+
},
|
|
113
|
+
display: () => Boolean(isDataSource?.()),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
type: 'table',
|
|
117
|
+
border: true,
|
|
118
|
+
text: '参数',
|
|
119
|
+
enableFullscreen: false,
|
|
120
|
+
enableToggleMode: false,
|
|
121
|
+
name: 'params',
|
|
122
|
+
dropSort: false,
|
|
123
|
+
items: [
|
|
124
|
+
{ type: 'text', label: '参数名', name: 'name' },
|
|
125
|
+
{ type: 'text', label: '描述', name: 'extra' },
|
|
126
|
+
paramColConfig || defaultParamColConfig(),
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'content',
|
|
131
|
+
type: 'vs-code',
|
|
132
|
+
options: codeOptions,
|
|
133
|
+
autosize: { minRows: 10, maxRows: 30 },
|
|
134
|
+
...(editable
|
|
135
|
+
? {
|
|
136
|
+
onChange: (_formState: any, code: string) => {
|
|
137
|
+
try {
|
|
138
|
+
// 检测 js 代码是否存在语法错误
|
|
139
|
+
getEditorConfig('parseDSL')(code);
|
|
140
|
+
return code;
|
|
141
|
+
} catch (error: any) {
|
|
142
|
+
tMagicMessage.error(error.message);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
}
|
|
147
|
+
: {}),
|
|
148
|
+
},
|
|
149
|
+
]) as FormConfig;
|
|
150
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computed, markRaw, type ShallowRef } from 'vue';
|
|
2
2
|
import { CopyDocument, Delete, DocumentCopy } from '@element-plus/icons-vue';
|
|
3
3
|
|
|
4
|
-
import { Id, MContainer, NodeType } from '@tmagic/core';
|
|
4
|
+
import { cloneDeep, Id, MContainer, NodeType } from '@tmagic/core';
|
|
5
5
|
import { calcValueByFontsize, isPage, isPageFragment } from '@tmagic/utils';
|
|
6
6
|
|
|
7
7
|
import ContentMenu from '@editor/components/ContentMenu.vue';
|
|
@@ -59,14 +59,17 @@ export const usePasteMenu = (menu?: ShallowRef<InstanceType<typeof ContentMenu>
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
const moveTo = (id: Id, { editorService }: Services) => {
|
|
62
|
+
const moveTo = async (id: Id, { editorService }: Services) => {
|
|
63
63
|
const nodes = editorService.get('nodes') || [];
|
|
64
64
|
const parent = editorService.getNodeById(id) as MContainer;
|
|
65
65
|
|
|
66
|
-
if (!parent) return;
|
|
66
|
+
if (!parent || nodes.length === 0) return;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
// 直接调用 moveToContainer:内部对多选场景已做合并,整批只产生一条历史记录。
|
|
69
|
+
// 不要再走 remove + add 两步,否则会被切成两条历史(且语义也不正确)。
|
|
70
|
+
await editorService.moveToContainer(cloneDeep(nodes), parent.id, {
|
|
71
|
+
doNotSwitchPage: true,
|
|
72
|
+
});
|
|
70
73
|
};
|
|
71
74
|
|
|
72
75
|
export const useMoveToMenu = ({ editorService }: Services): MenuButton => {
|
package/src/utils/dep/worker.ts
CHANGED
|
@@ -42,9 +42,11 @@ onmessage = (e) => {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
// worker 中 target 均为新建(deps 为空),无需删除阶段,直接批量收集
|
|
46
|
+
const targets = watcher.getCollectableTargets();
|
|
47
|
+
for (const page of mApp.items) {
|
|
48
|
+
watcher.collectItems(page, targets, { pageId: page.id }, true);
|
|
49
|
+
}
|
|
48
50
|
|
|
49
51
|
const data: Record<string, Record<Id, DepData>> = {
|
|
50
52
|
[DepTargetType.DATA_SOURCE]: {},
|
package/src/utils/index.ts
CHANGED
package/src/utils/undo-redo.ts
CHANGED
|
@@ -75,5 +75,28 @@ export class UndoRedo<T = any> {
|
|
|
75
75
|
}
|
|
76
76
|
return cloneDeep(this.elementList[this.listCursor - 1]);
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 返回栈内全部元素的浅克隆数组(按时间顺序,索引 0 为最早一步)。
|
|
81
|
+
* 仅用于历史面板等只读展示场景,不应直接修改返回值。
|
|
82
|
+
*/
|
|
83
|
+
public getElementList(): T[] {
|
|
84
|
+
return this.elementList.slice();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 当前游标位置:表示已应用的步骤数量。
|
|
89
|
+
* - cursor === 0 表示全部已撤销
|
|
90
|
+
* - cursor === length 表示已重做到末尾
|
|
91
|
+
* 历史面板用于区分"已应用 / 已撤销"两段。
|
|
92
|
+
*/
|
|
93
|
+
public getCursor(): number {
|
|
94
|
+
return this.listCursor;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 栈内总步数。 */
|
|
98
|
+
public getLength(): number {
|
|
99
|
+
return this.elementList.length;
|
|
100
|
+
}
|
|
78
101
|
}
|
|
79
102
|
// #endregion UndoRedo
|