@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.
Files changed (158) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +636 -589
  3. package/dist/tmagic-editor.umd.cjs +634 -586
  4. package/package.json +15 -11
  5. package/types/editorProps.d.ts +0 -7
  6. package/types/layouts/PropsPanel.vue.d.ts +9 -9
  7. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  8. package/types/services/codeBlock.d.ts +2 -1
  9. package/types/services/dataSource.d.ts +2 -1
  10. package/types/services/dep.d.ts +12 -2
  11. package/types/services/editor.d.ts +22 -4
  12. package/types/services/props.d.ts +7 -6
  13. package/types/type.d.ts +6 -0
  14. package/types/utils/editor.d.ts +1 -0
  15. package/types/utils/idle-task.d.ts +14 -0
  16. package/types/utils/operator.d.ts +2 -2
  17. package/src/Editor.vue +0 -211
  18. package/src/components/CodeBlockEditor.vue +0 -268
  19. package/src/components/CodeParams.vue +0 -60
  20. package/src/components/ContentMenu.vue +0 -193
  21. package/src/components/FloatingBox.vue +0 -178
  22. package/src/components/Icon.vue +0 -27
  23. package/src/components/Resizer.vue +0 -23
  24. package/src/components/ScrollBar.vue +0 -151
  25. package/src/components/ScrollViewer.vue +0 -128
  26. package/src/components/SearchInput.vue +0 -37
  27. package/src/components/SplitView.vue +0 -186
  28. package/src/components/ToolButton.vue +0 -138
  29. package/src/components/Tree.vue +0 -71
  30. package/src/components/TreeNode.vue +0 -148
  31. package/src/editorProps.ts +0 -124
  32. package/src/fields/Code.vue +0 -50
  33. package/src/fields/CodeLink.vue +0 -80
  34. package/src/fields/CodeSelect.vue +0 -132
  35. package/src/fields/CodeSelectCol.vue +0 -139
  36. package/src/fields/DataSourceFieldSelect.vue +0 -149
  37. package/src/fields/DataSourceFields.vue +0 -323
  38. package/src/fields/DataSourceInput.vue +0 -325
  39. package/src/fields/DataSourceMethodSelect.vue +0 -153
  40. package/src/fields/DataSourceMethods.vue +0 -104
  41. package/src/fields/DataSourceMocks.vue +0 -255
  42. package/src/fields/DataSourceSelect.vue +0 -98
  43. package/src/fields/EventSelect.vue +0 -301
  44. package/src/fields/KeyValue.vue +0 -137
  45. package/src/fields/PageFragmentSelect.vue +0 -63
  46. package/src/fields/UISelect.vue +0 -135
  47. package/src/hooks/index.ts +0 -24
  48. package/src/hooks/use-code-block-edit.ts +0 -83
  49. package/src/hooks/use-data-source-edit.ts +0 -46
  50. package/src/hooks/use-data-source-method.ts +0 -100
  51. package/src/hooks/use-editor-content-height.ts +0 -26
  52. package/src/hooks/use-filter.ts +0 -55
  53. package/src/hooks/use-float-box.ts +0 -76
  54. package/src/hooks/use-getso.ts +0 -35
  55. package/src/hooks/use-next-float-box-position.ts +0 -29
  56. package/src/hooks/use-node-status.ts +0 -48
  57. package/src/hooks/use-stage.ts +0 -129
  58. package/src/hooks/use-window-rect.ts +0 -20
  59. package/src/icons/AppManageIcon.vue +0 -15
  60. package/src/icons/CenterIcon.vue +0 -13
  61. package/src/icons/CodeIcon.vue +0 -28
  62. package/src/icons/FolderMinusIcon.vue +0 -22
  63. package/src/icons/PinIcon.vue +0 -25
  64. package/src/icons/PinnedIcon.vue +0 -25
  65. package/src/index.ts +0 -118
  66. package/src/initService.ts +0 -447
  67. package/src/layouts/AddPageBox.vue +0 -55
  68. package/src/layouts/CodeEditor.vue +0 -226
  69. package/src/layouts/Framework.vue +0 -163
  70. package/src/layouts/NavMenu.vue +0 -200
  71. package/src/layouts/PropsPanel.vue +0 -130
  72. package/src/layouts/page-bar/AddButton.vue +0 -48
  73. package/src/layouts/page-bar/PageBar.vue +0 -159
  74. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  75. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  76. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  77. package/src/layouts/sidebar/Sidebar.vue +0 -278
  78. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
  79. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  80. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  81. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
  82. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  83. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  84. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  85. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  86. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  87. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  88. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  89. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  90. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  91. package/src/layouts/workspace/Workspace.vue +0 -46
  92. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  93. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  94. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  95. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  96. package/src/services/BaseService.ts +0 -230
  97. package/src/services/codeBlock.ts +0 -324
  98. package/src/services/componentList.ts +0 -58
  99. package/src/services/dataSource.ts +0 -209
  100. package/src/services/dep.ts +0 -80
  101. package/src/services/editor.ts +0 -1087
  102. package/src/services/events.ts +0 -93
  103. package/src/services/history.ts +0 -126
  104. package/src/services/keybinding.ts +0 -220
  105. package/src/services/props.ts +0 -265
  106. package/src/services/stageOverlay.ts +0 -212
  107. package/src/services/storage.ts +0 -155
  108. package/src/services/ui.ts +0 -156
  109. package/src/shims-vue.d.ts +0 -6
  110. package/src/theme/breadcrumb.scss +0 -6
  111. package/src/theme/code-block.scss +0 -6
  112. package/src/theme/code-editor.scss +0 -38
  113. package/src/theme/common/var.scss +0 -14
  114. package/src/theme/component-list-panel.scss +0 -95
  115. package/src/theme/content-menu.scss +0 -76
  116. package/src/theme/data-source-field.scss +0 -12
  117. package/src/theme/data-source-fields.scss +0 -13
  118. package/src/theme/data-source-input.scss +0 -18
  119. package/src/theme/data-source-methods.scss +0 -13
  120. package/src/theme/data-source.scss +0 -28
  121. package/src/theme/event.scss +0 -37
  122. package/src/theme/floating-box.scss +0 -32
  123. package/src/theme/framework.scss +0 -69
  124. package/src/theme/icon.scss +0 -12
  125. package/src/theme/index.scss +0 -10
  126. package/src/theme/key-value.scss +0 -20
  127. package/src/theme/layer-panel.scss +0 -26
  128. package/src/theme/layout.scss +0 -9
  129. package/src/theme/nav-menu.scss +0 -78
  130. package/src/theme/page-bar.scss +0 -89
  131. package/src/theme/page-fragment-select.scss +0 -14
  132. package/src/theme/props-panel.scss +0 -55
  133. package/src/theme/resizer.scss +0 -66
  134. package/src/theme/ruler.scss +0 -38
  135. package/src/theme/search-input.scss +0 -14
  136. package/src/theme/sidebar.scss +0 -79
  137. package/src/theme/stage.scss +0 -76
  138. package/src/theme/theme.scss +0 -27
  139. package/src/theme/tree.scss +0 -89
  140. package/src/theme/workspace.scss +0 -9
  141. package/src/type.ts +0 -746
  142. package/src/utils/compose.ts +0 -52
  143. package/src/utils/config.ts +0 -29
  144. package/src/utils/content-menu.ts +0 -95
  145. package/src/utils/data-source/formConfigs/base.ts +0 -30
  146. package/src/utils/data-source/formConfigs/http.ts +0 -60
  147. package/src/utils/data-source/index.ts +0 -236
  148. package/src/utils/editor.ts +0 -294
  149. package/src/utils/index.ts +0 -24
  150. package/src/utils/keybinding-config.ts +0 -125
  151. package/src/utils/logger.ts +0 -47
  152. package/src/utils/monaco-editor.ts +0 -8
  153. package/src/utils/operator.ts +0 -106
  154. package/src/utils/props.ts +0 -504
  155. package/src/utils/scroll-viewer.ts +0 -165
  156. package/src/utils/tree.ts +0 -15
  157. package/src/utils/undo-redo.ts +0 -76
  158. package/tsconfig.build.json +0 -16
