@tmagic/editor 1.0.6 → 1.1.0-beta.10

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 (105) hide show
  1. package/dist/style.css +5 -1
  2. package/dist/{tmagic-editor.es.js → tmagic-editor.mjs} +1522 -1177
  3. package/dist/tmagic-editor.mjs.map +1 -0
  4. package/dist/tmagic-editor.umd.js +1606 -1259
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/package.json +22 -20
  7. package/src/Editor.vue +41 -15
  8. package/src/components/ContentMenu.vue +87 -99
  9. package/src/components/Icon.vue +2 -2
  10. package/src/components/ScrollViewer.vue +2 -2
  11. package/src/components/ToolButton.vue +151 -168
  12. package/src/fields/UISelect.vue +49 -70
  13. package/src/index.ts +2 -1
  14. package/src/layouts/AddPageBox.vue +3 -3
  15. package/src/layouts/Framework.vue +1 -1
  16. package/src/layouts/NavMenu.vue +2 -2
  17. package/src/layouts/PropsPanel.vue +1 -1
  18. package/src/layouts/Resizer.vue +1 -1
  19. package/src/layouts/sidebar/ComponentListPanel.vue +43 -2
  20. package/src/layouts/sidebar/LayerMenu.vue +3 -3
  21. package/src/layouts/sidebar/LayerPanel.vue +13 -4
  22. package/src/layouts/sidebar/Sidebar.vue +1 -1
  23. package/src/layouts/sidebar/TabPane.vue +3 -3
  24. package/src/layouts/workspace/PageBar.vue +63 -192
  25. package/src/layouts/workspace/PageBarScrollContainer.vue +111 -0
  26. package/src/layouts/workspace/Stage.vue +208 -188
  27. package/src/layouts/workspace/ViewerMenu.vue +141 -148
  28. package/src/layouts/workspace/Workspace.vue +11 -11
  29. package/src/services/BaseService.ts +5 -10
  30. package/src/services/componentList.ts +3 -3
  31. package/src/services/editor.ts +247 -140
  32. package/src/services/events.ts +1 -1
  33. package/src/services/history.ts +1 -1
  34. package/src/services/props.ts +63 -11
  35. package/src/services/storage.ts +133 -0
  36. package/src/services/ui.ts +10 -4
  37. package/src/theme/component-list-panel.scss +5 -0
  38. package/src/theme/framework.scss +1 -1
  39. package/src/theme/stage.scss +2 -2
  40. package/src/type.ts +28 -7
  41. package/src/utils/config.ts +1 -1
  42. package/src/utils/editor.ts +53 -35
  43. package/src/utils/operator.ts +109 -0
  44. package/src/utils/props.ts +2 -24
  45. package/src/utils/scroll-viewer.ts +1 -1
  46. package/tsconfig.build.json +13 -0
  47. package/{dist/types/src → types}/Editor.vue.d.ts +44 -9
  48. package/types/components/ContentMenu.vue.d.ts +116 -0
  49. package/types/components/Icon.vue.d.ts +13 -0
  50. package/types/components/ScrollViewer.vue.d.ts +22 -0
  51. package/types/components/ToolButton.vue.d.ts +109 -0
  52. package/types/fields/Code.vue.d.ts +23 -0
  53. package/{dist/types/src → types}/fields/CodeLink.vue.d.ts +4 -6
  54. package/types/fields/UISelect.vue.d.ts +83 -0
  55. package/{dist/types/src → types}/index.d.ts +4 -1
  56. package/types/layouts/AddPageBox.vue.d.ts +4 -0
  57. package/{dist/types/src → types}/layouts/CodeEditor.vue.d.ts +11 -13
  58. package/types/layouts/Framework.vue.d.ts +22 -0
  59. package/types/layouts/NavMenu.vue.d.ts +25 -0
  60. package/types/layouts/PropsPanel.vue.d.ts +245 -0
  61. package/types/layouts/Resizer.vue.d.ts +12 -0
  62. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +14 -0
  63. package/types/layouts/sidebar/LayerMenu.vue.d.ts +100 -0
  64. package/types/layouts/sidebar/LayerPanel.vue.d.ts +1099 -0
  65. package/{dist/types/src → types}/layouts/sidebar/Sidebar.vue.d.ts +3 -5
  66. package/types/layouts/sidebar/TabPane.vue.d.ts +14 -0
  67. package/types/layouts/workspace/PageBar.vue.d.ts +54 -0
  68. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +48 -0
  69. package/types/layouts/workspace/Stage.vue.d.ts +46 -0
  70. package/types/layouts/workspace/ViewerMenu.vue.d.ts +88 -0
  71. package/types/layouts/workspace/Workspace.vue.d.ts +6 -0
  72. package/{dist/types/src → types}/services/BaseService.d.ts +0 -0
  73. package/types/services/componentList.d.ts +14 -0
  74. package/{dist/types/src → types}/services/editor.d.ts +27 -14
  75. package/{dist/types/src → types}/services/events.d.ts +0 -0
  76. package/{dist/types/src → types}/services/history.d.ts +0 -0
  77. package/{dist/types/src → types}/services/props.d.ts +26 -2
  78. package/types/services/storage.d.ts +56 -0
  79. package/{dist/types/src → types}/services/ui.d.ts +1 -1
  80. package/{dist/types/src → types}/type.d.ts +21 -1
  81. package/{dist/types/src → types}/utils/compose.d.ts +1 -1
  82. package/{dist/types/src → types}/utils/config.d.ts +0 -0
  83. package/{dist/types/src → types}/utils/editor.d.ts +11 -4
  84. package/{dist/types/src → types}/utils/index.d.ts +0 -0
  85. package/{dist/types/src → types}/utils/logger.d.ts +0 -0
  86. package/types/utils/operator.d.ts +21 -0
  87. package/{dist/types/src → types}/utils/polyfills.d.ts +0 -0
  88. package/{dist/types/src → types}/utils/props.d.ts +2 -22
  89. package/{dist/types/src → types}/utils/scroll-viewer.d.ts +0 -0
  90. package/{dist/types/src → types}/utils/undo-redo.d.ts +0 -0
  91. package/dist/tmagic-editor.es.js.map +0 -1
  92. package/dist/types/src/components/Icon.vue.d.ts +0 -14
  93. package/dist/types/src/components/ScrollViewer.vue.d.ts +0 -24
  94. package/dist/types/src/fields/Code.vue.d.ts +0 -25
  95. package/dist/types/src/layouts/AddPageBox.vue.d.ts +0 -5
  96. package/dist/types/src/layouts/Framework.vue.d.ts +0 -24
  97. package/dist/types/src/layouts/NavMenu.vue.d.ts +0 -27
  98. package/dist/types/src/layouts/PropsPanel.vue.d.ts +0 -13
  99. package/dist/types/src/layouts/Resizer.vue.d.ts +0 -14
  100. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -14
  101. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +0 -16
  102. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +0 -8
  103. package/dist/types/src/shims-vue.d.ts +0 -6
  104. package/dist/types/src/vite-env.d.ts +0 -1
  105. package/src/vite-env.d.ts +0 -1
