@tmagic/editor 1.3.0-alpha.2 → 1.3.0-alpha.21

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 (167) hide show
  1. package/dist/style.css +91 -120
  2. package/dist/tmagic-editor.js +4609 -3257
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +5708 -4337
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +21 -22
  7. package/src/Editor.vue +29 -7
  8. package/src/components/CodeBlockEditor.vue +170 -0
  9. package/src/components/CodeParams.vue +60 -0
  10. package/src/components/ContentMenu.vue +30 -11
  11. package/src/components/Icon.vue +5 -1
  12. package/src/components/Resizer.vue +45 -0
  13. package/src/components/ScrollBar.vue +5 -1
  14. package/src/components/ScrollViewer.vue +5 -1
  15. package/src/components/SearchInput.vue +4 -0
  16. package/src/components/{Layout.vue → SplitView.vue} +8 -4
  17. package/src/components/ToolButton.vue +5 -1
  18. package/src/editorProps.ts +35 -4
  19. package/src/fields/Code.vue +28 -20
  20. package/src/fields/CodeLink.vue +15 -10
  21. package/src/fields/CodeSelect.vue +19 -10
  22. package/src/fields/CodeSelectCol.vue +67 -83
  23. package/src/fields/DataSourceFieldSelect.vue +47 -0
  24. package/src/fields/DataSourceFields.vue +24 -21
  25. package/src/fields/DataSourceInput.vue +318 -0
  26. package/src/fields/DataSourceMethodSelect.vue +136 -0
  27. package/src/fields/DataSourceMethods.vue +103 -0
  28. package/src/fields/DataSourceSelect.vue +68 -0
  29. package/src/fields/EventSelect.vue +62 -22
  30. package/src/fields/KeyValue.vue +13 -11
  31. package/src/fields/UISelect.vue +59 -15
  32. package/src/hooks/index.ts +21 -0
  33. package/src/hooks/use-code-block-edit.ts +84 -0
  34. package/src/hooks/use-data-source-method.ts +100 -0
  35. package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
  36. package/src/icons/AppManageIcon.vue +5 -1
  37. package/src/icons/CenterIcon.vue +13 -0
  38. package/src/icons/CodeIcon.vue +5 -3
  39. package/src/index.ts +24 -3
  40. package/src/initService.ts +75 -16
  41. package/src/layouts/AddPageBox.vue +5 -1
  42. package/src/layouts/CodeEditor.vue +66 -11
  43. package/src/layouts/Framework.vue +32 -28
  44. package/src/layouts/NavMenu.vue +5 -1
  45. package/src/layouts/PropsPanel.vue +14 -4
  46. package/src/layouts/sidebar/ComponentListPanel.vue +11 -10
  47. package/src/layouts/sidebar/LayerMenu.vue +13 -25
  48. package/src/layouts/sidebar/LayerNode.vue +40 -0
  49. package/src/layouts/sidebar/LayerPanel.vue +71 -28
  50. package/src/layouts/sidebar/Sidebar.vue +13 -17
  51. package/src/layouts/sidebar/code-block/CodeBlockList.vue +84 -118
  52. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +63 -0
  53. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +39 -34
  54. package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
  55. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +17 -65
  56. package/src/layouts/workspace/Breadcrumb.vue +5 -1
  57. package/src/layouts/workspace/PageBar.vue +5 -1
  58. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
  59. package/src/layouts/workspace/Stage.vue +30 -8
  60. package/src/layouts/workspace/ViewerMenu.vue +15 -36
  61. package/src/layouts/workspace/Workspace.vue +9 -134
  62. package/src/services/codeBlock.ts +20 -72
  63. package/src/services/dataSource.ts +17 -2
  64. package/src/services/dep.ts +23 -20
  65. package/src/services/editor.ts +3 -3
  66. package/src/services/keybinding.ts +185 -0
  67. package/src/services/props.ts +2 -2
  68. package/src/services/storage.ts +3 -2
  69. package/src/theme/code-block.scss +5 -117
  70. package/src/theme/code-editor.scss +27 -2
  71. package/src/theme/content-menu.scss +1 -1
  72. package/src/theme/data-source-input.scss +18 -0
  73. package/src/theme/data-source-methods.scss +13 -0
  74. package/src/theme/event.scss +15 -12
  75. package/src/theme/framework.scss +0 -3
  76. package/src/theme/layer-panel.scss +6 -0
  77. package/src/theme/layout.scss +4 -0
  78. package/src/theme/resizer.scss +25 -10
  79. package/src/theme/stage.scss +4 -0
  80. package/src/theme/theme.scss +2 -0
  81. package/src/type.ts +105 -7
  82. package/src/utils/config.ts +1 -1
  83. package/src/utils/content-menu.ts +92 -0
  84. package/src/utils/data-source/formConfigs/base.ts +35 -30
  85. package/src/utils/data-source/index.ts +75 -6
  86. package/src/utils/dep.ts +39 -7
  87. package/src/utils/index.ts +1 -1
  88. package/src/utils/keybinding-config.ts +120 -0
  89. package/src/utils/props.ts +298 -155
  90. package/src/utils/undo-redo.ts +1 -1
  91. package/types/Editor.vue.d.ts +37 -4
  92. package/types/components/CodeBlockEditor.vue.d.ts +23 -0
  93. package/types/components/CodeParams.vue.d.ts +26 -0
  94. package/types/components/ContentMenu.vue.d.ts +8 -3
  95. package/types/components/Icon.vue.d.ts +2 -2
  96. package/types/{layouts → components}/Resizer.vue.d.ts +2 -2
  97. package/types/components/ScrollBar.vue.d.ts +1 -1
  98. package/types/components/ScrollViewer.vue.d.ts +8 -5
  99. package/types/components/SearchInput.vue.d.ts +1 -1
  100. package/types/components/{Layout.vue.d.ts → SplitView.vue.d.ts} +9 -6
  101. package/types/components/ToolButton.vue.d.ts +10 -7
  102. package/types/editorProps.d.ts +23 -4
  103. package/types/fields/Code.vue.d.ts +23 -18
  104. package/types/fields/CodeLink.vue.d.ts +13 -22
  105. package/types/fields/CodeSelect.vue.d.ts +12 -20
  106. package/types/fields/CodeSelectCol.vue.d.ts +14 -15
  107. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  108. package/types/fields/DataSourceFields.vue.d.ts +13 -21
  109. package/types/fields/DataSourceInput.vue.d.ts +34 -0
  110. package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
  111. package/types/fields/DataSourceMethods.vue.d.ts +32 -0
  112. package/types/fields/DataSourceSelect.vue.d.ts +40 -0
  113. package/types/fields/EventSelect.vue.d.ts +3 -14
  114. package/types/fields/KeyValue.vue.d.ts +15 -27
  115. package/types/fields/UISelect.vue.d.ts +3 -12
  116. package/types/hooks/index.d.ts +3 -0
  117. package/types/hooks/use-code-block-edit.d.ts +125 -0
  118. package/types/hooks/use-data-source-method.d.ts +123 -0
  119. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  120. package/types/icons/CenterIcon.vue.d.ts +2 -0
  121. package/types/icons/CodeIcon.vue.d.ts +1 -1
  122. package/types/index.d.ts +12 -2
  123. package/types/initService.d.ts +2 -2
  124. package/types/layouts/AddPageBox.vue.d.ts +1 -1
  125. package/types/layouts/CodeEditor.vue.d.ts +18 -10
  126. package/types/layouts/Framework.vue.d.ts +11 -32
  127. package/types/layouts/NavMenu.vue.d.ts +7 -4
  128. package/types/layouts/PropsPanel.vue.d.ts +276 -4
  129. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
  130. package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
  131. package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
  132. package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
  133. package/types/layouts/sidebar/Sidebar.vue.d.ts +16 -16
  134. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -12
  135. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +28 -0
  136. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +4 -2
  137. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  138. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  139. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  140. package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
  141. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
  142. package/types/layouts/workspace/Stage.vue.d.ts +2 -2
  143. package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
  144. package/types/layouts/workspace/Workspace.vue.d.ts +9 -9
  145. package/types/services/codeBlock.d.ts +6 -37
  146. package/types/services/dataSource.d.ts +7 -1
  147. package/types/services/dep.d.ts +12 -21
  148. package/types/services/editor.d.ts +1 -1
  149. package/types/services/keybinding.d.ts +20 -0
  150. package/types/services/props.d.ts +10 -115
  151. package/types/type.d.ts +97 -7
  152. package/types/utils/config.d.ts +1 -1
  153. package/types/utils/content-menu.d.ts +7 -0
  154. package/types/utils/data-source/formConfigs/base.d.ts +2 -2
  155. package/types/utils/data-source/index.d.ts +7 -1
  156. package/types/utils/dep.d.ts +4 -2
  157. package/types/utils/index.d.ts +1 -1
  158. package/types/utils/keybinding-config.d.ts +3 -0
  159. package/types/utils/props.d.ts +13 -102
  160. package/src/components/CodeDraftEditor.vue +0 -144
  161. package/src/components/FunctionEditor.vue +0 -190
  162. package/src/layouts/Resizer.vue +0 -32
  163. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -96
  164. package/types/components/CodeDraftEditor.vue.d.ts +0 -58
  165. package/types/components/FunctionEditor.vue.d.ts +0 -192
  166. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +0 -25
  167. /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-alpha.2",
