@tmagic/editor 1.4.7 → 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.
Files changed (152) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +314 -452
  3. package/dist/tmagic-editor.umd.cjs +313 -450
  4. package/package.json +15 -11
  5. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  6. package/types/services/editor.d.ts +19 -2
  7. package/types/services/props.d.ts +5 -5
  8. package/types/type.d.ts +6 -0
  9. package/types/utils/editor.d.ts +1 -0
  10. package/src/Editor.vue +0 -211
  11. package/src/components/CodeBlockEditor.vue +0 -268
  12. package/src/components/CodeParams.vue +0 -60
  13. package/src/components/ContentMenu.vue +0 -193
  14. package/src/components/FloatingBox.vue +0 -178
  15. package/src/components/Icon.vue +0 -27
  16. package/src/components/Resizer.vue +0 -23
  17. package/src/components/ScrollBar.vue +0 -151
  18. package/src/components/ScrollViewer.vue +0 -128
  19. package/src/components/SearchInput.vue +0 -37
  20. package/src/components/SplitView.vue +0 -186
  21. package/src/components/ToolButton.vue +0 -138
  22. package/src/components/Tree.vue +0 -71
  23. package/src/components/TreeNode.vue +0 -150
  24. package/src/editorProps.ts +0 -117
  25. package/src/fields/Code.vue +0 -50
  26. package/src/fields/CodeLink.vue +0 -80
  27. package/src/fields/CodeSelect.vue +0 -132
  28. package/src/fields/CodeSelectCol.vue +0 -139
  29. package/src/fields/DataSourceFieldSelect.vue +0 -149
  30. package/src/fields/DataSourceFields.vue +0 -323
  31. package/src/fields/DataSourceInput.vue +0 -331
  32. package/src/fields/DataSourceMethodSelect.vue +0 -153
  33. package/src/fields/DataSourceMethods.vue +0 -104
  34. package/src/fields/DataSourceMocks.vue +0 -255
  35. package/src/fields/DataSourceSelect.vue +0 -98
  36. package/src/fields/EventSelect.vue +0 -375
  37. package/src/fields/KeyValue.vue +0 -137
  38. package/src/fields/PageFragmentSelect.vue +0 -63
  39. package/src/fields/UISelect.vue +0 -135
  40. package/src/hooks/index.ts +0 -24
  41. package/src/hooks/use-code-block-edit.ts +0 -83
  42. package/src/hooks/use-data-source-edit.ts +0 -46
  43. package/src/hooks/use-data-source-method.ts +0 -100
  44. package/src/hooks/use-editor-content-height.ts +0 -26
  45. package/src/hooks/use-filter.ts +0 -55
  46. package/src/hooks/use-float-box.ts +0 -76
  47. package/src/hooks/use-getso.ts +0 -35
  48. package/src/hooks/use-next-float-box-position.ts +0 -29
  49. package/src/hooks/use-node-status.ts +0 -48
  50. package/src/hooks/use-stage.ts +0 -129
  51. package/src/hooks/use-window-rect.ts +0 -20
  52. package/src/icons/AppManageIcon.vue +0 -15
  53. package/src/icons/CenterIcon.vue +0 -13
  54. package/src/icons/CodeIcon.vue +0 -28
  55. package/src/icons/FolderMinusIcon.vue +0 -22
  56. package/src/icons/PinIcon.vue +0 -25
  57. package/src/icons/PinnedIcon.vue +0 -25
  58. package/src/index.ts +0 -118
  59. package/src/initService.ts +0 -443
  60. package/src/layouts/AddPageBox.vue +0 -55
  61. package/src/layouts/CodeEditor.vue +0 -226
  62. package/src/layouts/Framework.vue +0 -163
  63. package/src/layouts/NavMenu.vue +0 -200
  64. package/src/layouts/PropsPanel.vue +0 -130
  65. package/src/layouts/page-bar/AddButton.vue +0 -48
  66. package/src/layouts/page-bar/PageBar.vue +0 -159
  67. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  68. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  69. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  70. package/src/layouts/sidebar/Sidebar.vue +0 -278
  71. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -160
  72. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  73. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  74. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -172
  75. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  76. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  77. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  78. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  79. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  80. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  81. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  82. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  83. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  84. package/src/layouts/workspace/Workspace.vue +0 -46
  85. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  86. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  87. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  88. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  89. package/src/services/BaseService.ts +0 -230
  90. package/src/services/codeBlock.ts +0 -327
  91. package/src/services/componentList.ts +0 -58
  92. package/src/services/dataSource.ts +0 -216
  93. package/src/services/dep.ts +0 -152
  94. package/src/services/editor.ts +0 -1096
  95. package/src/services/events.ts +0 -93
  96. package/src/services/history.ts +0 -126
  97. package/src/services/keybinding.ts +0 -220
  98. package/src/services/props.ts +0 -271
  99. package/src/services/stageOverlay.ts +0 -212
  100. package/src/services/storage.ts +0 -155
  101. package/src/services/ui.ts +0 -156
  102. package/src/shims-vue.d.ts +0 -6
  103. package/src/theme/breadcrumb.scss +0 -6
  104. package/src/theme/code-block.scss +0 -6
  105. package/src/theme/code-editor.scss +0 -38
  106. package/src/theme/common/var.scss +0 -14
  107. package/src/theme/component-list-panel.scss +0 -95
  108. package/src/theme/content-menu.scss +0 -76
  109. package/src/theme/data-source-field.scss +0 -12
  110. package/src/theme/data-source-fields.scss +0 -13
  111. package/src/theme/data-source-input.scss +0 -18
  112. package/src/theme/data-source-methods.scss +0 -13
  113. package/src/theme/data-source.scss +0 -28
  114. package/src/theme/event.scss +0 -37
  115. package/src/theme/floating-box.scss +0 -32
  116. package/src/theme/framework.scss +0 -69
  117. package/src/theme/icon.scss +0 -12
  118. package/src/theme/index.scss +0 -10
  119. package/src/theme/key-value.scss +0 -20
  120. package/src/theme/layer-panel.scss +0 -26
  121. package/src/theme/layout.scss +0 -9
  122. package/src/theme/nav-menu.scss +0 -78
  123. package/src/theme/page-bar.scss +0 -89
  124. package/src/theme/page-fragment-select.scss +0 -14
  125. package/src/theme/props-panel.scss +0 -55
  126. package/src/theme/resizer.scss +0 -66
  127. package/src/theme/ruler.scss +0 -38
  128. package/src/theme/search-input.scss +0 -14
  129. package/src/theme/sidebar.scss +0 -79
  130. package/src/theme/stage.scss +0 -76
  131. package/src/theme/theme.scss +0 -27
  132. package/src/theme/tree.scss +0 -89
  133. package/src/theme/workspace.scss +0 -9
  134. package/src/type.ts +0 -746
  135. package/src/utils/compose.ts +0 -52
  136. package/src/utils/config.ts +0 -29
  137. package/src/utils/content-menu.ts +0 -95
  138. package/src/utils/data-source/formConfigs/base.ts +0 -30
  139. package/src/utils/data-source/formConfigs/http.ts +0 -60
  140. package/src/utils/data-source/index.ts +0 -243
  141. package/src/utils/editor.ts +0 -294
  142. package/src/utils/idle-task.ts +0 -72
  143. package/src/utils/index.ts +0 -24
  144. package/src/utils/keybinding-config.ts +0 -125
  145. package/src/utils/logger.ts +0 -47
  146. package/src/utils/monaco-editor.ts +0 -8
  147. package/src/utils/operator.ts +0 -106
  148. package/src/utils/props.ts +0 -504
  149. package/src/utils/scroll-viewer.ts +0 -165
  150. package/src/utils/tree.ts +0 -15
  151. package/src/utils/undo-redo.ts +0 -76
  152. package/tsconfig.build.json +0 -16
@@ -1,24 +0,0 @@
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';
@@ -1,83 +0,0 @@
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
- };
@@ -1,46 +0,0 @@
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
- };
@@ -1,100 +0,0 @@
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
- };
@@ -1,26 +0,0 @@
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
- };
@@ -1,55 +0,0 @@
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
- };
@@ -1,76 +0,0 @@
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
- };
@@ -1,35 +0,0 @@
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
- };
@@ -1,29 +0,0 @@
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
- };
@@ -1,48 +0,0 @@
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
- };
@@ -1,129 +0,0 @@
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
- };
@@ -1,20 +0,0 @@
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
- };
@@ -1,15 +0,0 @@
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>