@@ -1,268 +0,0 @@
1
- <template>
2
- <!-- 代码块编辑区 -->
3
- <FloatingBox
4
- v-model:visible="boxVisible"
5
- v-model:width="width"
6
- v-model:height="codeBlockEditorHeight"
7
- :title="content.name ? `${disabled ? '查看' : '编辑'}${content.name}` : '新增代码'"
8
- :position="boxPosition"
9
- :before-close="beforeClose"
10
- >
11
- <template #body>
12
- <MFormBox
13
- class="m-editor-code-block-editor"
14
- ref="formBox"
15
- label-width="80px"
16
- :close-on-press-escape="false"
17
- :title="content.name"
18
- :config="functionConfig"
19
- :values="content"
20
- :disabled="disabled"
21
- style="height: 100%"
22
- @change="changeHandler"
23
- @submit="submitForm"
24
- @error="errorHandler"
25
- @closed="closedHandler"
26
- >
27
- <template #left>
28
- <TMagicButton v-if="!disabled" type="primary" link @click="difVisible = true">查看修改</TMagicButton>
29
- </template>
30
- </MFormBox>
31
- </template>
32
- </FloatingBox>
33
-
34
- <Teleport to="body">
35
- <TMagicDialog title="查看修改" v-model="difVisible" fullscreen>
36
- <div style="display: flex; margin-bottom: 10px">
37
- <div style="flex: 1"><TMagicTag size="small" type="info">修改前</TMagicTag></div>
38
- <div style="flex: 1"><TMagicTag size="small" type="success">修改后</TMagicTag></div>
39
- </div>
40
-
41
- <CodeEditor
42
- v-if="difVisible"
43
- ref="magicVsEditor"
44
- type="diff"
45
- language="json"
46
- :initValues="content.content"
47
- :modifiedValues="formBox?.form?.values.content"
48
- :style="`height: ${windowRect.height - 150}px`"
49
- ></CodeEditor>
50
-
51
- <template #footer>
52
- <span class="dialog-footer">
53
- <TMagicButton size="small" @click="difVisible = false">取消</TMagicButton>
54
- <TMagicButton size="small" type="primary" @click="diffChange">确定</TMagicButton>
55
- </span>
56
- </template>
57
- </TMagicDialog>
58
- </Teleport>
59
- </template>
60
-
61
- <script lang="ts" setup>
62
- import { computed, inject, Ref, ref } from 'vue';
63
-
64
- import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
65
- import { ColumnConfig, FormConfig, FormState, MFormBox } from '@tmagic/form';
66
- import type { CodeBlockContent } from '@tmagic/schema';
67
-
68
- import FloatingBox from '@editor/components/FloatingBox.vue';
69
- import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
70
- import { useNextFloatBoxPosition } from '@editor/hooks/use-next-float-box-position';
71
- import { useWindowRect } from '@editor/hooks/use-window-rect';
72
- import CodeEditor from '@editor/layouts/CodeEditor.vue';
73
- import type { Services } from '@editor/type';
74
- import { getConfig } from '@editor/utils/config';
75
-
76
- defineOptions({
77
- name: 'MEditorCodeBlockEditor',
78
- });
79
-
80
- const width = defineModel<number>('width', { default: 670 });
81
- const boxVisible = defineModel<boolean>('visible', { default: false });
82
-
83
- const props = defineProps<{
84
- content: CodeBlockContent;
85
- disabled?: boolean;
86
- isDataSource?: boolean;
87
- dataSourceType?: string;
88
- }>();
89
-
90
- const emit = defineEmits<{
91
- submit: [values: CodeBlockContent];
92
- }>();
93
-
94
- const services = inject<Services>('services');
95
-
96
- const { height: codeBlockEditorHeight } = useEditorContentHeight();
97
-
98
- const difVisible = ref(false);
99
- const { rect: windowRect } = useWindowRect();
100
-
101
- const magicVsEditor = ref<InstanceType<typeof CodeEditor>>();
102
-
103
- const diffChange = () => {
104
- if (!magicVsEditor.value || !formBox.value?.form) {
105
- return;
106
- }
107
-
108
- formBox.value.form.values.content = magicVsEditor.value.getEditorValue();
109
-
110
- difVisible.value = false;
111
- };
112
-
113
- const defaultParamColConfig: ColumnConfig = {
114
- type: 'row',
115
- label: '参数类型',
116
- items: [
117
- {
118
- text: '参数类型',
119
- labelWidth: '70px',
120
- type: 'select',
121
- name: 'type',
122
- options: [
123
- {
124
- text: '数字',
125
- label: '数字',
126
- value: 'number',
127
- },
128
- {
129
- text: '字符串',
130
- label: '字符串',
131
- value: 'text',
132
- },
133
- {
134
- text: '组件',
135
- label: '组件',
136
- value: 'ui-select',
137
- },
138
- ],
139
- },
140
- ],
141
- };
142
-
143
- const functionConfig = computed<FormConfig>(() => [
144
- {
145
- text: '名称',
146
- name: 'name',
147
- rules: [{ required: true, message: '请输入名称', trigger: 'blur' }],
148
- },
149
- {
150
- text: '描述',
151
- name: 'desc',
152
- },
153
- {
154
- text: '执行时机',
155
- name: 'timing',
156
- type: 'select',
157
- options: () => {
158
- const options = [
159
- { text: '初始化前', value: 'beforeInit' },
160
- { text: '初始化后', value: 'afterInit' },
161
- ];
162
- if (props.dataSourceType !== 'base') {
163
- options.push({ text: '请求前', value: 'beforeRequest' });
164
- options.push({ text: '请求后', value: 'afterRequest' });
165
- }
166
- return options;
167
- },
168
- display: () => props.isDataSource,
169
- },
170
- {
171
- type: 'table',
172
- border: true,
173
- text: '参数',
174
- enableFullscreen: false,
175
- enableToggleMode: false,
176
- name: 'params',
177
- dropSort: false,
178
- items: [
179
- {
180
- type: 'text',
181
- label: '参数名',
182
- name: 'name',
183
- },
184
- {
185
- type: 'text',
186
- label: '描述',
187
- name: 'extra',
188
- },
189
- services?.codeBlockService.getParamsColConfig() || defaultParamColConfig,
190
- ],
191
- },
192
- {
193
- name: 'content',
194
- type: 'vs-code',
195
- options: inject('codeOptions', {}),
196
- height: '500px',
197
- onChange: (formState: FormState | undefined, code: string) => {
198
- try {
199
- // 检测js代码是否存在语法错误
200
- getConfig('parseDSL')(code);
201
-
202
- return code;
203
- } catch (error: any) {
204
- tMagicMessage.error(error.message);
205
-
206
- throw error;
207
- }
208
- },
209
- },
210
- ]);
211
-
212
- const submitForm = (values: CodeBlockContent) => {
213
- changedValue.value = undefined;
214
- emit('submit', values);
215
- };
216
-
217
- const errorHandler = (error: any) => {
218
- tMagicMessage.error(error.message);
219
- };
220
-
221
- const formBox = ref<InstanceType<typeof MFormBox>>();
222
-
223
- const changedValue = ref<CodeBlockContent>();
224
- const changeHandler = (values: CodeBlockContent) => {
225
- changedValue.value = values;
226
- };
227
-
228
- const beforeClose = (done: (cancel?: boolean) => void) => {
229
- if (!changedValue.value) {
230
- done();
231
- return;
232
- }
233
- tMagicMessageBox
234
- .confirm('当前代码块已修改,是否保存?', '提示', {
235
- confirmButtonText: '保存并关闭',
236
- cancelButtonText: '不保存并关闭',
237
- type: 'warning',
238
- distinguishCancelAndClose: true,
239
- })
240
- .then(() => {
241
- changedValue.value && submitForm(changedValue.value);
242
- done();
243
- })
244
- .catch((action: string) => {
245
- if (action === 'cancel') {
246
- }
247
- done(action === 'cancel');
248
- });
249
- };
250
-
251
- const closedHandler = () => {
252
- changedValue.value = undefined;
253
- };
254
-
255
- const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
256
- const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(services?.uiService, parentFloating);
257
-
258
- defineExpose({
259
- async show() {
260
- calcBoxPosition();
261
- boxVisible.value = true;
262
- },
263
-
264
- async hide() {
265
- boxVisible.value = false;
266
- },
267
- });
268
- </script>
@@ -1,60 +0,0 @@
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>
@@ -1,193 +0,0 @@
1
- <template>
2
- <transition name="fade">
3
- <div
4
- v-show="visible"
5
- class="magic-editor-content-menu"
6
- ref="menu"
7
- :style="menuStyle"
8
- @mouseenter="mouseenterHandler()"
9
- >
10
- <slot name="title"></slot>
11
- <div>
12
- <ToolButton
13
- v-for="(item, index) in menuData"
14
- event-type="mouseup"
15
- ref="buttons"
16
- :class="{ active: active && item.id === active }"
17
- :data="item"
18
- :key="index"
19
- @mouseup="clickHandler"
20
- @mouseenter="showSubMenu(item, index)"
21
- ></ToolButton>
22
- </div>
23
- <teleport to="body">
24
- <content-menu
25
- v-if="subMenuData.length"
26
- class="sub-menu"
27
- ref="subMenu"
28
- :active="active"
29
- :menu-data="subMenuData"
30
- :is-sub-menu="true"
31
- @hide="hide"
32
- ></content-menu>
33
- </teleport>
34
- </div>
35
- </transition>
36
- </template>
37
-
38
- <script lang="ts" setup>
39
- import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
40
-
41
- import { MenuButton, MenuComponent } from '@editor/type';
42
-
43
- import ToolButton from './ToolButton.vue';
44
-
45
- defineOptions({
46
- name: 'MEditorContentMenu',
47
- });
48
-
49
- const props = withDefaults(
50
- defineProps<{
51
- menuData?: (MenuButton | MenuComponent)[];
52
- isSubMenu?: boolean;
53
- active?: string | number;
54
- autoHide?: boolean;
55
- }>(),
56
- {
57
- menuData: () => [],
58
- isSubMenu: false,
59
- autoHide: true,
60
- },
61
- );
62
-
63
- const emit = defineEmits<{
64
- hide: [];
65
- show: [];
66
- mouseenter: [];
67
- }>();
68
-
69
- const menu = ref<HTMLDivElement>();
70
- const buttons = ref<InstanceType<typeof ToolButton>[]>();
71
- const subMenu = ref<any>();
72
- const visible = ref(false);
73
- const subMenuData = ref<(MenuButton | MenuComponent)[]>([]);
74
-
75
- const menuPosition = ref({
76
- left: 0,
77
- top: 0,
78
- });
79
-
80
- const menuStyle = computed(() => ({
81
- top: `${menuPosition.value.top}px`,
82
- left: `${menuPosition.value.left}px`,
83
- }));
84
-
85
- const contains = (el: HTMLElement) => menu.value?.contains(el) || subMenu.value?.contains(el);
86
-
87
- const hide = () => {
88
- if (!visible.value) return;
89
-
90
- visible.value = false;
91
- subMenu.value?.hide();
92
-
93
- emit('hide');
94
- };
95
-
96
- const clickHandler = () => {
97
- if (!props.autoHide) return;
98
-
99
- hide();
100
- };
101
-
102
- const outsideClickHideHandler = (e: MouseEvent) => {
103
- if (!props.autoHide) return;
104
-
105
- const target = e.target as HTMLElement | undefined;
106
- if (!visible.value || !target) {
107
- return;
108
- }
109
- if (contains(target)) {
110
- return;
111
- }
112
- hide();
113
- };
114
-
115
- const setPosition = (e: { clientY: number; clientX: number }) => {
116
- const menuHeight = menu.value?.clientHeight || 0;
117
-
118
- let top = e.clientY;
119
- if (menuHeight + e.clientY > document.body.clientHeight) {
120
- top = document.body.clientHeight - menuHeight;
121
- }
122
-
123
- menuPosition.value = {
124
- top,
125
- left: e.clientX,
126
- };
127
- };
128
-
129
- const show = (e?: { clientY: number; clientX: number }) => {
130
- // 加settimeout是以为,如果菜单中的按钮监听的是mouseup,那么菜单显示出来时鼠标如果正好在菜单上就会马上触发按钮的mouseup
131
- setTimeout(() => {
132
- visible.value = true;
133
-
134
- nextTick(() => {
135
- e && setPosition(e);
136
-
137
- emit('show');
138
- });
139
- }, 300);
140
- };
141
-
142
- const showSubMenu = (item: MenuButton | MenuComponent, index: number) => {
143
- const menuItem = item as MenuButton;
144
- if (typeof item !== 'object') {
145
- return;
146
- }
147
-
148
- subMenuData.value = menuItem.items || [];
149
- setTimeout(() => {
150
- if (!visible.value) {
151
- return;
152
- }
153
-
154
- if (menu.value) {
155
- // 将子菜单放置在按钮右侧,与按钮齐平
156
- let y = menu.value.offsetTop;
157
- if (buttons.value?.[index].$el) {
158
- const rect = buttons.value?.[index].$el.getBoundingClientRect();
159
- y = rect.top;
160
- }
161
- subMenu.value?.show({
162
- clientX: menu.value.offsetLeft + menu.value.clientWidth,
163
- clientY: y,
164
- });
165
- }
166
- }, 0);
167
- };
168
-
169
- const mouseenterHandler = () => {
170
- emit('mouseenter');
171
- };
172
-
173
- onMounted(() => {
174
- if (props.isSubMenu) return;
175
-
176
- globalThis.addEventListener('mousedown', outsideClickHideHandler, true);
177
- });
178
-
179
- onBeforeUnmount(() => {
180
- if (props.isSubMenu) return;
181
-
182
- globalThis.removeEventListener('mousedown', outsideClickHideHandler, true);
183
- });
184
-
185
- defineExpose({
186
- menu,
187
- menuPosition,
188
- hide,
189
- show,
190
- contains,
191
- setPosition,
192
- });
193
- </script>
@@ -1,178 +0,0 @@
1
- <template>
2
- <Teleport to="body" v-if="visible">
3
- <div ref="target" class="m-editor-float-box" :style="{ ...style, zIndex: curZIndex }" @mousedown="nextZIndex">
4
- <div ref="titleEl" class="m-editor-float-box-title">
5
- <slot name="title">
6
- <span>{{ title }}</span>
7
- </slot>
8
- <div>
9
- <TMagicButton link size="small" @click="closeHandler"><MIcon :icon="Close"></MIcon></TMagicButton>
10
- </div>
11
- </div>
12
- <div class="m-editor-float-box-body" :style="{ height: `${bodyHeight}px` }">
13
- <slot name="body"></slot>
14
- </div>
15
- </div>
16
- </Teleport>
17
- </template>
18
-
19
- <script setup lang="ts">
20
- import { computed, inject, nextTick, onBeforeUnmount, provide, ref, watch } from 'vue';
21
- import { Close } from '@element-plus/icons-vue';
22
- import VanillaMoveable from 'moveable';
23
-
24
- import { TMagicButton, useZIndex } from '@tmagic/design';
25
-
26
- import MIcon from '@editor/components/Icon.vue';
27
- import type { Services } from '@editor/type';
28
-
29
- interface Position {
30
- left: number;
31
- top: number;
32
- }
33
-
34
- const width = defineModel<number>('width', { default: 0 });
35
- const height = defineModel<number>('height', { default: 0 });
36
- const visible = defineModel<boolean>('visible', { default: false });
37
-
38
- const props = withDefaults(
39
- defineProps<{
40
- position?: Position;
41
- title?: string;
42
- beforeClose?: (done: (cancel?: boolean) => void) => void;
43
- }>(),
44
- {
45
- title: '',
46
- position: () => ({ left: 0, top: 0 }),
47
- },
48
- );
49
-
50
- const target = ref<HTMLDivElement>();
51
- const titleEl = ref<HTMLDivElement>();
52
-
53
- const zIndex = useZIndex();
54
- const curZIndex = ref<number>(0);
55
-
56
- const titleHeight = ref(0);
57
- const bodyHeight = computed(() => {
58
- if (height.value) {
59
- return height.value - titleHeight.value;
60
- }
61
-
62
- if (target.value) {
63
- return target.value.clientHeight - titleHeight.value;
64
- }
65
-
66
- return 'auto';
67
- });
68
-
69
- const services = inject<Services>('services');
70
- const frameworkWidth = computed(() => services?.uiService.get('frameworkRect').width || 0);
71
- const style = computed(() => {
72
- let { left } = props.position;
73
- if (width.value) {
74
- left = left + width.value > frameworkWidth.value ? frameworkWidth.value - width.value : left;
75
- }
76
-
77
- return {
78
- left: `${left}px`,
79
- top: `${props.position.top}px`,
80
- width: width.value ? `${width.value}px` : 'auto',
81
- height: height.value ? `${height.value}px` : 'auto',
82
- };
83
- });
84
-
85
- let moveable: VanillaMoveable | null = null;
86
-
87
- const initMoveable = () => {
88
- moveable = new VanillaMoveable(globalThis.document.body, {
89
- className: 'm-editor-floating-box-moveable',
90
- target: target.value,
91
- draggable: true,
92
- resizable: true,
93
- edge: true,
94
- keepRatio: false,
95
- origin: false,
96
- snappable: true,
97
- dragTarget: titleEl.value,
98
- dragTargetSelf: false,
99
- linePadding: 10,
100
- controlPadding: 10,
101
- bounds: { left: 0, top: 0, right: 0, bottom: 0, position: 'css' },
102
- });
103
-
104
- moveable.on('drag', (e) => {
105
- e.target.style.transform = e.transform;
106
- });
107
-
108
- moveable.on('resize', (e) => {
109
- width.value = e.width;
110
- height.value = e.height;
111
- e.target.style.width = `${e.width}px`;
112
- e.target.style.height = `${e.height}px`;
113
- e.target.style.transform = e.drag.transform;
114
- });
115
- };
116
-
117
- const destroyMoveable = () => {
118
- moveable?.destroy();
119
- moveable = null;
120
- };
121
-
122
- watch(
123
- visible,
124
- async (visible) => {
125
- if (visible) {
126
- await nextTick();
127
- curZIndex.value = zIndex.nextZIndex();
128
-
129
- const targetRect = target.value?.getBoundingClientRect();
130
- if (targetRect) {
131
- width.value = targetRect.width;
132
- height.value = targetRect.height;
133
- initMoveable();
134
- }
135
-
136
- if (titleEl.value) {
137
- const titleRect = titleEl.value.getBoundingClientRect();
138
- titleHeight.value = titleRect.height;
139
- }
140
- } else {
141
- destroyMoveable();
142
- }
143
- },
144
- {
145
- immediate: true,
146
- },
147
- );
148
-
149
- onBeforeUnmount(() => {
150
- destroyMoveable();
151
- });
152
-
153
- const hide = (cancel?: boolean) => {
154
- if (cancel !== false) {
155
- visible.value = false;
156
- }
157
- };
158
-
159
- const closeHandler = () => {
160
- if (typeof props.beforeClose === 'function') {
161
- props.beforeClose(hide);
162
- } else {
163
- hide();
164
- }
165
- };
166
-
167
- const nextZIndex = () => {
168
- curZIndex.value = zIndex.nextZIndex();
169
- };
170
-
171
- provide('parentFloating', target);
172
-
173
- defineExpose({
174
- bodyHeight,
175
- target,
176
- titleEl,
177
- });
178
- </script>