2
+ "version": "1.3.0-alpha.21",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -46,43 +46,42 @@
46
46
  "dependencies": {
47
47
  "@babel/core": "^7.18.0",
48
48
  "@element-plus/icons-vue": "^2.0.9",
49
- "@tmagic/core": "1.3.0-alpha.2",
50
- "@tmagic/design": "1.3.0-alpha.2",
51
- "@tmagic/form": "1.3.0-alpha.2",
52
- "@tmagic/schema": "1.3.0-alpha.2",
53
- "@tmagic/stage": "1.3.0-alpha.2",
54
- "@tmagic/table": "1.3.0-alpha.2",
55
- "@tmagic/utils": "1.3.0-alpha.2",
49
+ "@tmagic/core": "1.3.0-alpha.21",
50
+ "@tmagic/design": "1.3.0-alpha.21",
51
+ "@tmagic/form": "1.3.0-alpha.21",
52
+ "@tmagic/schema": "1.3.0-alpha.21",
53
+ "@tmagic/stage": "1.3.0-alpha.21",
54
+ "@tmagic/table": "1.3.0-alpha.21",
55
+ "@tmagic/utils": "1.3.0-alpha.21",
56
56
  "buffer": "^6.0.3",
57
57
  "color": "^3.1.3",
58
58
  "events": "^3.3.0",
59
- "gesto": "^1.7.0",
60
- "keycon": "^1.1.2",
59
+ "gesto": "^1.19.1",
60
+ "keycon": "^1.4.0",
61
61
  "lodash-es": "^4.17.21",
62
- "monaco-editor": "^0.34.0",
62
+ "monaco-editor": "^0.41.0",
63
63
  "serialize-javascript": "^6.0.0",
64
- "vue": "^3.2.37"
64
+ "vue": "^3.3.4"
65
65
  },
