@tmagic/editor 1.4.8 → 1.4.9
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/package.json +11 -11
- package/src/Editor.vue +211 -0
- package/src/components/CodeBlockEditor.vue +268 -0
- package/src/components/CodeParams.vue +60 -0
- package/src/components/ContentMenu.vue +193 -0
- package/src/components/FloatingBox.vue +178 -0
- package/src/components/Icon.vue +27 -0
- package/src/components/Resizer.vue +23 -0
- package/src/components/ScrollBar.vue +151 -0
- package/src/components/ScrollViewer.vue +128 -0
- package/src/components/SearchInput.vue +37 -0
- package/src/components/SplitView.vue +186 -0
- package/src/components/ToolButton.vue +138 -0
- package/src/components/Tree.vue +71 -0
- package/src/components/TreeNode.vue +150 -0
- package/src/editorProps.ts +117 -0
- package/src/fields/Code.vue +50 -0
- package/src/fields/CodeLink.vue +80 -0
- package/src/fields/CodeSelect.vue +132 -0
- package/src/fields/CodeSelectCol.vue +139 -0
- package/src/fields/DataSourceFieldSelect.vue +149 -0
- package/src/fields/DataSourceFields.vue +323 -0
- package/src/fields/DataSourceInput.vue +339 -0
- package/src/fields/DataSourceMethodSelect.vue +153 -0
- package/src/fields/DataSourceMethods.vue +104 -0
- package/src/fields/DataSourceMocks.vue +255 -0
- package/src/fields/DataSourceSelect.vue +98 -0
- package/src/fields/EventSelect.vue +375 -0
- package/src/fields/KeyValue.vue +137 -0
- package/src/fields/PageFragmentSelect.vue +63 -0
- package/src/fields/UISelect.vue +135 -0
- package/src/hooks/index.ts +24 -0
- package/src/hooks/use-code-block-edit.ts +83 -0
- package/src/hooks/use-data-source-edit.ts +46 -0
- package/src/hooks/use-data-source-method.ts +100 -0
- package/src/hooks/use-editor-content-height.ts +26 -0
- package/src/hooks/use-filter.ts +55 -0
- package/src/hooks/use-float-box.ts +76 -0
- package/src/hooks/use-getso.ts +35 -0
- package/src/hooks/use-next-float-box-position.ts +29 -0
- package/src/hooks/use-node-status.ts +48 -0
- package/src/hooks/use-stage.ts +129 -0
- package/src/hooks/use-window-rect.ts +20 -0
- package/src/icons/AppManageIcon.vue +15 -0
- package/src/icons/CenterIcon.vue +13 -0
- package/src/icons/CodeIcon.vue +28 -0
- package/src/icons/FolderMinusIcon.vue +22 -0
- package/src/icons/PinIcon.vue +25 -0
- package/src/icons/PinnedIcon.vue +25 -0
- package/src/index.ts +118 -0
- package/src/initService.ts +448 -0
- package/src/layouts/AddPageBox.vue +55 -0
- package/src/layouts/CodeEditor.vue +226 -0
- package/src/layouts/Framework.vue +163 -0
- package/src/layouts/NavMenu.vue +200 -0
- package/src/layouts/PropsPanel.vue +131 -0
- package/src/layouts/page-bar/AddButton.vue +48 -0
- package/src/layouts/page-bar/PageBar.vue +159 -0
- package/src/layouts/page-bar/PageBarScrollContainer.vue +156 -0
- package/src/layouts/page-bar/SwitchTypeButton.vue +45 -0
- package/src/layouts/sidebar/ComponentListPanel.vue +134 -0
- package/src/layouts/sidebar/Sidebar.vue +278 -0
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +160 -0
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +70 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +84 -0
- package/src/layouts/sidebar/data-source/DataSourceList.vue +172 -0
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +106 -0
- package/src/layouts/sidebar/layer/LayerMenu.vue +128 -0
- package/src/layouts/sidebar/layer/LayerNodeTool.vue +32 -0
- package/src/layouts/sidebar/layer/LayerPanel.vue +119 -0
- package/src/layouts/sidebar/layer/use-click.ts +113 -0
- package/src/layouts/sidebar/layer/use-drag.ts +167 -0
- package/src/layouts/sidebar/layer/use-keybinding.ts +54 -0
- package/src/layouts/sidebar/layer/use-node-status.ts +114 -0
- package/src/layouts/workspace/Breadcrumb.vue +35 -0
- package/src/layouts/workspace/Workspace.vue +46 -0
- package/src/layouts/workspace/viewer/NodeListMenu.vue +115 -0
- package/src/layouts/workspace/viewer/Stage.vue +246 -0
- package/src/layouts/workspace/viewer/StageOverlay.vue +68 -0
- package/src/layouts/workspace/viewer/ViewerMenu.vue +145 -0
- package/src/services/BaseService.ts +230 -0
- package/src/services/codeBlock.ts +327 -0
- package/src/services/componentList.ts +58 -0
- package/src/services/dataSource.ts +216 -0
- package/src/services/dep.ts +152 -0
- package/src/services/editor.ts +1135 -0
- package/src/services/events.ts +93 -0
- package/src/services/history.ts +126 -0
- package/src/services/keybinding.ts +220 -0
- package/src/services/props.ts +286 -0
- package/src/services/stageOverlay.ts +212 -0
- package/src/services/storage.ts +155 -0
- package/src/services/ui.ts +156 -0
- package/src/shims-vue.d.ts +6 -0
- package/src/theme/breadcrumb.scss +6 -0
- package/src/theme/code-block.scss +6 -0
- package/src/theme/code-editor.scss +38 -0
- package/src/theme/common/var.scss +14 -0
- package/src/theme/component-list-panel.scss +95 -0
- package/src/theme/content-menu.scss +76 -0
- package/src/theme/data-source-field.scss +12 -0
- package/src/theme/data-source-fields.scss +13 -0
- package/src/theme/data-source-input.scss +18 -0
- package/src/theme/data-source-methods.scss +13 -0
- package/src/theme/data-source.scss +28 -0
- package/src/theme/event.scss +37 -0
- package/src/theme/floating-box.scss +32 -0
- package/src/theme/framework.scss +69 -0
- package/src/theme/icon.scss +12 -0
- package/src/theme/index.scss +10 -0
- package/src/theme/key-value.scss +20 -0
- package/src/theme/layer-panel.scss +26 -0
- package/src/theme/layout.scss +9 -0
- package/src/theme/nav-menu.scss +78 -0
- package/src/theme/page-bar.scss +89 -0
- package/src/theme/page-fragment-select.scss +14 -0
- package/src/theme/props-panel.scss +55 -0
- package/src/theme/resizer.scss +66 -0
- package/src/theme/ruler.scss +38 -0
- package/src/theme/search-input.scss +14 -0
- package/src/theme/sidebar.scss +79 -0
- package/src/theme/stage.scss +76 -0
- package/src/theme/theme.scss +27 -0
- package/src/theme/tree.scss +89 -0
- package/src/theme/workspace.scss +9 -0
- package/src/type.ts +749 -0
- package/src/utils/compose.ts +52 -0
- package/src/utils/config.ts +29 -0
- package/src/utils/content-menu.ts +95 -0
- package/src/utils/data-source/formConfigs/base.ts +30 -0
- package/src/utils/data-source/formConfigs/http.ts +60 -0
- package/src/utils/data-source/index.ts +243 -0
- package/src/utils/editor.ts +313 -0
- package/src/utils/idle-task.ts +72 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/keybinding-config.ts +125 -0
- package/src/utils/logger.ts +47 -0
- package/src/utils/monaco-editor.ts +8 -0
- package/src/utils/operator.ts +106 -0
- package/src/utils/props.ts +504 -0
- package/src/utils/scroll-viewer.ts +165 -0
- package/src/utils/tree.ts +15 -0
- package/src/utils/undo-redo.ts +76 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2023 THL A29 Limited, a Tencent company. 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
|
+
export * from './use-code-block-edit';
|
|
20
|
+
export * from './use-data-source-method';
|
|
21
|
+
export * from './use-stage';
|
|
22
|
+
export * from './use-float-box';
|
|
23
|
+
export * from './use-window-rect';
|
|
24
|
+
export * from './use-editor-content-height';
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { nextTick, ref } from 'vue';
|
|
2
|
+
import { cloneDeep } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
5
|
+
import type { CodeBlockContent } from '@tmagic/schema';
|
|
6
|
+
|
|
7
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
8
|
+
import type { CodeBlockService } from '@editor/services/codeBlock';
|
|
9
|
+
|
|
10
|
+
export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|
11
|
+
const codeConfig = ref<CodeBlockContent>();
|
|
12
|
+
const codeId = ref<string>();
|
|
13
|
+
const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
|
|
14
|
+
|
|
15
|
+
// 新增代码块
|
|
16
|
+
const createCodeBlock = async () => {
|
|
17
|
+
if (!codeBlockService) {
|
|
18
|
+
tMagicMessage.error('新增代码块失败');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
codeConfig.value = {
|
|
23
|
+
name: '',
|
|
24
|
+
content: `({app, params}) => {\n // place your code here\n}`,
|
|
25
|
+
params: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
codeId.value = await codeBlockService.getUniqueId();
|
|
29
|
+
|
|
30
|
+
await nextTick();
|
|
31
|
+
|
|
32
|
+
codeBlockEditor.value?.show();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// 编辑代码块
|
|
36
|
+
const editCode = async (id: string) => {
|
|
37
|
+
const codeBlock = await codeBlockService?.getCodeContentById(id);
|
|
38
|
+
|
|
39
|
+
if (!codeBlock) {
|
|
40
|
+
tMagicMessage.error('获取代码块内容失败');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let codeContent = codeBlock.content;
|
|
45
|
+
|
|
46
|
+
if (typeof codeContent !== 'string') {
|
|
47
|
+
codeContent = codeContent.toString();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
codeConfig.value = {
|
|
51
|
+
...cloneDeep(codeBlock),
|
|
52
|
+
content: codeContent,
|
|
53
|
+
};
|
|
54
|
+
codeId.value = id;
|
|
55
|
+
|
|
56
|
+
await nextTick();
|
|
57
|
+
codeBlockEditor.value?.show();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// 删除代码块
|
|
61
|
+
const deleteCode = async (key: string) => {
|
|
62
|
+
codeBlockService?.deleteCodeDslByIds([key]);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const submitCodeBlockHandler = async (values: CodeBlockContent) => {
|
|
66
|
+
if (!codeId.value) return;
|
|
67
|
+
|
|
68
|
+
await codeBlockService?.setCodeDslById(codeId.value, values);
|
|
69
|
+
|
|
70
|
+
codeBlockEditor.value?.hide();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
codeId,
|
|
75
|
+
codeConfig,
|
|
76
|
+
codeBlockEditor,
|
|
77
|
+
|
|
78
|
+
createCodeBlock,
|
|
79
|
+
editCode,
|
|
80
|
+
deleteCode,
|
|
81
|
+
submitCodeBlockHandler,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { computed, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { DataSourceSchema } from '@tmagic/schema';
|
|
4
|
+
|
|
5
|
+
import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
|
|
6
|
+
import type { DataSourceService } from '@editor/services/dataSource';
|
|
7
|
+
|
|
8
|
+
export const useDataSourceEdit = (dataSourceService?: DataSourceService) => {
|
|
9
|
+
const dialogTitle = ref('');
|
|
10
|
+
const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
|
|
11
|
+
const dataSourceValues = ref<Record<string, any>>({});
|
|
12
|
+
|
|
13
|
+
const editable = computed(() => dataSourceService?.get('editable') ?? true);
|
|
14
|
+
|
|
15
|
+
const editHandler = (id: string) => {
|
|
16
|
+
if (!editDialog.value) return;
|
|
17
|
+
|
|
18
|
+
dataSourceValues.value = {
|
|
19
|
+
...dataSourceService?.getDataSourceById(id),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
dialogTitle.value = `编辑${dataSourceValues.value.title || ''}`;
|
|
23
|
+
|
|
24
|
+
editDialog.value.show();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const submitDataSourceHandler = (value: DataSourceSchema) => {
|
|
28
|
+
if (value.id) {
|
|
29
|
+
dataSourceService?.update(value);
|
|
30
|
+
} else {
|
|
31
|
+
dataSourceService?.add(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
editDialog.value?.hide();
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
dialogTitle,
|
|
39
|
+
editDialog,
|
|
40
|
+
dataSourceValues,
|
|
41
|
+
editable,
|
|
42
|
+
|
|
43
|
+
editHandler,
|
|
44
|
+
submitDataSourceHandler,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { nextTick, ref } from 'vue';
|
|
2
|
+
import { cloneDeep } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
import { tMagicMessage } from '@tmagic/design';
|
|
5
|
+
import type { CodeBlockContent, DataSourceSchema } from '@tmagic/schema';
|
|
6
|
+
|
|
7
|
+
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
8
|
+
import { getConfig } from '@editor/utils/config';
|
|
9
|
+
|
|
10
|
+
export const useDataSourceMethod = () => {
|
|
11
|
+
const codeConfig = ref<CodeBlockContent>();
|
|
12
|
+
const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
|
|
13
|
+
|
|
14
|
+
const dataSource = ref<DataSourceSchema>();
|
|
15
|
+
const dataSourceMethod = ref('');
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
codeConfig,
|
|
19
|
+
codeBlockEditor,
|
|
20
|
+
|
|
21
|
+
createCode: async (model: DataSourceSchema) => {
|
|
22
|
+
codeConfig.value = {
|
|
23
|
+
name: '',
|
|
24
|
+
content: `({ params, dataSource, app }) => {\n // place your code here\n}`,
|
|
25
|
+
params: [],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
await nextTick();
|
|
29
|
+
|
|
30
|
+
dataSource.value = model;
|
|
31
|
+
dataSourceMethod.value = '';
|
|
32
|
+
|
|
33
|
+
codeBlockEditor.value?.show();
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
editCode: async (model: DataSourceSchema, methodName: string) => {
|
|
37
|
+
const method = model.methods?.find((method) => method.name === methodName);
|
|
38
|
+
|
|
39
|
+
if (!method) {
|
|
40
|
+
tMagicMessage.error('获取数据源方法失败');
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let codeContent = method.content;
|
|
45
|
+
|
|
46
|
+
if (typeof codeContent !== 'string') {
|
|
47
|
+
codeContent = codeContent.toString();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
codeConfig.value = {
|
|
51
|
+
...cloneDeep(method),
|
|
52
|
+
content: codeContent,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
await nextTick();
|
|
56
|
+
|
|
57
|
+
dataSource.value = model;
|
|
58
|
+
dataSourceMethod.value = methodName;
|
|
59
|
+
|
|
60
|
+
codeBlockEditor.value?.show();
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
deleteCode: async (model: DataSourceSchema, methodName: string) => {
|
|
64
|
+
if (!model.methods) return;
|
|
65
|
+
|
|
66
|
+
const index = model.methods.findIndex((method) => method.name === methodName);
|
|
67
|
+
|
|
68
|
+
if (index === -1) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
model.methods.splice(index, 1);
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
submitCode: (values: CodeBlockContent) => {
|
|
76
|
+
if (!dataSource.value) return;
|
|
77
|
+
|
|
78
|
+
if (!dataSource.value.methods) {
|
|
79
|
+
dataSource.value.methods = [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (values.content) {
|
|
83
|
+
// 在保存的时候转换代码内容
|
|
84
|
+
const parseDSL = getConfig('parseDSL');
|
|
85
|
+
if (typeof values.content === 'string') {
|
|
86
|
+
values.content = parseDSL<(...args: any[]) => any>(values.content);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (dataSourceMethod.value) {
|
|
91
|
+
const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
|
|
92
|
+
dataSource.value.methods.splice(index, 1, values);
|
|
93
|
+
} else {
|
|
94
|
+
dataSource.value.methods.push(values);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
codeBlockEditor.value?.hide();
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { computed, inject, ref, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { Services } from '@editor/type';
|
|
4
|
+
|
|
5
|
+
export const useEditorContentHeight = () => {
|
|
6
|
+
const services = inject<Services>('services');
|
|
7
|
+
const frameworkHeight = computed(() => services?.uiService.get('frameworkRect').height || 0);
|
|
8
|
+
const navMenuHeight = computed(() => services?.uiService.get('navMenuRect').height || 0);
|
|
9
|
+
const editorContentHeight = computed(() => frameworkHeight.value - navMenuHeight.value);
|
|
10
|
+
|
|
11
|
+
const height = ref(0);
|
|
12
|
+
watch(
|
|
13
|
+
editorContentHeight,
|
|
14
|
+
() => {
|
|
15
|
+
if (height.value > 0 && height.value === editorContentHeight.value) return;
|
|
16
|
+
height.value = editorContentHeight.value;
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
immediate: true,
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
height,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Ref, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { Id, MNode } from '@tmagic/schema';
|
|
4
|
+
|
|
5
|
+
import type { LayerNodeStatus, TreeNodeData } from '@editor/type';
|
|
6
|
+
import { traverseNode } from '@editor/utils';
|
|
7
|
+
import { updateStatus } from '@editor/utils/tree';
|
|
8
|
+
|
|
9
|
+
export const useFilter = (
|
|
10
|
+
nodeData: Ref<TreeNodeData[]>,
|
|
11
|
+
nodeStatusMap: Ref<Map<Id, LayerNodeStatus> | undefined>,
|
|
12
|
+
filterNodeMethod: (value: string, data: MNode) => boolean,
|
|
13
|
+
) => {
|
|
14
|
+
// tree方法:对树节点进行筛选时执行的方法
|
|
15
|
+
const filterIsMatch = (value: string | string[], data: MNode): boolean => {
|
|
16
|
+
const string = !Array.isArray(value) ? [value] : value;
|
|
17
|
+
|
|
18
|
+
if (!string.length) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return string.some((v) => filterNodeMethod(v, data));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const filter = (text: string | string[]) => {
|
|
26
|
+
if (!nodeData.value.length) return;
|
|
27
|
+
|
|
28
|
+
nodeData.value.forEach((node) => {
|
|
29
|
+
traverseNode(node, (node: MNode, parents: MNode[]) => {
|
|
30
|
+
if (!nodeStatusMap.value) return;
|
|
31
|
+
|
|
32
|
+
const visible = filterIsMatch(text, node);
|
|
33
|
+
if (visible && parents.length) {
|
|
34
|
+
parents.forEach((parent) => {
|
|
35
|
+
updateStatus(nodeStatusMap.value!, parent.id, {
|
|
36
|
+
visible,
|
|
37
|
+
expand: true,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
updateStatus(nodeStatusMap.value, node.id, {
|
|
43
|
+
visible,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
filterText: ref(''),
|
|
51
|
+
filterTextChangeHandler(text: string | string[]) {
|
|
52
|
+
filter(text);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { computed, ComputedRef, inject, ref, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { Services } from '@editor/type';
|
|
4
|
+
|
|
5
|
+
interface State {
|
|
6
|
+
status: boolean;
|
|
7
|
+
top: number;
|
|
8
|
+
left: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const useFloatBox = (slideKeys: ComputedRef<string[]>) => {
|
|
12
|
+
const services = inject<Services>('services');
|
|
13
|
+
|
|
14
|
+
const floatBoxStates = ref<{
|
|
15
|
+
[key in (typeof slideKeys.value)[number]]: State;
|
|
16
|
+
}>(
|
|
17
|
+
slideKeys.value.reduce(
|
|
18
|
+
(total, cur) => ({
|
|
19
|
+
...total,
|
|
20
|
+
[cur]: {
|
|
21
|
+
status: false,
|
|
22
|
+
top: 0,
|
|
23
|
+
left: 0,
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
{},
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const showingBoxKeys = computed(() =>
|
|
31
|
+
Object.keys(floatBoxStates.value).filter((key) => floatBoxStates.value[key].status),
|
|
32
|
+
);
|
|
33
|
+
const isDragging = ref(false);
|
|
34
|
+
|
|
35
|
+
const dragstartHandler = () => (isDragging.value = true);
|
|
36
|
+
const dragendHandler = (key: string, e: DragEvent) => {
|
|
37
|
+
const navMenuRect = services?.uiService?.get('navMenuRect');
|
|
38
|
+
floatBoxStates.value[key] = {
|
|
39
|
+
left: e.clientX,
|
|
40
|
+
top: (navMenuRect?.top ?? 0) + (navMenuRect?.height ?? 0),
|
|
41
|
+
status: true,
|
|
42
|
+
};
|
|
43
|
+
isDragging.value = false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
document.body.addEventListener('dragover', (e: DragEvent) => {
|
|
47
|
+
if (!isDragging.value) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
watch(
|
|
52
|
+
() => slideKeys.value,
|
|
53
|
+
(slideKeys) => {
|
|
54
|
+
slideKeys.forEach((key) => {
|
|
55
|
+
if (!floatBoxStates.value[key]) {
|
|
56
|
+
floatBoxStates.value[key] = {
|
|
57
|
+
status: false,
|
|
58
|
+
top: 0,
|
|
59
|
+
left: 0,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
deep: true,
|
|
66
|
+
immediate: true,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
dragstartHandler,
|
|
72
|
+
dragendHandler,
|
|
73
|
+
floatBoxStates,
|
|
74
|
+
showingBoxKeys,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted, type Ref, ref } from 'vue';
|
|
2
|
+
import Gesto, { type OnDrag } from 'gesto';
|
|
3
|
+
|
|
4
|
+
export const useGetSo = (target: Ref<HTMLElement | undefined>, emit: (evt: 'change', e: OnDrag<Gesto>) => void) => {
|
|
5
|
+
let getso: Gesto;
|
|
6
|
+
const isDraging = ref(false);
|
|
7
|
+
|
|
8
|
+
onMounted(() => {
|
|
9
|
+
if (!target.value) return;
|
|
10
|
+
getso = new Gesto(target.value, {
|
|
11
|
+
container: window,
|
|
12
|
+
pinchOutside: true,
|
|
13
|
+
})
|
|
14
|
+
.on('drag', (e) => {
|
|
15
|
+
if (!target.value) return;
|
|
16
|
+
|
|
17
|
+
emit('change', e);
|
|
18
|
+
})
|
|
19
|
+
.on('dragStart', () => {
|
|
20
|
+
isDraging.value = true;
|
|
21
|
+
})
|
|
22
|
+
.on('dragEnd', () => {
|
|
23
|
+
isDraging.value = false;
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
onBeforeUnmount(() => {
|
|
28
|
+
getso?.unset();
|
|
29
|
+
isDraging.value = false;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
isDraging,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Ref, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
import { UiService } from '@editor/services/ui';
|
|
4
|
+
|
|
5
|
+
export const useNextFloatBoxPosition = (uiService?: UiService, parent?: Ref<HTMLDivElement | null>) => {
|
|
6
|
+
const boxPosition = ref({
|
|
7
|
+
left: 0,
|
|
8
|
+
top: 0,
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const calcBoxPosition = () => {
|
|
12
|
+
const columnWidth = uiService?.get('columnWidth');
|
|
13
|
+
const navMenuRect = uiService?.get('navMenuRect');
|
|
14
|
+
let left = columnWidth?.left ?? 0;
|
|
15
|
+
if (parent?.value) {
|
|
16
|
+
const rect = parent?.value?.getBoundingClientRect();
|
|
17
|
+
left = (rect?.left ?? 0) + (rect?.width ?? 0);
|
|
18
|
+
}
|
|
19
|
+
boxPosition.value = {
|
|
20
|
+
left,
|
|
21
|
+
top: (navMenuRect?.top ?? 0) + (navMenuRect?.height ?? 0),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
boxPosition,
|
|
27
|
+
calcBoxPosition,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComputedRef, ref, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { Id, MNode } from '@tmagic/schema';
|
|
4
|
+
|
|
5
|
+
import { LayerNodeStatus, TreeNodeData } from '@editor/type';
|
|
6
|
+
import { traverseNode } from '@editor/utils';
|
|
7
|
+
|
|
8
|
+
const createPageNodeStatus = (nodeData: TreeNodeData[], initialLayerNodeStatus?: Map<Id, LayerNodeStatus>) => {
|
|
9
|
+
const map = new Map<Id, LayerNodeStatus>();
|
|
10
|
+
|
|
11
|
+
nodeData.forEach((node: MNode) =>
|
|
12
|
+
traverseNode(node, (node) => {
|
|
13
|
+
map.set(
|
|
14
|
+
node.id,
|
|
15
|
+
initialLayerNodeStatus?.get(node.id) || {
|
|
16
|
+
visible: true,
|
|
17
|
+
expand: false,
|
|
18
|
+
selected: false,
|
|
19
|
+
draggable: false,
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return map;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const useNodeStatus = (nodeData: ComputedRef<TreeNodeData[]>) => {
|
|
29
|
+
/** 所有页面的节点状态 */
|
|
30
|
+
const nodeStatusMap = ref(new Map<Id, LayerNodeStatus>());
|
|
31
|
+
|
|
32
|
+
// 切换页面或者新增页面,重新生成节点状态
|
|
33
|
+
watch(
|
|
34
|
+
nodeData,
|
|
35
|
+
(nodeData) => {
|
|
36
|
+
// 生成节点状态
|
|
37
|
+
nodeStatusMap.value = createPageNodeStatus(nodeData, nodeStatusMap.value);
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
immediate: true,
|
|
41
|
+
deep: true,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
nodeStatusMap,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { computed, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { MNode } from '@tmagic/schema';
|
|
4
|
+
import StageCore, { GuidesType, RemoveEventData, SortEventData, UpdateEventData } from '@tmagic/stage';
|
|
5
|
+
|
|
6
|
+
import editorService from '@editor/services/editor';
|
|
7
|
+
import uiService from '@editor/services/ui';
|
|
8
|
+
import {
|
|
9
|
+
H_GUIDE_LINE_STORAGE_KEY,
|
|
10
|
+
StageOptions,
|
|
11
|
+
UI_SELECT_MODE_EVENT_NAME,
|
|
12
|
+
V_GUIDE_LINE_STORAGE_KEY,
|
|
13
|
+
} from '@editor/type';
|
|
14
|
+
import { getGuideLineFromCache } from '@editor/utils/editor';
|
|
15
|
+
|
|
16
|
+
const root = computed(() => editorService.get('root'));
|
|
17
|
+
const page = computed(() => editorService.get('page'));
|
|
18
|
+
const zoom = computed(() => uiService.get('zoom') || 1);
|
|
19
|
+
const uiSelectMode = computed(() => uiService.get('uiSelectMode'));
|
|
20
|
+
|
|
21
|
+
const getGuideLineKey = (key: string) => `${key}_${root.value?.id}_${page.value?.id}`;
|
|
22
|
+
|
|
23
|
+
export const useStage = (stageOptions: StageOptions) => {
|
|
24
|
+
const stage = new StageCore({
|
|
25
|
+
render: stageOptions.render,
|
|
26
|
+
runtimeUrl: stageOptions.runtimeUrl,
|
|
27
|
+
zoom: stageOptions.zoom ?? zoom.value,
|
|
28
|
+
autoScrollIntoView: stageOptions.autoScrollIntoView,
|
|
29
|
+
isContainer: stageOptions.isContainer,
|
|
30
|
+
containerHighlightClassName: stageOptions.containerHighlightClassName,
|
|
31
|
+
containerHighlightDuration: stageOptions.containerHighlightDuration,
|
|
32
|
+
containerHighlightType: stageOptions.containerHighlightType,
|
|
33
|
+
disabledDragStart: stageOptions.disabledDragStart,
|
|
34
|
+
renderType: stageOptions.renderType,
|
|
35
|
+
canSelect: (el, event, stop) => {
|
|
36
|
+
if (!stageOptions.canSelect) return true;
|
|
37
|
+
|
|
38
|
+
const elCanSelect = stageOptions.canSelect?.(el);
|
|
39
|
+
// 在组件联动过程中不能再往下选择,返回并触发 ui-select
|
|
40
|
+
if (uiSelectMode.value && elCanSelect && event.type === 'mousedown') {
|
|
41
|
+
document.dispatchEvent(new CustomEvent(UI_SELECT_MODE_EVENT_NAME, { detail: el }));
|
|
42
|
+
return stop();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return elCanSelect;
|
|
46
|
+
},
|
|
47
|
+
moveableOptions: stageOptions.moveableOptions,
|
|
48
|
+
updateDragEl: stageOptions.updateDragEl,
|
|
49
|
+
guidesOptions: stageOptions.guidesOptions,
|
|
50
|
+
disabledMultiSelect: stageOptions.disabledMultiSelect,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
watch(
|
|
54
|
+
() => editorService.get('disabledMultiSelect'),
|
|
55
|
+
(disabledMultiSelect) => {
|
|
56
|
+
if (disabledMultiSelect) {
|
|
57
|
+
stage.disableMultiSelect();
|
|
58
|
+
} else {
|
|
59
|
+
stage.enableMultiSelect();
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
stage.mask.setGuides([
|
|
65
|
+
getGuideLineFromCache(getGuideLineKey(H_GUIDE_LINE_STORAGE_KEY)),
|
|
66
|
+
getGuideLineFromCache(getGuideLineKey(V_GUIDE_LINE_STORAGE_KEY)),
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
stage.on('page-el-update', () => {
|
|
70
|
+
editorService.set('stageLoading', false);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
stage.on('select', (el: HTMLElement) => {
|
|
74
|
+
if (`${editorService.get('node')?.id}` === el.id && editorService.get('nodes').length === 1) return;
|
|
75
|
+
editorService.select(el.id);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
stage.on('highlight', (el: HTMLElement) => {
|
|
79
|
+
editorService.highlight(el.id);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
stage.on('multi-select', (els: HTMLElement[]) => {
|
|
83
|
+
editorService.multiSelect(els.map((el) => el.id));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
stage.on('update', (ev: UpdateEventData) => {
|
|
87
|
+
if (ev.parentEl) {
|
|
88
|
+
for (const data of ev.data) {
|
|
89
|
+
editorService.moveToContainer({ id: data.el.id, style: data.style }, ev.parentEl.id);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
editorService.update(ev.data.map((data) => ({ id: data.el.id, style: data.style })));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
stage.on('sort', (ev: SortEventData) => {
|
|
98
|
+
editorService.sort(ev.src, ev.dist);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
stage.on('remove', (ev: RemoveEventData) => {
|
|
102
|
+
const nodes = ev.data.map(({ el }) => editorService.getNodeById(el.id));
|
|
103
|
+
editorService.remove(nodes.filter((node) => Boolean(node)) as MNode[]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
stage.on('select-parent', () => {
|
|
107
|
+
const parent = editorService.get('parent');
|
|
108
|
+
if (!parent) throw new Error('父节点为空');
|
|
109
|
+
editorService.select(parent);
|
|
110
|
+
editorService.get('stage')?.select(parent.id);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
stage.on('change-guides', (e) => {
|
|
114
|
+
uiService.set('showGuides', true);
|
|
115
|
+
|
|
116
|
+
if (!root.value || !page.value) return;
|
|
117
|
+
|
|
118
|
+
const storageKey = getGuideLineKey(
|
|
119
|
+
e.type === GuidesType.HORIZONTAL ? H_GUIDE_LINE_STORAGE_KEY : V_GUIDE_LINE_STORAGE_KEY,
|
|
120
|
+
);
|
|
121
|
+
if (e.guides.length) {
|
|
122
|
+
globalThis.localStorage.setItem(storageKey, JSON.stringify(e.guides));
|
|
123
|
+
} else {
|
|
124
|
+
globalThis.localStorage.removeItem(storageKey);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return stage;
|
|
129
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { onBeforeUnmount, reactive } from 'vue';
|
|
2
|
+
|
|
3
|
+
export const useWindowRect = () => {
|
|
4
|
+
const rect = reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
|
|
5
|
+
|
|
6
|
+
const windowResizeHandler = () => {
|
|
7
|
+
rect.width = globalThis.innerWidth;
|
|
8
|
+
rect.height = globalThis.innerHeight;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
globalThis.addEventListener('resize', windowResizeHandler);
|
|
12
|
+
|
|
13
|
+
onBeforeUnmount(() => {
|
|
14
|
+
globalThis.removeEventListener('resize', windowResizeHandler);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
rect,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- app-manage cdn链接:https://cloudcache.tencent-cloud.com/qcloud/ui/static/console_aside_v4/6638c8a5-2e7f-477a-83b1-a413a0e4ba39.svg -->
|
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<g fill="#7C878E" fill-rule="evenodd">
|
|
5
|
+
<path d="M15.3,5.5 L8,0 L0.7,5.5 L8,11 L15.3,5.5 Z M8,2.5 L12,5.5 L8,8.5 L4,5.5 L8,2.5 Z" fill-rule="nonzero" />
|
|
6
|
+
<path d="M8 13.5L2.3 9.2 0.7 10.5 8 16 15.3 10.5 13.7 9.2z" />
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script lang="ts" setup>
|
|
12
|
+
defineOptions({
|
|
13
|
+
name: 'MEditorAppManageIcon',
|
|
14
|
+
});
|
|
15
|
+
</script>
|