@@ -50,180 +50,163 @@
50
50
  </div>
51
51
  </template>
52
52
 
53
- <script lang="ts">
54
- import { computed, defineComponent, inject, markRaw, PropType } from 'vue';
55
- import { ArrowDown, Back, Delete, Grid, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons';
53
+ <script lang="ts" setup>
54
+ import { computed, inject, markRaw, PropType } from 'vue';
55
+ import { ArrowDown, Back, Delete, Grid, Right, ScaleToOriginal, ZoomIn, ZoomOut } from '@element-plus/icons-vue';
56
56
 
57
57
  import { NodeType } from '@tmagic/schema';
58
58
 
59
- import MIcon from '@editor/components/Icon.vue';
60
- import type { MenuButton, MenuComponent, MenuItem, Services } from '@editor/type';
59
+ import MIcon from '../components/Icon.vue';
60
+ import type { MenuButton, MenuComponent, MenuItem, Services } from '../type';
61
+
62
+ const props = defineProps({
63
+ data: {
64
+ type: [Object, String] as PropType<MenuItem | string>,
65
+ require: true,
66
+ default: () => ({
67
+ type: 'text',
68
+ display: false,
69
+ }),
70
+ },
61
71
 
62
- export default defineComponent({
63
- components: { MIcon, ArrowDown },
72
+ eventType: {
73
+ type: String as PropType<'mousedown' | 'mouseup' | 'click'>,
74
+ default: 'click',
75
+ },
76
+ });
64
77
 
65
- props: {
66
- data: {
67
- type: [Object, String] as PropType<MenuItem | string>,
68
- require: true,
69
- default: () => ({
78
+ const services = inject<Services>('services');
79
+ const uiService = services?.uiService;
80
+
81
+ const zoom = computed((): number => uiService?.get<number>('zoom') ?? 1);
82
+ const showGuides = computed((): boolean => uiService?.get<boolean>('showGuides') ?? true);
83
+ const showRule = computed((): boolean => uiService?.get<boolean>('showRule') ?? true);
84
+
85
+ const zoomInHandler = () => uiService?.zoom(0.1);
86
+ const zoomOutHandler = () => uiService?.zoom(-0.1);
87
+
88
+ const item = computed((): MenuButton | MenuComponent => {
89
+ if (typeof props.data !== 'string') {
90
+ return props.data;
91
+ }
92
+ switch (props.data) {
93
+ case '/':
94
+ return {
95
+ type: 'divider',
96
+ };
97
+ case 'zoom':
98
+ return {
99
+ type: 'zoom',
100
+ };
101
+ case 'delete':
102
+ return {
103
+ type: 'button',
104
+ icon: markRaw(Delete),
105
+ tooltip: '刪除',
106
+ disabled: () => services?.editorService.get('node')?.type === NodeType.PAGE,
107
+ handler: () => services?.editorService.remove(services?.editorService.get('node')),
108
+ };
109
+ case 'undo':
110
+ return {
111
+ type: 'button',
112
+ icon: markRaw(Back),
113
+ tooltip: '后退',
114
+ disabled: () => !services?.historyService.state.canUndo,
115
+ handler: () => services?.editorService.undo(),
116
+ };
117
+ case 'redo':
118
+ return {
119
+ type: 'button',
120
+ icon: markRaw(Right),
121
+ tooltip: '前进',
122
+ disabled: () => !services?.historyService.state.canRedo,
123
+ handler: () => services?.editorService.redo(),
124
+ };
125
+ case 'zoom-in':
126
+ return {
127
+ type: 'button',
128
+ icon: markRaw(ZoomIn),
129
+ tooltip: '放大',
130
+ handler: zoomInHandler,
131
+ };
132
+ case 'zoom-out':
133
+ return {
134
+ type: 'button',
135
+ icon: markRaw(ZoomOut),
136
+ tooltip: '縮小',
137
+ handler: zoomOutHandler,
138
+ };
139
+ case 'rule':
140
+ return {
141
+ type: 'button',
142
+ icon: markRaw(ScaleToOriginal),
143
+ tooltip: showRule.value ? '隐藏标尺' : '显示标尺',
144
+ handler: () => uiService?.set('showRule', !showRule.value),
145
+ };
146
+ case 'guides':
147
+ return {
148
+ type: 'button',
149
+ icon: markRaw(Grid),
150
+ tooltip: showGuides.value ? '隐藏参考线' : '显示参考线',
151
+ handler: () => uiService?.set('showGuides', !showGuides.value),
152
+ };
153
+ default:
154
+ return {
70
155
  type: 'text',
71
- display: false,
72
- }),
73
- },
74
-
75
- eventType: {
76
- type: String as PropType<'mousedown' | 'mouseup' | 'click'>,
77
- default: 'click',
78
- },
79
- },
156
+ text: props.data,
157
+ };
158
+ }
159
+ });
80
160
 
81
- setup(props) {
82
- const services = inject<Services>('services');
83
- const uiService = services?.uiService;
84
-
85
- const zoom = computed((): number => uiService?.get<number>('zoom') ?? 1);
86
- const showGuides = computed((): boolean => uiService?.get<boolean>('showGuides') ?? true);
87
- const showRule = computed((): boolean => uiService?.get<boolean>('showRule') ?? true);
88
-
89
- const zoomInHandler = () => uiService?.zoom(0.1);
90
- const zoomOutHandler = () => uiService?.zoom(-0.1);
91
-
92
- const item = computed((): MenuButton | MenuComponent => {
93
- if (typeof props.data !== 'string') {
94
- return props.data;
95
- }
96
- switch (props.data) {
97
- case '/':
98
- return {
99
- type: 'divider',
100
- };
101
- case 'zoom':
102
- return {
103
- type: 'zoom',
104
- };
105
- case 'delete':
106
- return {
107
- type: 'button',
108
- icon: markRaw(Delete),
109
- tooltip: '刪除',
110
- disabled: () => services?.editorService.get('node')?.type === NodeType.PAGE,
111
- handler: () => services?.editorService.remove(services?.editorService.get('node')),
112
- };
113
- case 'undo':
114
- return {
115
- type: 'button',
116
- icon: markRaw(Back),
117
- tooltip: '后退',
118
- disabled: () => !services?.historyService.state.canUndo,
119
- handler: () => services?.editorService.undo(),
120
- };
121
- case 'redo':
122
- return {
123
- type: 'button',
124
- icon: markRaw(Right),
125
- tooltip: '前进',
126
- disabled: () => !services?.historyService.state.canRedo,
127
- handler: () => services?.editorService.redo(),
128
- };
129
- case 'zoom-in':
130
- return {
131
- type: 'button',
132
- icon: markRaw(ZoomIn),
133
- tooltip: '放大',
134
- handler: zoomInHandler,
135
- };
136
- case 'zoom-out':
137
- return {
138
- type: 'button',
139
- icon: markRaw(ZoomOut),
140
- tooltip: '縮小',
141
- handler: zoomOutHandler,
142
- };
143
- case 'rule':
144
- return {
145
- type: 'button',
146
- icon: markRaw(ScaleToOriginal),
147
- tooltip: showRule.value ? '隐藏标尺' : '显示标尺',
148
- handler: () => uiService?.set('showRule', !showRule.value),
149
- };
150
- case 'guides':
151
- return {
152
- type: 'button',
153
- icon: markRaw(Grid),
154
- tooltip: showGuides.value ? '隐藏参考线' : '显示参考线',
155
- handler: () => uiService?.set('showGuides', !showGuides.value),
156
- };
157
- default:
158
- return {
159
- type: 'text',
160
- text: props.data,
161
- };
162
- }
163
- });
164
-
165
- const disabled = computed(() => {
166
- if (typeof item.value === 'string') return false;
167
- if (item.value.type === 'component') return false;
168
- if (typeof item.value.disabled === 'function') {
169
- return item.value.disabled(services);
170
- }
171
- return item.value.disabled;
172
- });
173
-
174
- const buttonHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
175
- if (disabled.value) return;
176
- if (typeof (item as MenuButton).handler === 'function' && services) {
177
- (item as MenuButton).handler?.(services, event);
178
- }
179
- };
180
-
181
- return {
182
- ZoomIn: markRaw(ZoomIn),
183
- ZoomOut: markRaw(ZoomOut),
184
-
185
- item,
186
- zoom,
187
- disabled,
188
- display: computed(() => {
189
- if (!item.value) return false;
190
- if (typeof item.value === 'string') return true;
191
- if (typeof item.value.display === 'function') {
192
- return item.value.display(services);
193
- }
194
- return item.value.display ?? true;
195
- }),
196
-
197
- zoomInHandler,
198
- zoomOutHandler,
199
-
200
- dropdownHandler(command: any) {
201
- if (command.item.handler) {
202
- command.item.handler(services);
203
- }
204
- },
205
-
206
- clickHandler(item: MenuButton | MenuComponent, event: MouseEvent) {
207
- if (props.eventType !== 'click') return;
208
- if (item.type === 'button') {
209
- buttonHandler(item, event);
210
- }
211
- },
212
-
213
- mousedownHandler(item: MenuButton | MenuComponent, event: MouseEvent) {
214
- if (props.eventType !== 'mousedown') return;
215
- if (item.type === 'button') {
216
- buttonHandler(item, event);
217
- }
218
- },
219
-
220
- mouseupHandler(item: MenuButton | MenuComponent, event: MouseEvent) {
221
- if (props.eventType !== 'mouseup') return;
222
- if (item.type === 'button') {
223
- buttonHandler(item, event);
224
- }
225
- },
226
- };
227
- },
161
+ const disabled = computed(() => {
162
+ if (typeof item.value === 'string') return false;
163
+ if (item.value.type === 'component') return false;
164
+ if (typeof item.value.disabled === 'function') {
165
+ return item.value.disabled(services);
166
+ }
167
+ return item.value.disabled;
168
+ });
169
+
170
+ const buttonHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
171
+ if (disabled.value) return;
172
+ if (typeof (item as MenuButton).handler === 'function' && services) {
173
+ (item as MenuButton).handler?.(services, event);
174
+ }
175
+ };
176
+
177
+ const display = computed(() => {
178
+ if (!item.value) return false;
179
+ if (typeof item.value === 'string') return true;
180
+ if (typeof item.value.display === 'function') {
181
+ return item.value.display(services);
182
+ }
183
+ return item.value.display ?? true;
228
184
  });
185
+
186
+ const dropdownHandler = (command: any) => {
187
+ if (command.item.handler) {
188
+ command.item.handler(services);
189
+ }
190
+ };
191
+
192
+ const clickHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
193
+ if (props.eventType !== 'click') return;
194
+ if (item.type === 'button') {
195
+ buttonHandler(item, event);
196
+ }
197
+ };
198
+
199
+ const mousedownHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
200
+ if (props.eventType !== 'mousedown') return;
201
+ if (item.type === 'button') {
202
+ buttonHandler(item, event);
203
+ }
204
+ };
205
+
206
+ const mouseupHandler = (item: MenuButton | MenuComponent, event: MouseEvent) => {
207
+ if (props.eventType !== 'mouseup') return;
208
+ if (item.type === 'button') {
209
+ buttonHandler(item, event);
210
+ }
211
+ };
229
212
  </script>