66
66
  "peerDependencies": {
67
- "@tmagic/design": "1.3.0-alpha.2",
68
- "@tmagic/form": "1.3.0-alpha.2",
69
- "monaco-editor": "^0.34.0",
70
- "vue": "^3.2.37"
67
+ "@tmagic/design": "1.3.0-alpha.21",
68
+ "@tmagic/form": "1.3.0-alpha.21",
69
+ "monaco-editor": "^0.41.0",
70
+ "vue": "^3.3.4"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@types/events": "^3.0.0",
74
74
  "@types/lodash-es": "^4.17.4",
75
75
  "@types/node": "^15.12.4",
76
76
  "@types/serialize-javascript": "^5.0.1",
77
- "@vitejs/plugin-vue": "^4.1.0",
78
- "@vue/compiler-sfc": "^3.2.37",
79
- "@vue/test-utils": "^2.0.0",
77
+ "@vitejs/plugin-vue": "^4.2.3",
78
+ "@vue/compiler-sfc": "^3.3.4",
79
+ "@vue/test-utils": "^2.3.2",
80
80
  "rimraf": "^3.0.2",
81
81
  "sass": "^1.35.1",
82
82
  "tsc-alias": "^1.8.5",
83
83
  "typescript": "^5.0.4",
84
- "vite": "^4.2.1",
85
- "vite-plugin-vue-setup-extend": "^0.4.0",
86
- "vue-tsc": "^1.0.11"
84
+ "vite": "^4.4.4",
85
+ "vue-tsc": "^1.6.5"
87
86
  }
