@tmagic/editor 1.4.6 → 1.4.8
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/style.css +1 -1
- package/dist/tmagic-editor.js +636 -589
- package/dist/tmagic-editor.umd.cjs +634 -586
- package/package.json +15 -11
- package/types/editorProps.d.ts +0 -7
- package/types/layouts/PropsPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
- package/types/services/codeBlock.d.ts +2 -1
- package/types/services/dataSource.d.ts +2 -1
- package/types/services/dep.d.ts +12 -2
- package/types/services/editor.d.ts +22 -4
- package/types/services/props.d.ts +7 -6
- package/types/type.d.ts +6 -0
- package/types/utils/editor.d.ts +1 -0
- package/types/utils/idle-task.d.ts +14 -0
- package/types/utils/operator.d.ts +2 -2
- package/src/Editor.vue +0 -211
- package/src/components/CodeBlockEditor.vue +0 -268
- package/src/components/CodeParams.vue +0 -60
- package/src/components/ContentMenu.vue +0 -193
- package/src/components/FloatingBox.vue +0 -178
- package/src/components/Icon.vue +0 -27
- package/src/components/Resizer.vue +0 -23
- package/src/components/ScrollBar.vue +0 -151
- package/src/components/ScrollViewer.vue +0 -128
- package/src/components/SearchInput.vue +0 -37
- package/src/components/SplitView.vue +0 -186
- package/src/components/ToolButton.vue +0 -138
- package/src/components/Tree.vue +0 -71
- package/src/components/TreeNode.vue +0 -148
- package/src/editorProps.ts +0 -124
- package/src/fields/Code.vue +0 -50
- package/src/fields/CodeLink.vue +0 -80
- package/src/fields/CodeSelect.vue +0 -132
- package/src/fields/CodeSelectCol.vue +0 -139
- package/src/fields/DataSourceFieldSelect.vue +0 -149
- package/src/fields/DataSourceFields.vue +0 -323
- package/src/fields/DataSourceInput.vue +0 -325
- package/src/fields/DataSourceMethodSelect.vue +0 -153
- package/src/fields/DataSourceMethods.vue +0 -104
- package/src/fields/DataSourceMocks.vue +0 -255
- package/src/fields/DataSourceSelect.vue +0 -98
- package/src/fields/EventSelect.vue +0 -301
- package/src/fields/KeyValue.vue +0 -137
- package/src/fields/PageFragmentSelect.vue +0 -63
- package/src/fields/UISelect.vue +0 -135
- package/src/hooks/index.ts +0 -24
- package/src/hooks/use-code-block-edit.ts +0 -83
- package/src/hooks/use-data-source-edit.ts +0 -46
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/hooks/use-editor-content-height.ts +0 -26
- package/src/hooks/use-filter.ts +0 -55
- package/src/hooks/use-float-box.ts +0 -76
- package/src/hooks/use-getso.ts +0 -35
- package/src/hooks/use-next-float-box-position.ts +0 -29
- package/src/hooks/use-node-status.ts +0 -48
- package/src/hooks/use-stage.ts +0 -129
- package/src/hooks/use-window-rect.ts +0 -20
- package/src/icons/AppManageIcon.vue +0 -15
- package/src/icons/CenterIcon.vue +0 -13
- package/src/icons/CodeIcon.vue +0 -28
- package/src/icons/FolderMinusIcon.vue +0 -22
- package/src/icons/PinIcon.vue +0 -25
- package/src/icons/PinnedIcon.vue +0 -25
- package/src/index.ts +0 -118
- package/src/initService.ts +0 -447
- package/src/layouts/AddPageBox.vue +0 -55
- package/src/layouts/CodeEditor.vue +0 -226
- package/src/layouts/Framework.vue +0 -163
- package/src/layouts/NavMenu.vue +0 -200
- package/src/layouts/PropsPanel.vue +0 -130
- package/src/layouts/page-bar/AddButton.vue +0 -48
- package/src/layouts/page-bar/PageBar.vue +0 -159
- package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
- package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
- package/src/layouts/sidebar/Sidebar.vue +0 -278
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
- package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
- package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
- package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
- package/src/layouts/sidebar/layer/use-click.ts +0 -110
- package/src/layouts/sidebar/layer/use-drag.ts +0 -161
- package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
- package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
- package/src/layouts/workspace/Breadcrumb.vue +0 -35
- package/src/layouts/workspace/Workspace.vue +0 -46
- package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
- package/src/layouts/workspace/viewer/Stage.vue +0 -246
- package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
- package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
- package/src/services/BaseService.ts +0 -230
- package/src/services/codeBlock.ts +0 -324
- package/src/services/componentList.ts +0 -58
- package/src/services/dataSource.ts +0 -209
- package/src/services/dep.ts +0 -80
- package/src/services/editor.ts +0 -1087
- package/src/services/events.ts +0 -93
- package/src/services/history.ts +0 -126
- package/src/services/keybinding.ts +0 -220
- package/src/services/props.ts +0 -265
- package/src/services/stageOverlay.ts +0 -212
- package/src/services/storage.ts +0 -155
- package/src/services/ui.ts +0 -156
- package/src/shims-vue.d.ts +0 -6
- package/src/theme/breadcrumb.scss +0 -6
- package/src/theme/code-block.scss +0 -6
- package/src/theme/code-editor.scss +0 -38
- package/src/theme/common/var.scss +0 -14
- package/src/theme/component-list-panel.scss +0 -95
- package/src/theme/content-menu.scss +0 -76
- package/src/theme/data-source-field.scss +0 -12
- package/src/theme/data-source-fields.scss +0 -13
- package/src/theme/data-source-input.scss +0 -18
- package/src/theme/data-source-methods.scss +0 -13
- package/src/theme/data-source.scss +0 -28
- package/src/theme/event.scss +0 -37
- package/src/theme/floating-box.scss +0 -32
- package/src/theme/framework.scss +0 -69
- package/src/theme/icon.scss +0 -12
- package/src/theme/index.scss +0 -10
- package/src/theme/key-value.scss +0 -20
- package/src/theme/layer-panel.scss +0 -26
- package/src/theme/layout.scss +0 -9
- package/src/theme/nav-menu.scss +0 -78
- package/src/theme/page-bar.scss +0 -89
- package/src/theme/page-fragment-select.scss +0 -14
- package/src/theme/props-panel.scss +0 -55
- package/src/theme/resizer.scss +0 -66
- package/src/theme/ruler.scss +0 -38
- package/src/theme/search-input.scss +0 -14
- package/src/theme/sidebar.scss +0 -79
- package/src/theme/stage.scss +0 -76
- package/src/theme/theme.scss +0 -27
- package/src/theme/tree.scss +0 -89
- package/src/theme/workspace.scss +0 -9
- package/src/type.ts +0 -746
- package/src/utils/compose.ts +0 -52
- package/src/utils/config.ts +0 -29
- package/src/utils/content-menu.ts +0 -95
- package/src/utils/data-source/formConfigs/base.ts +0 -30
- package/src/utils/data-source/formConfigs/http.ts +0 -60
- package/src/utils/data-source/index.ts +0 -236
- package/src/utils/editor.ts +0 -294
- package/src/utils/index.ts +0 -24
- package/src/utils/keybinding-config.ts +0 -125
- package/src/utils/logger.ts +0 -47
- package/src/utils/monaco-editor.ts +0 -8
- package/src/utils/operator.ts +0 -106
- package/src/utils/props.ts +0 -504
- package/src/utils/scroll-viewer.ts +0 -165
- package/src/utils/tree.ts +0 -15
- package/src/utils/undo-redo.ts +0 -76
- package/tsconfig.build.json +0 -16
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<Tree :data="list" :node-status-map="nodeStatusMap" @node-click="clickHandler">
|
|
3
|
-
<template #tree-node-label="{ data }">
|
|
4
|
-
<div
|
|
5
|
-
:class="{
|
|
6
|
-
ds: data.type === 'ds',
|
|
7
|
-
hook: data.type === 'key',
|
|
8
|
-
disabled: data.type === 'key' || data.type === 'ds',
|
|
9
|
-
}"
|
|
10
|
-
>
|
|
11
|
-
{{ data.name }} {{ data.key ? `(${data.key})` : '' }}
|
|
12
|
-
</div>
|
|
13
|
-
</template>
|
|
14
|
-
<template #tree-node-tool="{ data }">
|
|
15
|
-
<TMagicTooltip v-if="data.type === 'ds'" effect="dark" :content="editable ? '编辑' : '查看'" placement="bottom">
|
|
16
|
-
<Icon :icon="editable ? Edit : View" class="edit-icon" @click.stop="editHandler(`${data.key}`)"></Icon>
|
|
17
|
-
</TMagicTooltip>
|
|
18
|
-
<TMagicTooltip v-if="data.type === 'ds' && editable" effect="dark" content="删除" placement="bottom">
|
|
19
|
-
<Icon :icon="Close" class="edit-icon" @click.stop="removeHandler(`${data.key}`)"></Icon>
|
|
20
|
-
</TMagicTooltip>
|
|
21
|
-
<slot name="data-source-panel-tool" :data="data"></slot>
|
|
22
|
-
</template>
|
|
23
|
-
</Tree>
|
|
24
|
-
</template>
|
|
25
|
-
|
|
26
|
-
<script lang="ts" setup>
|
|
27
|
-
import { computed, inject } from 'vue';
|
|
28
|
-
import { Close, Edit, View } from '@element-plus/icons-vue';
|
|
29
|
-
|
|
30
|
-
import { DepTargetType } from '@tmagic/dep';
|
|
31
|
-
import { tMagicMessageBox, TMagicTooltip } from '@tmagic/design';
|
|
32
|
-
import { DepData, Id, MNode } from '@tmagic/schema';
|
|
33
|
-
|
|
34
|
-
import Icon from '@editor/components/Icon.vue';
|
|
35
|
-
import Tree from '@editor/components/Tree.vue';
|
|
36
|
-
import { useFilter } from '@editor/hooks/use-filter';
|
|
37
|
-
import { useNodeStatus } from '@editor/hooks/use-node-status';
|
|
38
|
-
import type { DataSourceListSlots, Services } from '@editor/type';
|
|
39
|
-
|
|
40
|
-
defineSlots<DataSourceListSlots>();
|
|
41
|
-
|
|
42
|
-
defineOptions({
|
|
43
|
-
name: 'MEditorDataSourceList',
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const emit = defineEmits<{
|
|
47
|
-
edit: [id: string];
|
|
48
|
-
remove: [id: string];
|
|
49
|
-
}>();
|
|
50
|
-
|
|
51
|
-
const { depService, editorService, dataSourceService } = inject<Services>('services') || {};
|
|
52
|
-
|
|
53
|
-
const editable = computed(() => dataSourceService?.get('editable') ?? true);
|
|
54
|
-
|
|
55
|
-
const dataSources = computed(() => dataSourceService?.get('dataSources') || []);
|
|
56
|
-
|
|
57
|
-
const dsDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE) || {});
|
|
58
|
-
const dsMethodDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_METHOD) || {});
|
|
59
|
-
const dsCondDep = computed(() => depService?.getTargets(DepTargetType.DATA_SOURCE_COND) || {});
|
|
60
|
-
|
|
61
|
-
const getKeyTreeConfig = (dep: DepData[string], type?: string, parentKey?: Id) =>
|
|
62
|
-
dep.keys.map((key) => ({
|
|
63
|
-
name: key,
|
|
64
|
-
id: `${parentKey}_${key}`,
|
|
65
|
-
type: 'key',
|
|
66
|
-
isMethod: type === 'method',
|
|
67
|
-
isCond: type === 'cond',
|
|
68
|
-
}));
|
|
69
|
-
|
|
70
|
-
const getNodeTreeConfig = (id: string, dep: DepData[string], type?: string, parentKey?: Id) => ({
|
|
71
|
-
name: dep.name,
|
|
72
|
-
type: 'node',
|
|
73
|
-
id: `${parentKey}_${id}`,
|
|
74
|
-
key: id,
|
|
75
|
-
items: getKeyTreeConfig(dep, type, `${parentKey}_${id}`),
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 生成tree中依赖节点的数据
|
|
80
|
-
* @param items 节点
|
|
81
|
-
* @param deps 依赖
|
|
82
|
-
* @param type 依赖类型
|
|
83
|
-
*/
|
|
84
|
-
const mergeChildren = (dsId: Id, items: any[], deps: DepData, type?: string) => {
|
|
85
|
-
Object.entries(deps).forEach(([id, dep]) => {
|
|
86
|
-
// 已经生成过的节点
|
|
87
|
-
const nodeItem = items.find((item) => item.key === id);
|
|
88
|
-
// 节点存在,则追加依赖的key
|
|
89
|
-
if (nodeItem) {
|
|
90
|
-
nodeItem.items = nodeItem.items.concat(getKeyTreeConfig(dep, type, nodeItem.key));
|
|
91
|
-
} else {
|
|
92
|
-
// 节点不存在,则生成
|
|
93
|
-
items.push(getNodeTreeConfig(id, dep, type, dsId));
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const list = computed(() =>
|
|
99
|
-
dataSources.value.map((ds) => {
|
|
100
|
-
const dsDeps = dsDep.value[ds.id]?.deps || {};
|
|
101
|
-
const dsMethodDeps = dsMethodDep.value[ds.id]?.deps || {};
|
|
102
|
-
const dsCondDeps = dsCondDep.value[ds.id]?.deps || {};
|
|
103
|
-
|
|
104
|
-
const items: any[] = [];
|
|
105
|
-
// 数据源依赖分为三种类型:key/node、method、cond,是分开存储,这里将其合并展示
|
|
106
|
-
mergeChildren(ds.id, items, dsDeps);
|
|
107
|
-
mergeChildren(ds.id, items, dsMethodDeps, 'method');
|
|
108
|
-
mergeChildren(ds.id, items, dsCondDeps, 'cond');
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
id: ds.id,
|
|
112
|
-
key: ds.id,
|
|
113
|
-
name: ds.title,
|
|
114
|
-
type: 'ds',
|
|
115
|
-
items,
|
|
116
|
-
};
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const filterNode = (value: string, data: MNode): boolean => {
|
|
121
|
-
if (!value) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return `${data.name}${data.id}`.toLocaleLowerCase().includes(value.toLocaleLowerCase());
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const { nodeStatusMap } = useNodeStatus(list);
|
|
128
|
-
const { filterTextChangeHandler } = useFilter(list, nodeStatusMap, filterNode);
|
|
129
|
-
|
|
130
|
-
const editHandler = (id: string) => {
|
|
131
|
-
emit('edit', id);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const removeHandler = async (id: string) => {
|
|
135
|
-
await tMagicMessageBox.confirm('确定删除?', '提示', {
|
|
136
|
-
confirmButtonText: '确定',
|
|
137
|
-
cancelButtonText: '取消',
|
|
138
|
-
type: 'warning',
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
emit('remove', id);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// 选中组件
|
|
145
|
-
const selectComp = (compId: Id) => {
|
|
146
|
-
const stage = editorService?.get('stage');
|
|
147
|
-
editorService?.select(compId);
|
|
148
|
-
stage?.select(compId);
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
const clickHandler = (event: MouseEvent, data: any) => {
|
|
152
|
-
if (data.type === 'node') {
|
|
153
|
-
selectComp(data.key);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
defineExpose({
|
|
158
|
-
filter: filterTextChangeHandler,
|
|
159
|
-
});
|
|
160
|
-
</script>
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicScrollbar class="data-source-list-panel m-editor-layer-panel">
|
|
3
|
-
<div class="search-wrapper">
|
|
4
|
-
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
|
5
|
-
<TMagicPopover v-if="editable" placement="right">
|
|
6
|
-
<template #reference>
|
|
7
|
-
<TMagicButton type="primary" size="small">新增</TMagicButton>
|
|
8
|
-
</template>
|
|
9
|
-
<div class="data-source-list-panel-add-menu">
|
|
10
|
-
<ToolButton
|
|
11
|
-
v-for="(item, index) in datasourceTypeList"
|
|
12
|
-
:data="{
|
|
13
|
-
type: 'button',
|
|
14
|
-
text: item.text,
|
|
15
|
-
handler: () => {
|
|
16
|
-
addHandler(item.type);
|
|
17
|
-
},
|
|
18
|
-
}"
|
|
19
|
-
:key="index"
|
|
20
|
-
></ToolButton>
|
|
21
|
-
</div>
|
|
22
|
-
</TMagicPopover>
|
|
23
|
-
|
|
24
|
-
<slot name="data-source-panel-search"></slot>
|
|
25
|
-
</div>
|
|
26
|
-
|
|
27
|
-
<!-- 数据源列表 -->
|
|
28
|
-
<DataSourceList ref="dataSourceList" @edit="editHandler" @remove="removeHandler"></DataSourceList>
|
|
29
|
-
</TMagicScrollbar>
|
|
30
|
-
|
|
31
|
-
<DataSourceConfigPanel
|
|
32
|
-
ref="editDialog"
|
|
33
|
-
:disabled="!editable"
|
|
34
|
-
:values="dataSourceValues"
|
|
35
|
-
:title="dialogTitle"
|
|
36
|
-
@submit="submitDataSourceHandler"
|
|
37
|
-
></DataSourceConfigPanel>
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
<script setup lang="ts">
|
|
41
|
-
import { computed, inject, ref } from 'vue';
|
|
42
|
-
import { mergeWith } from 'lodash-es';
|
|
43
|
-
|
|
44
|
-
import { TMagicButton, TMagicPopover, TMagicScrollbar } from '@tmagic/design';
|
|
45
|
-
|
|
46
|
-
import SearchInput from '@editor/components/SearchInput.vue';
|
|
47
|
-
import ToolButton from '@editor/components/ToolButton.vue';
|
|
48
|
-
import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
|
|
49
|
-
import type { DataSourceListSlots, EventBus, Services } from '@editor/type';
|
|
50
|
-
|
|
51
|
-
import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
|
|
52
|
-
import DataSourceList from './DataSourceList.vue';
|
|
53
|
-
|
|
54
|
-
defineSlots<DataSourceListSlots>();
|
|
55
|
-
|
|
56
|
-
defineOptions({
|
|
57
|
-
name: 'MEditorDataSourceListPanel',
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const eventBus = inject<EventBus>('eventBus');
|
|
61
|
-
const { dataSourceService } = inject<Services>('services') || {};
|
|
62
|
-
|
|
63
|
-
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
|
64
|
-
useDataSourceEdit(dataSourceService);
|
|
65
|
-
|
|
66
|
-
const datasourceTypeList = computed(() =>
|
|
67
|
-
[
|
|
68
|
-
{ text: '基础', type: 'base' },
|
|
69
|
-
{ text: 'HTTP', type: 'http' },
|
|
70
|
-
].concat(dataSourceService?.get('datasourceTypeList') ?? []),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const addHandler = (type: string) => {
|
|
74
|
-
if (!editDialog.value) return;
|
|
75
|
-
|
|
76
|
-
const datasourceType = datasourceTypeList.value.find((item) => item.type === type);
|
|
77
|
-
|
|
78
|
-
dataSourceValues.value = mergeWith(
|
|
79
|
-
{ type, title: datasourceType?.text },
|
|
80
|
-
dataSourceService?.getFormValue(type) || {},
|
|
81
|
-
(objValue, srcValue) => {
|
|
82
|
-
if (Array.isArray(srcValue)) {
|
|
83
|
-
return srcValue;
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
dialogTitle.value = `新增${datasourceType?.text || ''}`;
|
|
89
|
-
|
|
90
|
-
editDialog.value.show();
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const removeHandler = (id: string) => {
|
|
94
|
-
dataSourceService?.remove(id);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const dataSourceList = ref<InstanceType<typeof DataSourceList>>();
|
|
98
|
-
|
|
99
|
-
const filterTextChangeHandler = (val: string) => {
|
|
100
|
-
dataSourceList.value?.filter(val);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
eventBus?.on('edit-data-source', (id: string) => {
|
|
104
|
-
editHandler(id);
|
|
105
|
-
});
|
|
106
|
-
</script>
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<ContentMenu :menu-data="menuData" ref="menu" style="overflow: initial"></ContentMenu>
|
|
3
|
-
</template>
|
|
4
|
-
|
|
5
|
-
<script lang="ts" setup>
|
|
6
|
-
import { computed, inject, markRaw, ref } from 'vue';
|
|
7
|
-
import { Files, Plus } from '@element-plus/icons-vue';
|
|
8
|
-
|
|
9
|
-
import { isPage, isPageFragment } from '@tmagic/utils';
|
|
10
|
-
|
|
11
|
-
import ContentMenu from '@editor/components/ContentMenu.vue';
|
|
12
|
-
import FolderMinusIcon from '@editor/icons/FolderMinusIcon.vue';
|
|
13
|
-
import type { ComponentGroup, MenuButton, MenuComponent, Services } from '@editor/type';
|
|
14
|
-
import { useCopyMenu, useDeleteMenu, useMoveToMenu, usePasteMenu } from '@editor/utils/content-menu';
|
|
15
|
-
|
|
16
|
-
defineOptions({
|
|
17
|
-
name: 'MEditorLayerMenu',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const props = withDefaults(
|
|
21
|
-
defineProps<{
|
|
22
|
-
layerContentMenu: (MenuButton | MenuComponent)[];
|
|
23
|
-
customContentMenu?: (menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[];
|
|
24
|
-
}>(),
|
|
25
|
-
{
|
|
26
|
-
layerContentMenu: () => [],
|
|
27
|
-
customContentMenu: (menus: (MenuButton | MenuComponent)[]) => menus,
|
|
28
|
-
},
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const emit = defineEmits<{
|
|
32
|
-
'collapse-all': [];
|
|
33
|
-
}>();
|
|
34
|
-
|
|
35
|
-
const services = inject<Services>('services');
|
|
36
|
-
const menu = ref<InstanceType<typeof ContentMenu>>();
|
|
37
|
-
const node = computed(() => services?.editorService.get('node'));
|
|
38
|
-
const nodes = computed(() => services?.editorService.get('nodes'));
|
|
39
|
-
const componentList = computed(() => services?.componentListService.getList() || []);
|
|
40
|
-
|
|
41
|
-
const createMenuItems = (group: ComponentGroup): MenuButton[] =>
|
|
42
|
-
group.items.map((component) => ({
|
|
43
|
-
text: component.text,
|
|
44
|
-
type: 'button',
|
|
45
|
-
icon: component.icon,
|
|
46
|
-
handler: () => {
|
|
47
|
-
services?.editorService.add({
|
|
48
|
-
name: component.text,
|
|
49
|
-
type: component.type,
|
|
50
|
-
...(component.data || {}),
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
}));
|
|
54
|
-
|
|
55
|
-
const getSubMenuData = computed<MenuButton[]>(() => {
|
|
56
|
-
if (node.value?.type === 'tabs') {
|
|
57
|
-
return [
|
|
58
|
-
{
|
|
59
|
-
text: '标签页',
|
|
60
|
-
type: 'button',
|
|
61
|
-
icon: Files,
|
|
62
|
-
handler: () => {
|
|
63
|
-
services?.editorService.add({
|
|
64
|
-
type: 'tab-pane',
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
}
|
|
70
|
-
if (node.value?.items) {
|
|
71
|
-
return (
|
|
72
|
-
componentList.value.reduce(
|
|
73
|
-
(subMenuData: MenuButton[], group: ComponentGroup, index) =>
|
|
74
|
-
subMenuData.concat(
|
|
75
|
-
createMenuItems(group),
|
|
76
|
-
index < componentList.value.length - 1
|
|
77
|
-
? [
|
|
78
|
-
{
|
|
79
|
-
type: 'divider',
|
|
80
|
-
direction: 'horizontal',
|
|
81
|
-
},
|
|
82
|
-
]
|
|
83
|
-
: [],
|
|
84
|
-
),
|
|
85
|
-
[],
|
|
86
|
-
) || []
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
return [];
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
const menuData = computed<(MenuButton | MenuComponent)[]>(() =>
|
|
93
|
-
props.customContentMenu(
|
|
94
|
-
[
|
|
95
|
-
{
|
|
96
|
-
type: 'button',
|
|
97
|
-
text: '全部折叠',
|
|
98
|
-
icon: FolderMinusIcon,
|
|
99
|
-
display: () => isPage(node.value) || isPageFragment(node.value),
|
|
100
|
-
handler: () => {
|
|
101
|
-
emit('collapse-all');
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
type: 'button',
|
|
106
|
-
text: '新增',
|
|
107
|
-
icon: markRaw(Plus),
|
|
108
|
-
display: () => node.value?.items && nodes.value?.length === 1,
|
|
109
|
-
items: getSubMenuData.value,
|
|
110
|
-
},
|
|
111
|
-
useCopyMenu(),
|
|
112
|
-
usePasteMenu(),
|
|
113
|
-
useDeleteMenu(),
|
|
114
|
-
useMoveToMenu(services),
|
|
115
|
-
...props.layerContentMenu,
|
|
116
|
-
],
|
|
117
|
-
'layer',
|
|
118
|
-
),
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
const show = (e: MouseEvent) => {
|
|
122
|
-
menu.value?.show(e);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
defineExpose({
|
|
126
|
-
show,
|
|
127
|
-
});
|
|
128
|
-
</script>
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<template v-if="data.type !== 'page'">
|
|
3
|
-
<MIcon v-if="data.visible === false" :icon="Hide" @click.stop="setNodeVisible(true)" title="点击显示"></MIcon>
|
|
4
|
-
<MIcon v-else :icon="View" @click.stop="setNodeVisible(false)" class="node-lock" title="点击隐藏"></MIcon>
|
|
5
|
-
</template>
|
|
6
|
-
</template>
|
|
7
|
-
|
|
8
|
-
<script setup lang="ts">
|
|
9
|
-
import { inject } from 'vue';
|
|
10
|
-
import { Hide, View } from '@element-plus/icons-vue';
|
|
11
|
-
|
|
12
|
-
import type { MNode } from '@tmagic/schema';
|
|
13
|
-
|
|
14
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
15
|
-
import { Services } from '@editor/type';
|
|
16
|
-
|
|
17
|
-
const props = defineProps<{
|
|
18
|
-
data: MNode;
|
|
19
|
-
}>();
|
|
20
|
-
|
|
21
|
-
const services = inject<Services>('services');
|
|
22
|
-
const editorService = services?.editorService;
|
|
23
|
-
|
|
24
|
-
const setNodeVisible = (visible: boolean) => {
|
|
25
|
-
if (!editorService) return;
|
|
26
|
-
|
|
27
|
-
editorService.update({
|
|
28
|
-
id: props.data.id,
|
|
29
|
-
visible,
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
</script>
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicScrollbar class="m-editor-layer-panel">
|
|
3
|
-
<slot name="layer-panel-header"></slot>
|
|
4
|
-
|
|
5
|
-
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
|
6
|
-
|
|
7
|
-
<Tree
|
|
8
|
-
v-if="page && nodeStatusMap"
|
|
9
|
-
tabindex="-1"
|
|
10
|
-
ref="tree"
|
|
11
|
-
:data="nodeData"
|
|
12
|
-
:node-status-map="nodeStatusMap"
|
|
13
|
-
@node-dragover="handleDragOver"
|
|
14
|
-
@node-dragstart="handleDragStart"
|
|
15
|
-
@node-dragleave="handleDragLeave"
|
|
16
|
-
@node-dragend="handleDragEnd"
|
|
17
|
-
@node-contextmenu="nodeContentMenuHandler"
|
|
18
|
-
@node-mouseenter="mouseenterHandler"
|
|
19
|
-
@node-click="nodeClickHandler"
|
|
20
|
-
>
|
|
21
|
-
<template #tree-node-content="{ data: nodeData }">
|
|
22
|
-
<slot name="layer-node-content" :data="nodeData"> </slot>
|
|
23
|
-
</template>
|
|
24
|
-
|
|
25
|
-
<template #tree-node-tool="{ data: nodeData }">
|
|
26
|
-
<slot name="layer-node-tool" :data="nodeData">
|
|
27
|
-
<LayerNodeTool :data="nodeData"></LayerNodeTool>
|
|
28
|
-
</slot>
|
|
29
|
-
</template>
|
|
30
|
-
|
|
31
|
-
<template #tree-node-label="{ data: nodeData }">
|
|
32
|
-
<slot name="layer-node-label" :data="nodeData"></slot>
|
|
33
|
-
</template>
|
|
34
|
-
</Tree>
|
|
35
|
-
|
|
36
|
-
<Teleport to="body">
|
|
37
|
-
<LayerMenu
|
|
38
|
-
ref="menu"
|
|
39
|
-
:layer-content-menu="layerContentMenu"
|
|
40
|
-
:custom-content-menu="customContentMenu"
|
|
41
|
-
@collapse-all="collapseAllHandler"
|
|
42
|
-
></LayerMenu>
|
|
43
|
-
</Teleport>
|
|
44
|
-
</TMagicScrollbar>
|
|
45
|
-
</template>
|
|
46
|
-
|
|
47
|
-
<script setup lang="ts">
|
|
48
|
-
import { computed, inject, ref } from 'vue';
|
|
49
|
-
|
|
50
|
-
import { TMagicScrollbar } from '@tmagic/design';
|
|
51
|
-
import type { MNode } from '@tmagic/schema';
|
|
52
|
-
|
|
53
|
-
import SearchInput from '@editor/components/SearchInput.vue';
|
|
54
|
-
import Tree from '@editor/components/Tree.vue';
|
|
55
|
-
import { useFilter } from '@editor/hooks/use-filter';
|
|
56
|
-
import { LayerPanelSlots, MenuButton, MenuComponent, Services, TreeNodeData } from '@editor/type';
|
|
57
|
-
|
|
58
|
-
import LayerMenu from './LayerMenu.vue';
|
|
59
|
-
import LayerNodeTool from './LayerNodeTool.vue';
|
|
60
|
-
import { useClick } from './use-click';
|
|
61
|
-
import { useDrag } from './use-drag';
|
|
62
|
-
import { useKeybinding } from './use-keybinding';
|
|
63
|
-
import { useNodeStatus } from './use-node-status';
|
|
64
|
-
|
|
65
|
-
defineSlots<LayerPanelSlots>();
|
|
66
|
-
|
|
67
|
-
defineOptions({
|
|
68
|
-
name: 'MEditorLayerPanel',
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
defineProps<{
|
|
72
|
-
layerContentMenu: (MenuButton | MenuComponent)[];
|
|
73
|
-
customContentMenu?: (menus: (MenuButton | MenuComponent)[], type: string) => (MenuButton | MenuComponent)[];
|
|
74
|
-
}>();
|
|
75
|
-
|
|
76
|
-
const services = inject<Services>('services');
|
|
77
|
-
const editorService = services?.editorService;
|
|
78
|
-
|
|
79
|
-
const tree = ref<InstanceType<typeof Tree>>();
|
|
80
|
-
|
|
81
|
-
const page = computed(() => editorService?.get('page'));
|
|
82
|
-
const nodeData = computed<TreeNodeData[]>(() => (!page.value ? [] : [page.value]));
|
|
83
|
-
|
|
84
|
-
const { nodeStatusMap } = useNodeStatus(services);
|
|
85
|
-
const { isCtrlKeyDown } = useKeybinding(services, tree);
|
|
86
|
-
|
|
87
|
-
const filterNodeMethod = (v: string, data: MNode): boolean => {
|
|
88
|
-
let name = '';
|
|
89
|
-
if (data.name) {
|
|
90
|
-
name = data.name;
|
|
91
|
-
} else if (data.items) {
|
|
92
|
-
name = 'container';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return `${data.id}${name}${data.type}`.includes(v);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const { filterTextChangeHandler } = useFilter(nodeData, nodeStatusMap, filterNodeMethod);
|
|
99
|
-
|
|
100
|
-
const collapseAllHandler = () => {
|
|
101
|
-
if (!page.value || !nodeStatusMap.value) return;
|
|
102
|
-
const items = nodeStatusMap.value.entries();
|
|
103
|
-
for (const [id, status] of items) {
|
|
104
|
-
if (id === page.value.id) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
status.expand = false;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const { handleDragStart, handleDragEnd, handleDragLeave, handleDragOver } = useDrag(services);
|
|
112
|
-
|
|
113
|
-
const {
|
|
114
|
-
menu,
|
|
115
|
-
nodeClickHandler,
|
|
116
|
-
nodeContentMenuHandler,
|
|
117
|
-
highlightHandler: mouseenterHandler,
|
|
118
|
-
} = useClick(services, isCtrlKeyDown, nodeStatusMap);
|
|
119
|
-
</script>
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { computed, type ComputedRef, nextTick, type Ref, ref } from 'vue';
|
|
2
|
-
import { throttle } from 'lodash-es';
|
|
3
|
-
|
|
4
|
-
import { Id, MNode } from '@tmagic/schema';
|
|
5
|
-
|
|
6
|
-
import { LayerNodeStatus, Services, TreeNodeData, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
|
|
7
|
-
import { updateStatus } from '@editor/utils/tree';
|
|
8
|
-
|
|
9
|
-
import LayerMenu from './LayerMenu.vue';
|
|
10
|
-
|
|
11
|
-
export const useClick = (
|
|
12
|
-
services: Services | undefined,
|
|
13
|
-
isCtrlKeyDown: Ref<boolean>,
|
|
14
|
-
nodeStatusMap: ComputedRef<Map<Id, LayerNodeStatus> | undefined>,
|
|
15
|
-
) => {
|
|
16
|
-
const isMultiSelect = computed(() => isCtrlKeyDown.value && !services?.editorService.get('disabledMultiSelect'));
|
|
17
|
-
|
|
18
|
-
// 触发画布选中
|
|
19
|
-
const select = async (data: MNode) => {
|
|
20
|
-
if (!data.id) {
|
|
21
|
-
throw new Error('没有id');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (isMultiSelect.value) {
|
|
25
|
-
multiSelect(data);
|
|
26
|
-
} else {
|
|
27
|
-
await services?.editorService.select(data);
|
|
28
|
-
services?.editorService.get('stage')?.select(data.id);
|
|
29
|
-
services?.stageOverlayService.get('stage')?.select(data.id);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const multiSelect = async (data: MNode) => {
|
|
34
|
-
const nodes = services?.editorService.get('nodes') || [];
|
|
35
|
-
|
|
36
|
-
const newNodes: Id[] = [];
|
|
37
|
-
let isCancel = false;
|
|
38
|
-
nodes.forEach((node) => {
|
|
39
|
-
if (node.id === data.id) {
|
|
40
|
-
isCancel = true;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
newNodes.push(node.id);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
// 只剩一个不能取消选中
|
|
48
|
-
if (!isCancel || newNodes.length === 0) {
|
|
49
|
-
newNodes.push(data.id);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await services?.editorService.multiSelect(newNodes);
|
|
53
|
-
services?.editorService.get('stage')?.multiSelect(newNodes);
|
|
54
|
-
services?.stageOverlayService.get('stage')?.multiSelect(newNodes);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const throttleTime = 300;
|
|
58
|
-
// 鼠标在组件树移动触发高亮
|
|
59
|
-
const highlightHandler = throttle((event: MouseEvent, data: TreeNodeData) => {
|
|
60
|
-
highlight(data);
|
|
61
|
-
}, throttleTime);
|
|
62
|
-
|
|
63
|
-
// 触发画布高亮
|
|
64
|
-
const highlight = (data: TreeNodeData) => {
|
|
65
|
-
services?.editorService?.highlight(data);
|
|
66
|
-
services?.editorService?.get('stage')?.highlight(data.id);
|
|
67
|
-
services?.stageOverlayService?.get('stage')?.highlight(data.id);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const nodeClickHandler = (event: MouseEvent, data: TreeNodeData) => {
|
|
71
|
-
if (!nodeStatusMap?.value) return;
|
|
72
|
-
|
|
73
|
-
if (services?.uiService.get('uiSelectMode')) {
|
|
74
|
-
document.dispatchEvent(new CustomEvent(UI_SELECT_MODE_EVENT_NAME, { detail: data }));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (data.items && data.items.length > 0 && !isMultiSelect.value) {
|
|
79
|
-
updateStatus(nodeStatusMap.value, data.id, {
|
|
80
|
-
expand: true,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
nextTick(() => {
|
|
85
|
-
select(data);
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// 右键菜单
|
|
90
|
-
const menu = ref<InstanceType<typeof LayerMenu>>();
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
menu,
|
|
94
|
-
|
|
95
|
-
nodeClickHandler,
|
|
96
|
-
|
|
97
|
-
nodeContentMenuHandler(event: MouseEvent, data: TreeNodeData) {
|
|
98
|
-
event.preventDefault();
|
|
99
|
-
|
|
100
|
-
const nodes = services?.editorService.get('nodes') || [];
|
|
101
|
-
if (nodes.length < 2 || !nodes.includes(data)) {
|
|
102
|
-
nodeClickHandler(event, data);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
menu.value?.show(event);
|
|
106
|
-
},
|
|
107
|
-
|
|
108
|
-
highlightHandler,
|
|
109
|
-
};
|
|
110
|
-
};
|