@@ -12,89 +12,68 @@
12
12
  </div>
13
13
  </template>
14
14
 
15
- <script lang="ts">
16
- import { computed, defineComponent, inject, markRaw, ref } from 'vue';
17
- import { Close, Delete, Pointer } from '@element-plus/icons';
15
+ <script lang="ts" setup>
16
+ import { computed, inject, ref } from 'vue';
17
+ import { Close, Delete } from '@element-plus/icons-vue';
18
18
 
19
19
  import { FormState } from '@tmagic/form';
20
20
 
21
- import { Services } from '@editor/type';
21
+ import { Services } from '../type';
22
22
 
23
- export default defineComponent({
24
- name: 'm-fields-ui-select',
23
+ const props = defineProps<{
24
+ config: any;
25
+ model: any;
26
+ prop: string;
27
+ name: string;
28
+ }>();
25
29
 
26
- props: {
27
- labelWidth: String,
28
- config: Object,
29
- model: Object,
30
- prop: {
31
- type: String,
32
- default() {
33
- return '';
34
- },
35
- },
36
- name: String,
37
- },
30
+ const emit = defineEmits(['change']);
38
31
 
39
- emits: ['change'],
32
+ const services = inject<Services>('services');
33
+ const mForm = inject<FormState>('mForm');
34
+ const val = computed(() => props.model[props.name]);
35
+ const uiSelectMode = ref(false);
40
36
 
41
- setup(props: any, { emit }) {
42
- const services = inject<Services>('services');
43
- const mForm = inject<FormState>('mForm');
44
- const val = computed(() => props.model[props.name]);
45
- const uiSelectMode = ref(false);
37
+ const cancelHandler = () => {
38
+ if (!services?.uiService) return;
39
+ services.uiService.set<boolean>('uiSelectMode', false);
40
+ uiSelectMode.value = false;
41
+ globalThis.document.removeEventListener('ui-select', clickHandler as EventListener);
42
+ };
46
43
 
47
- const cancelHandler = () => {
48
- if (!services?.uiService) return;
49
- services.uiService.set<boolean>('uiSelectMode', false);
50
- uiSelectMode.value = false;
51
- globalThis.document.removeEventListener('ui-select', clickHandler as EventListener);
52
- };
53
-
54
- const clickHandler = ({ detail }: Event & { detail: any }) => {
55
- if (detail.id) {
56
- props.model[props.name] = detail.id;
57
- emit('change', detail.id);
58
- mForm?.$emit('field-change', props.prop, detail.id);
59
- }
60
-
61
- if (cancelHandler) {
62
- cancelHandler();
63
- }
64
- };
65
-
66
- return {
67
- Delete: markRaw(Delete),
68
- Pointer: markRaw(Pointer),
69
- Close: markRaw(Close),
44
+ const clickHandler = ({ detail }: Event & { detail: any }) => {
45
+ if (detail.id) {
46
+ props.model[props.name] = detail.id;
47
+ emit('change', detail.id);
48
+ mForm?.$emit('field-change', props.prop, detail.id);
49
+ }
70
50
 
71
- val,
72
- uiSelectMode,
73
- toName: computed(() => {
74
- const config = services?.editorService.getNodeById(val.value);
75
- return config?.name || '';
76
- }),
51
+ if (cancelHandler) {
52
+ cancelHandler();
53
+ }
54
+ };
77
55
 
78
- startSelect() {
79
- if (!services?.uiService) return;
80
- services.uiService.set<boolean>('uiSelectMode', true);
81
- uiSelectMode.value = true;
82
- globalThis.document.addEventListener('ui-select', clickHandler as EventListener);
83
- },
56
+ const toName = computed(() => {
57
+ const config = services?.editorService.getNodeById(val.value);
58
+ return config?.name || '';
59
+ });
84
60
 
85
- cancelHandler,
61
+ const startSelect = () => {
62
+ if (!services?.uiService) return;
63
+ services.uiService.set<boolean>('uiSelectMode', true);
64
+ uiSelectMode.value = true;
65
+ globalThis.document.addEventListener('ui-select', clickHandler as EventListener);
66
+ };
86
67
 
87
- deleteHandler() {
88
- if (props.model) {
89
- props.model[props.name] = '';
90
- emit('change', '');
91
- mForm?.$emit('field-change', props.prop, '');
92
- }
93
- },
94
- };
95
- },
96
- });
68
+ const deleteHandler = () => {
69
+ if (props.model) {
70
+ props.model[props.name] = '';
71
+ emit('change', '');
72
+ mForm?.$emit('field-change', props.prop, '');
73
+ }
74
+ };
97
75
  </script>