88
87
  }
package/src/Editor.vue CHANGED
@@ -1,9 +1,19 @@
1
1
  <template>
2
- <Framework :code-options="codeOptions">
2
+ <Framework>
3
+ <template #header>
4
+ <slot name="header"></slot>
5
+ </template>
6
+
3
7
  <template #nav>
4
8
  <slot name="nav" :editorService="editorService"><TMagicNavMenu :data="menu"></TMagicNavMenu></slot>
5
9
  </template>
6
10
 
11
+ <template #content-before>
12
+ <slot name="content-before"></slot>
13
+ </template>
14
+
15
+ <template #src-code><slot name="src-code" :editorService="editorService"></slot></template>
16
+
7
17
  <template #sidebar>
8
18
  <slot name="sidebar" :editorService="editorService">
9
19
  <Sidebar :data="sidebar" :layer-content-menu="layerContentMenu">
@@ -30,10 +40,6 @@
30
40
  <template #code-block-panel-tool="{ id, data }">
31
41
  <slot name="code-block-panel-tool" :id="id" :data="data"></slot>
32
42
  </template>
33
-
34
- <template #code-block-edit-panel-header="{ id }">
35
- <slot name="code-block-edit-panel-header" :id="id"></slot>
36
- </template>
37
43
  </Sidebar>
38
44
  </slot>
39
45
  </template>
@@ -51,7 +57,10 @@
51
57
 
52
58
  <template #props-panel>
53
59
  <slot name="props-panel">
54
- <PropsPanel @mounted="(instance: any) => $emit('props-panel-mounted', instance)">
60
+ <PropsPanel
61
+ :extend-state="extendFormState"
62
+ @mounted="(instance: any) => $emit('props-panel-mounted', instance)"
63
+ >
55
64
  <template #props-panel-header>
56
65
  <slot name="props-panel-header"></slot>
57
66
  </template>
@@ -60,6 +69,14 @@
60
69
  </template>
61
70
 
62
71
  <template #empty><slot name="empty" :editorService="editorService"></slot></template>
72
+
73
+ <template #content-after>
74
+ <slot name="content-after"></slot>
75
+ </template>
76
+
77
+ <template #footer>
78
+ <slot name="footer"></slot>
79
+ </template>
63
80
  </Framework>
64
81
  </template>
65
82
 
@@ -78,15 +95,17 @@ import depService from './services/dep';
78
95
  import editorService from './services/editor';
79
96
  import eventsService from './services/events';
80
97
  import historyService from './services/history';
98
+ import keybindingService from './services/keybinding';
81
99
  import propsService from './services/props';
82
100
  import storageService from './services/storage';
83
101
  import uiService from './services/ui';
102
+ import keybindingConfig from './utils/keybinding-config';
84
103
  import editorProps from './editorProps';
85
104
  import { initServiceEvents, initServiceState } from './initService';
86
105
  import type { Services } from './type';
87
106
 