76
+
98
77
  <style lang="scss">
99
78
  .m-fields-ui-select {
100
79
  cursor: pointer;
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ export { default as TMagicCodeEditor } from './layouts/CodeEditor.vue';
37
37
  export { default as editorService } from './services/editor';
38
38
  export { default as propsService } from './services/props';
39
39
  export { default as historyService } from './services/history';
40
+ export { default as storageService } from './services/storage';
40
41
  export { default as eventsService } from './services/events';
41
42
  export { default as uiService } from './services/ui';
42
43
  export { default as ComponentListPanel } from './layouts/sidebar/ComponentListPanel.vue';
@@ -57,7 +58,7 @@ export default {
57
58
  setConfig(option);
58
59
 
59
60
  app.component(Editor.name, Editor);
60
- app.component(uiSelect.name, uiSelect);
61
+ app.component('m-fields-ui-select', uiSelect);
61
62
  app.component(CodeLink.name, CodeLink);
62
63
  app.component(Code.name, Code);
63
64
  app.component(CodeEditor.name, CodeEditor);
@@ -13,12 +13,12 @@
13
13
 
14
14
  <script lang="ts">
15
15
  import { defineComponent, inject, toRaw } from 'vue';
16
- import { Plus } from '@element-plus/icons';
16
+ import { Plus } from '@element-plus/icons-vue';
17
17
 
18
18
  import { NodeType } from '@tmagic/schema';
19
19
 
20
- import type { Services } from '@editor/type';
21
- import { generatePageNameByApp } from '@editor/utils';
20
+ import type { Services } from '../type';
21
+ import { generatePageNameByApp } from '../utils';
22
22
 
23
23
  export default defineComponent({
24
24
  components: { Plus },
@@ -43,7 +43,7 @@ import { computed, defineComponent, inject } from 'vue';
43
43
 
44
44
  import type { MApp } from '@tmagic/schema';
45
45
 
46
- import { GetColumnWidth, Services } from '@editor/type';
46
+ import { GetColumnWidth, Services } from '../type';
47
47
 
48
48
  import AddPageBox from './AddPageBox.vue';
49
49
  import Resizer from './Resizer.vue';
@@ -9,8 +9,8 @@
9
9
  <script lang="ts">
10
10
  import { computed, defineComponent, inject, PropType } from 'vue';
11
11
 
12
- import ToolButton from '@editor/components/ToolButton.vue';
13
- import { GetColumnWidth, MenuBarData, Services } from '@editor/type';
12
+ import ToolButton from '../components/ToolButton.vue';
13
+ import { GetColumnWidth, MenuBarData, Services } from '../type';
14
14
 
15
15
  export default defineComponent({
16
16
  name: 'nav-menu',
@@ -20,7 +20,7 @@ import { ElMessage } from 'element-plus';
20
20
  import type { FormValue, MForm } from '@tmagic/form';
21
21
  import type { MNode } from '@tmagic/schema';
22
22
 
23
- import type { Services } from '@editor/type';
23
+ import type { Services } from '../type';
24
24
 
25
25
  export default defineComponent({
26
26
  name: 'm-editor-props-panel',
@@ -8,7 +8,7 @@
8
8
  import { defineComponent, inject, onMounted, onUnmounted, ref, toRaw } from 'vue';
9
9
  import Gesto from 'gesto';
10
10
 
11
- import { Services } from '@editor/type';
11
+ import { Services } from '../type';
12
12
 
13
13
  export default defineComponent({
14
14
  name: 'm-editor-resize',
@@ -21,6 +21,8 @@
21
21
  :key="item.type"
22
22
  @click="appendComponent(item)"
23
23
  @dragstart="dragstartHandler(item, $event)"
24
+ @dragend="dragendHandler"
25
+ @drag="dragHandler"
24
26
  >
25
27
  <m-icon :icon="item.icon"></m-icon>
26
28
 
@@ -38,8 +40,11 @@
38
40
  import { computed, defineComponent, inject, ref } from 'vue';
39
41
  import serialize from 'serialize-javascript';
40
42
 
41
- import MIcon from '@editor/components/Icon.vue';
42
- import type { ComponentGroup, ComponentItem, Services } from '@editor/type';
43
+ import type StageCore from '@tmagic/stage';
44
+ import { removeClassNameByClassName } from '@tmagic/utils';
45
+
46
+ import MIcon from '../../components/Icon.vue';
47
+ import type { ComponentGroup, ComponentItem, Services, StageOptions } from '../../type';
43
48
 
44
49
  export default defineComponent({
45
50
  name: 'ui-component-panel',
@@ -49,6 +54,9 @@ export default defineComponent({
49
54
  setup() {
50
55
  const searchText = ref('');
51
56
  const services = inject<Services>('services');
57
+ const stageOptions = inject<StageOptions>('stageOptions');
58
+
59
+ const stage = computed(() => services?.editorService.get<StageCore>('stage'));
52
60
  const list = computed(() =>
53
61
  services?.componentListService.getList().map((group: ComponentGroup) => ({
54
62
  ...group,
@@ -61,6 +69,10 @@ export default defineComponent({
61
69
  .map((x, i) => i),
62
70
  );
63
71
 
72
+ let timeout: NodeJS.Timeout | undefined;
73
+ let clientX: number;
74
+ let clientY: number;
75
+
64
76
  return {
65
77
  searchText,
66
78
  collapseValue,
@@ -87,6 +99,35 @@ export default defineComponent({
87
99
  );
88
100
  }
89
101
  },
102
+
103
+ dragendHandler() {
104
+ if (timeout) {
105
+ globalThis.clearTimeout(timeout);
106
+ timeout = undefined;
107
+ }
108
+ const doc = stage.value?.renderer.contentWindow?.document;
109
+ if (doc && stageOptions) {
110
+ removeClassNameByClassName(doc, stageOptions.containerHighlightClassName);
111
+ }
112
+ clientX = 0;
113
+ clientY = 0;
114
+ },
115
+
116
+ dragHandler(e: DragEvent) {
117
+ if (e.clientX !== clientX || e.clientY !== clientY) {
118
+ clientX = e.clientX;
119
+ clientY = e.clientY;
120
+ if (timeout) {
121
+ globalThis.clearTimeout(timeout);
122
+ timeout = undefined;
123
+ }
124
+ return;
125
+ }
126
+
127
+ if (timeout || !stage.value) return;
128
+
129
+ timeout = stage.value.getAddContainerHighlightClassNameTimeout(e);
130
+ },
90
131
  };
91
132
  },
92
133
  });
@@ -4,12 +4,12 @@
4
4
 
5
5
  <script lang="ts">
6
6
  import { computed, defineComponent, inject, markRaw, ref } from 'vue';
7
- import { Delete, DocumentCopy, Files, Plus } from '@element-plus/icons';
7
+ import { Delete, DocumentCopy, Files, Plus } from '@element-plus/icons-vue';
8
8
 
9
9
  import { NodeType } from '@tmagic/schema';
10
10
 
11
- import ContentMenu from '@editor/components/ContentMenu.vue';
12
- import type { ComponentGroup, MenuButton, MenuItem, Services } from '@editor/type';
11
+ import ContentMenu from '../../components/ContentMenu.vue';
12
+ import type { ComponentGroup, MenuButton, MenuItem, Services } from '../../type';
13
13
 
14
14
  export default defineComponent({
15
15
  components: { ContentMenu },
@@ -61,11 +61,12 @@ import type { ElTree } from 'element-plus';
61
61
  import { throttle } from 'lodash-es';
62
62
 
63
63
  import type { MNode, MPage } from '@tmagic/schema';
64
- import { NodeType } from '@tmagic/schema';
64
+ import { MContainer, NodeType } from '@tmagic/schema';
65
65
  import StageCore from '@tmagic/stage';
66
66
 
67
- import type { EditorService } from '@editor/services/editor';
68
- import type { Services } from '@editor/type';
67
+ import type { EditorService } from '../../services/editor';
68
+ import type { Services } from '../../type';
69
+ import { Layout } from '../../type';
69
70
 
70
71
  import LayerMenu from './LayerMenu.vue';
71
72
 
@@ -104,8 +105,16 @@ const useDrop = (tree: Ref<InstanceType<typeof ElTree> | undefined>, editorServi
104
105
  return false;
105
106
  },
106
107
 
107
- handleDragEnd() {
108
+ async handleDragEnd(e: any) {
108
109
  if (!tree.value) return;
110
+ const { data: node } = e;
111
+ const parent = editorService?.getParentById(node.id, false) as MContainer;
112
+ const layout = await editorService?.getLayout(parent);
113
+ node.style.position = layout;
114
+ if (layout === Layout.RELATIVE) {
115
+ node.style.top = 0;
116
+ node.style.left = 0;
117
+ }
109
118
  const { data } = tree.value;
110
119
  const [page] = data as [MPage];
111
120
  editorService?.update(page);