88
107
  export default defineComponent({
89
- name: 'm-editor',
108
+ name: 'MEditor',
90
109
 
91
110
  components: {
92
111
  TMagicNavMenu: NavMenu,
@@ -112,10 +131,13 @@ export default defineComponent({
112
131
  codeBlockService,
113
132
  depService,
114
133
  dataSourceService,
134
+ keybindingService,
115
135
  };
116
136
 
117
137
  initServiceEvents(props, emit, services);
118
138
  initServiceState(props, services);
139
+ keybindingService.registe(keybindingConfig);
140
+ keybindingService.registeEl('global');
119
141
 
120
142
  provide('services', services);
121
143
 
@@ -0,0 +1,170 @@
1
+ <template>
2
+ <MFormDrawer
3
+ class="m-editor-code-block-editor"
4
+ ref="fomDrawer"
5
+ label-width="80px"
6
+ :close-on-press-escape="false"
7
+ :title="content.name"
8
+ :width="size"
9
+ :config="functionConfig"
10
+ :values="content"
11
+ :disabled="disabled"
12
+ @submit="submitForm"
13
+ @error="errorHandler"
14
+ @open="openHandler"
15
+ ></MFormDrawer>
16
+ </template>
17
+
18
+ <script lang="ts" setup>
19
+ import { computed, inject, ref } from 'vue';
20
+
21
+ import { tMagicMessage } from '@tmagic/design';
22
+ import { ColumnConfig, FormState, MFormDrawer } from '@tmagic/form';
23
+ import type { CodeBlockContent } from '@tmagic/schema';
24
+
25
+ import type { Services } from '@editor/type';
26
+ import { getConfig } from '@editor/utils/config';
27
+
28
+ defineOptions({
29
+ name: 'MEditorCodeBlockEditor',
30
+ });
31
+
32
+ const props = defineProps<{
33
+ content: CodeBlockContent;
34
+ disabled?: boolean;
35
+ isDataSource?: boolean;
36
+ }>();
37
+
38
+ const emit = defineEmits<{
39
+ submit: [values: CodeBlockContent];
40
+ }>();
41
+
42
+ const services = inject<Services>('services');
43
+
44
+ const columnWidth = computed(() => services?.uiService.get('columnWidth'));
45
+ const size = computed(() =>
46
+ columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600,
47
+ );
48
+
49
+ const codeEditorHeight = ref('600px');
50
+
51
+ const defaultParamColConfig: ColumnConfig = {
52
+ type: 'row',
53
+ label: '参数类型',
54
+ items: [
55
+ {
56
+ text: '参数类型',
57
+ labelWidth: '70px',
58
+ type: 'select',
59
+ name: 'type',
60
+ options: [
61
+ {
62
+ text: '数字',
63
+ label: '数字',
64
+ value: 'number',
65
+ },
66
+ {
67
+ text: '字符串',
68
+ label: '字符串',
69
+ value: 'text',
70
+ },
71
+ {
72
+ text: '组件',
73
+ label: '组件',
74
+ value: 'ui-select',
75
+ },
76
+ ],
77
+ },
78
+ ],
79
+ };
80
+
81
+ const functionConfig = computed(() => [
82
+ {
83
+ text: '名称',
84
+ name: 'name',
85
+ },
86
+ {
87
+ text: '描述',
88
+ name: 'desc',
89
+ },
90
+ {
91
+ text: '执行时机',
92
+ name: 'timing',
93
+ type: 'select',
94
+ options: [
95
+ { text: '初始化前', value: 'beforeInit' },
96
+ { text: '初始化后', value: 'afterInit' },
97
+ ],
98
+ display: () => props.isDataSource,
99
+ },
100
+ {
101
+ type: 'table',
102
+ border: true,
103
+ text: '参数',
104
+ enableFullscreen: false,
105
+ enableToggleMode: false,
106
+ name: 'params',
107
+ dropSort: false,
108
+ items: [
109
+ {
110
+ type: 'text',
111
+ label: '参数名',
112
+ name: 'name',
113
+ },
114
+ {
115
+ type: 'text',
116
+ label: '描述',
117
+ name: 'extra',
118
+ },
119
+ services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
120
+ ],
121
+ },
122
+ {
123
+ name: 'content',
124
+ type: 'vs-code',
125
+ options: inject('codeOptions', {}),
126
+ height: codeEditorHeight.value,
127
+ onChange: (formState: FormState | undefined, code: string) => {
128
+ try {
129
+ // 检测js代码是否存在语法错误
130
+ getConfig('parseDSL')(code);
131
+
132
+ return code;
133
+ } catch (error: any) {
134
+ tMagicMessage.error(error.message);
135
+
136
+ throw error;
137
+ }
138
+ },
139
+ },
140
+ ]);
141
+
142
+ const submitForm = async (values: CodeBlockContent) => {
143
+ emit('submit', values);
144
+ };
145
+
146
+ const errorHandler = (error: any) => {
147
+ tMagicMessage.error(error.message);
148
+ };
149
+
150
+ const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
151
+
152
+ const openHandler = () => {
153
+ setTimeout(() => {
154
+ if (fomDrawer.value) {
155
+ const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
156
+ codeEditorHeight.value = `${height > 100 ? height : 600}px`;
157
+ }
158
+ });
159
+ };
160
+
161
+ defineExpose({
162
+ show() {
163
+ fomDrawer.value?.show();
164
+ },
165
+
166
+ hide() {
167
+ fomDrawer.value?.hide();
168
+ },
169
+ });
170
+ </script>
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <MForm
3
+ ref="form"
4
+ :config="codeParamsConfig"
5
+ :init-values="model"
6
+ :disabled="disabled"
7
+ :size="size"
8
+ :watch-props="false"
9
+ @change="onParamsChangeHandler"
10
+ ></MForm>
11
+ </template>
12
+
13
+ <script lang="ts" setup>
14
+ import { computed, ref } from 'vue';
15
+
16
+ import { FormConfig, MForm } from '@tmagic/form';
17
+
18
+ import type { CodeParamStatement } from '@editor/type';
19
+ import { error } from '@editor/utils';
20
+
21
+ defineOptions({
22
+ name: 'MEditorCodeParams',
23
+ });
24
+
25
+ const props = defineProps<{
26
+ model: any;
27
+ size?: 'small' | 'default' | 'large';
28
+ disabled?: boolean;
29
+ name: string;
30
+ paramsConfig: CodeParamStatement[];
31
+ }>();
32
+
33
+ const emit = defineEmits(['change']);
34
+
35
+ const form = ref<InstanceType<typeof MForm>>();
36
+
37
+ const getFormConfig = (items: FormConfig = []) => [
38
+ {
39
+ type: 'fieldset',
40
+ items,
41
+ legend: '参数',
42
+ labelWidth: '70px',
43
+ name: props.name,
44
+ },
45
+ ];
46
+
47
+ const codeParamsConfig = computed(() => getFormConfig(props.paramsConfig));
48
+
49
+ /**
50
+ * 参数值修改更新
51
+ */
52
+ const onParamsChangeHandler = async () => {
53
+ try {
54
+ const value = await form.value?.submitForm(true);
55
+ emit('change', value);
56
+ } catch (e) {
57
+ error(e);
58
+ }
59
+ };
60
+ </script>
@@ -4,14 +4,16 @@
4
4
  <ToolButton
5
5
  v-for="(item, index) in menuData"
6
6
  event-type="mouseup"
7
+ ref="buttons"
7
8
  :data="item"
8
9
  :key="index"
9
10
  @mouseup="hide"
10
- @mouseenter="showSubMenu(item)"
11
+ @mouseenter="showSubMenu(item, index)"
11
12
  ></ToolButton>
12
13
  </div>
13
14
  <teleport to="body">
14
15
  <content-menu
16
+ v-if="subMenuData.length"
15
17
  class="sub-menu"
16
18
  ref="subMenu"
17
19
  :menu-data="subMenuData"
@@ -22,13 +24,17 @@
22
24
  </div>
23
25
  </template>
24
26
 
25
- <script lang="ts" setup name="MEditorContentMenu">
27
+ <script lang="ts" setup>
26
28
  import { nextTick, onMounted, onUnmounted, ref } from 'vue';
27
29
 
28
30
  import { MenuButton, MenuComponent } from '@editor/type';
29
31
 
30
32
  import ToolButton from './ToolButton.vue';
31
33
 
34
+ defineOptions({
35
+ name: 'MEditorContentMenu',
36
+ });
37
+
32
38
  const props = withDefaults(
33
39
  defineProps<{
34
40
  menuData?: (MenuButton | MenuComponent)[];
@@ -43,6 +49,7 @@ const props = withDefaults(
43
49
  const emit = defineEmits(['hide', 'show']);
44
50
 
45
51
  const menu = ref<HTMLDivElement>();
52
+ const buttons = ref<InstanceType<typeof ToolButton>[]>();
46
53
  const subMenu = ref<any>();
47
54
  const visible = ref(false);
48
55
  const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
@@ -51,6 +58,8 @@ const menuStyle = ref({
51
58
  top: '0',
52
59
  });
53
60
 
61
+ const contains = (el: HTMLElement) => menu.value?.contains(el) || subMenu.value?.contains(el);
62
+
54
63
  const hide = () => {
55
64
  if (!visible.value) return;
56
65
 
@@ -65,7 +74,7 @@ const hideHandler = (e: MouseEvent) => {
65
74
  if (!visible.value || !target) {
66
75
  return;
67
76
  }
68
- if (menu.value?.contains(target) || subMenu.value?.$el?.contains(target)) {
77
+ if (contains(target)) {
69
78
  return;
70
79
  }
71
80
  hide();
@@ -94,19 +103,27 @@ const show = (e: MouseEvent) => {
94
103
  }, 300);
95
104
  };
96
105
 
97
- const showSubMenu = (item: MenuButton | MenuComponent) => {
106
+ const showSubMenu = (item: MenuButton | MenuComponent, index: number) => {
98
107
  const menuItem = item as MenuButton;
99
108
  if (typeof item !== 'object' || !menuItem.items?.length) {
100
109
  return;
101
110
  }
102
111
 
103
- subMenuData.value = menuItem.items;
104
- if (menu.value) {
105
- subMenu.value.show({
106
- clientX: menu.value.offsetLeft + menu.value.clientWidth,
107
- clientY: menu.value.offsetTop,
108
- });
109
- }
112
+ subMenuData.value = menuItem.items || [];
113
+ setTimeout(() => {
114
+ if (menu.value) {
115
+ // 将子菜单放置在按钮右侧,与按钮齐平
116
+ let y = menu.value.offsetTop;
117
+ if (buttons.value?.[index].$el) {
118
+ const rect = buttons.value?.[index].$el.getBoundingClientRect();
119
+ y = rect.top;
120
+ }
121
+ subMenu.value?.show({
122
+ clientX: menu.value.offsetLeft + menu.value.clientWidth,
123
+ clientY: y,
124
+ });
125
+ }
126
+ }, 0);
110
127
  };
111
128
 
112
129
  onMounted(() => {
@@ -122,7 +139,9 @@ onUnmounted(() => {
122
139
  });
123
140
 
124
141
  defineExpose({
142
+ menu,
125
143
  hide,
126
144
  show,
145
+ contains,
127
146
  });
128
147
  </script>
@@ -7,12 +7,16 @@
7
7
  <TMagicIcon v-else class="magic-editor-icon"><component :is="toRaw(icon)"></component></TMagicIcon>
8
8
  </template>
9
9
 
10
- <script lang="ts" setup name="MEditorIcon">
10
+ <script lang="ts" setup>
11
11
  import { toRaw } from 'vue';
12
12
  import { Edit } from '@element-plus/icons-vue';
13
13
 
14
14
  import { TMagicIcon } from '@tmagic/design';
15
15
 
16
+ defineOptions({
17
+ name: 'MEditorIcon',
18
+ });
19
+
16
20
  defineProps<{
17
21
  icon?: any;
18
22
  }>();
@@ -0,0 +1,45 @@
1
+ <template>
2
+ <span ref="target" class="m-editor-resizer" :class="{ 'm-editor-resizer-draging': isDraging }">
3
+ <slot></slot>
4
+ </span>
5
+ </template>
6
+
7
+ <script lang="ts" setup>
8
+ import { onMounted, onUnmounted, ref } from 'vue';
9
+ import Gesto from 'gesto';
10
+
11
+ defineOptions({
12
+ name: 'MEditorResizer',
13
+ });
14
+
15
+ const emit = defineEmits(['change']);
16
+
17
+ const target = ref<HTMLSpanElement>();
18
+ const isDraging = ref(false);
19
+
20
+ let getso: Gesto;
21
+
22
+ onMounted(() => {
23
+ if (!target.value) return;
24
+ getso = new Gesto(target.value, {
25
+ container: window,
26
+ pinchOutside: true,
27
+ })
28
+ .on('drag', (e) => {
29
+ if (!target.value) return;
30
+
31
+ emit('change', e.deltaX);
32
+ })
33
+ .on('dragStart', () => {
34
+ isDraging.value = true;
35
+ })
36
+ .on('dragEnd', () => {
37
+ isDraging.value = false;
38
+ });
39
+ });
40
+
41
+ onUnmounted(() => {
42
+ getso?.unset();
43
+ isDraging.value = false;
44
+ });
45
+ </script>
@@ -4,10 +4,14 @@
4
4
  </div>
5
5
  </template>
6
6
 
7
- <script lang="ts" setup name="MEditorScrollBar">
7
+ <script lang="ts" setup>
8
8
  import { computed, onMounted, onUnmounted, ref } from 'vue';
9
9
  import Gesto from 'gesto';
10
10
 
11
+ defineOptions({
12
+ name: 'MEditorScrollBar',
13
+ });
14
+
11
15
  const props = defineProps<{
12
16
  size: number;
13
17
  scrollSize: number;
@@ -22,7 +22,7 @@
22
22
  </div>
23
23
  </template>
24
24
 
25
- <script lang="ts" setup name="MEditorScrollViewer">
25
+ <script lang="ts" setup>
26
26
  import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
27
27
 
28
28
  import type { ScrollViewerEvent } from '@editor/type';
@@ -30,6 +30,10 @@ import { ScrollViewer } from '@editor/utils/scroll-viewer';
30
30
 
31
31
  import ScrollBar from './ScrollBar.vue';
32
32
 
33
+ defineOptions({
34
+ name: 'MEditorScrollViewer',
35
+ });
36
+
33
37
  const props = withDefaults(
34
38
  defineProps<{
35
39
  width?: number;
@@ -19,6 +19,10 @@ import { Search } from '@element-plus/icons-vue';
19
19
 
20
20
  import { TMagicIcon, TMagicInput } from '@tmagic/design';
21
21
 
22
+ defineOptions({
23
+ name: 'MEditorSearchInput',
24
+ });
25
+
22
26
  const emit = defineEmits(['search']);
23
27
 
24
28
  const filterText = ref('');
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div ref="el" class="m-editor-layout">
3
- <template v-if="hasLeft">
3
+ <template v-if="hasLeft && $slots.left">
4
4
  <div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
5
5
  <slot name="left"></slot>
6
6
  </div>
@@ -11,7 +11,7 @@
11
11
  <slot name="center"></slot>
12
12
  </div>
13
13
 
14
- <template v-if="hasRight">
14
+ <template v-if="hasRight && $slots.right">
15
15
  <Resizer @change="changeRight"></Resizer>
16
16
  <div class="m-editor-layout-right" :class="rightClass" :style="`width: ${right}px`">
17
17
  <slot name="right"></slot>
@@ -20,10 +20,14 @@
20
20
  </div>
21
21
  </template>
22
22
 
23
- <script lang="ts" setup name="MEditorLayout">
23
+ <script lang="ts" setup>
24
24
  import { computed, onMounted, onUnmounted, ref } from 'vue';
25
25
 
26
- import Resizer from '@editor/layouts/Resizer.vue';
26
+ import Resizer from './Resizer.vue';
27
+
28
+ defineOptions({
29
+ name: 'MEditorLayout',
30
+ });
27
31
 
28
32
  const emit = defineEmits(['update:left', 'change', 'update:right']);
29
33
 
@@ -43,7 +43,7 @@
43
43
  </div>
44
44
  </template>
45
45
 
46
- <script lang="ts" setup name="MEditorToolButton">
46
+ <script lang="ts" setup>
47
47
  import { computed, inject } from 'vue';
48
48
  import { ArrowDown } from '@element-plus/icons-vue';
49
49
 
@@ -60,6 +60,10 @@ import {
60
60
  import MIcon from '../components/Icon.vue';
61
61
  import type { MenuButton, MenuComponent, Services } from '../type';
62
62
 
63
+ defineOptions({
64
+ name: 'MEditorToolButton',
65
+ });
66
+
63
67
  const props = withDefaults(
64
68
  defineProps<{
65
69
  data?: MenuButton | MenuComponent;