@tmagic/editor 1.1.0-beta.4 → 1.1.0-beta.7

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 (100) hide show
  1. package/dist/{tmagic-editor.es.js → tmagic-editor.mjs} +1361 -1144
  2. package/dist/tmagic-editor.mjs.map +1 -0
  3. package/dist/tmagic-editor.umd.js +1375 -1158
  4. package/dist/tmagic-editor.umd.js.map +1 -1
  5. package/package.json +21 -19
  6. package/src/Editor.vue +14 -12
  7. package/src/components/ContentMenu.vue +87 -99
  8. package/src/components/ScrollViewer.vue +1 -1
  9. package/src/components/ToolButton.vue +150 -167
  10. package/src/fields/UISelect.vue +49 -70
  11. package/src/index.ts +2 -1
  12. package/src/layouts/AddPageBox.vue +2 -2
  13. package/src/layouts/Framework.vue +1 -1
  14. package/src/layouts/NavMenu.vue +2 -2
  15. package/src/layouts/PropsPanel.vue +1 -1
  16. package/src/layouts/Resizer.vue +1 -1
  17. package/src/layouts/sidebar/ComponentListPanel.vue +2 -2
  18. package/src/layouts/sidebar/LayerMenu.vue +2 -2
  19. package/src/layouts/sidebar/LayerPanel.vue +13 -4
  20. package/src/layouts/sidebar/Sidebar.vue +1 -1
  21. package/src/layouts/sidebar/TabPane.vue +2 -2
  22. package/src/layouts/workspace/PageBar.vue +63 -192
  23. package/src/layouts/workspace/PageBarScrollContainer.vue +111 -0
  24. package/src/layouts/workspace/Stage.vue +195 -222
  25. package/src/layouts/workspace/ViewerMenu.vue +142 -146
  26. package/src/layouts/workspace/Workspace.vue +11 -11
  27. package/src/services/BaseService.ts +1 -1
  28. package/src/services/componentList.ts +3 -3
  29. package/src/services/editor.ts +117 -135
  30. package/src/services/events.ts +1 -1
  31. package/src/services/history.ts +1 -1
  32. package/src/services/props.ts +62 -10
  33. package/src/services/storage.ts +133 -0
  34. package/src/services/ui.ts +2 -2
  35. package/src/type.ts +22 -6
  36. package/src/utils/config.ts +1 -1
  37. package/src/utils/editor.ts +1 -1
  38. package/src/utils/operator.ts +210 -0
  39. package/src/utils/props.ts +2 -24
  40. package/src/utils/scroll-viewer.ts +1 -1
  41. package/tsconfig.build.json +13 -0
  42. package/{dist/types/src → types}/Editor.vue.d.ts +7 -8
  43. package/types/components/ContentMenu.vue.d.ts +116 -0
  44. package/types/components/Icon.vue.d.ts +13 -0
  45. package/types/components/ScrollViewer.vue.d.ts +22 -0
  46. package/types/components/ToolButton.vue.d.ts +109 -0
  47. package/types/fields/Code.vue.d.ts +23 -0
  48. package/{dist/types/src → types}/fields/CodeLink.vue.d.ts +4 -6
  49. package/types/fields/UISelect.vue.d.ts +83 -0
  50. package/{dist/types/src → types}/index.d.ts +4 -1
  51. package/types/layouts/AddPageBox.vue.d.ts +4 -0
  52. package/{dist/types/src → types}/layouts/CodeEditor.vue.d.ts +11 -13
  53. package/types/layouts/Framework.vue.d.ts +22 -0
  54. package/types/layouts/NavMenu.vue.d.ts +25 -0
  55. package/types/layouts/PropsPanel.vue.d.ts +245 -0
  56. package/types/layouts/Resizer.vue.d.ts +12 -0
  57. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +14 -0
  58. package/types/layouts/sidebar/LayerMenu.vue.d.ts +100 -0
  59. package/types/layouts/sidebar/LayerPanel.vue.d.ts +1099 -0
  60. package/{dist/types/src → types}/layouts/sidebar/Sidebar.vue.d.ts +3 -5
  61. package/types/layouts/sidebar/TabPane.vue.d.ts +14 -0
  62. package/types/layouts/workspace/PageBar.vue.d.ts +54 -0
  63. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +48 -0
  64. package/types/layouts/workspace/Stage.vue.d.ts +46 -0
  65. package/types/layouts/workspace/ViewerMenu.vue.d.ts +88 -0
  66. package/types/layouts/workspace/Workspace.vue.d.ts +6 -0
  67. package/{dist/types/src → types}/services/BaseService.d.ts +0 -0
  68. package/types/services/componentList.d.ts +14 -0
  69. package/{dist/types/src → types}/services/editor.d.ts +26 -11
  70. package/{dist/types/src → types}/services/events.d.ts +0 -0
  71. package/{dist/types/src → types}/services/history.d.ts +0 -0
  72. package/{dist/types/src → types}/services/props.d.ts +25 -1
  73. package/types/services/storage.d.ts +56 -0
  74. package/{dist/types/src → types}/services/ui.d.ts +1 -1
  75. package/{dist/types/src → types}/type.d.ts +15 -0
  76. package/{dist/types/src → types}/utils/compose.d.ts +1 -1
  77. package/{dist/types/src → types}/utils/config.d.ts +0 -0
  78. package/{dist/types/src → types}/utils/editor.d.ts +2 -2
  79. package/{dist/types/src → types}/utils/index.d.ts +0 -0
  80. package/{dist/types/src → types}/utils/logger.d.ts +0 -0
  81. package/types/utils/operator.d.ts +44 -0
  82. package/{dist/types/src → types}/utils/polyfills.d.ts +0 -0
  83. package/{dist/types/src → types}/utils/props.d.ts +2 -22
  84. package/{dist/types/src → types}/utils/scroll-viewer.d.ts +0 -0
  85. package/{dist/types/src → types}/utils/undo-redo.d.ts +0 -0
  86. package/dist/tmagic-editor.es.js.map +0 -1
  87. package/dist/types/src/components/Icon.vue.d.ts +0 -14
  88. package/dist/types/src/components/ScrollViewer.vue.d.ts +0 -24
  89. package/dist/types/src/fields/Code.vue.d.ts +0 -25
  90. package/dist/types/src/layouts/AddPageBox.vue.d.ts +0 -5
  91. package/dist/types/src/layouts/Framework.vue.d.ts +0 -24
  92. package/dist/types/src/layouts/NavMenu.vue.d.ts +0 -27
  93. package/dist/types/src/layouts/PropsPanel.vue.d.ts +0 -13
  94. package/dist/types/src/layouts/Resizer.vue.d.ts +0 -14
  95. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +0 -16
  96. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +0 -16
  97. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +0 -8
  98. package/dist/types/src/shims-vue.d.ts +0 -6
  99. package/dist/types/src/vite-env.d.ts +0 -1
  100. package/src/vite-env.d.ts +0 -1
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "version": "1.1.0-beta.4",
2
+ "version": "1.1.0-beta.7",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
6
6
  "src/theme/*"
7
7
  ],
8
8
  "main": "dist/tmagic-editor.umd.js",
9
- "module": "dist/tmagic-editor.es.js",
9
+ "module": "dist/tmagic-editor.mjs",
10
10
  "style": "dist/style.css",
11
- "types": "dist/types/src/index.d.ts",
11
+ "types": "types/index.d.ts",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/tmagic-editor.es.js",
14
+ "import": "./dist/tmagic-editor.mjs",
15
15
  "require": "./dist/tmagic-editor.umd.js"
16
16
  },
17
17
  "./dist/style.css": {
@@ -22,7 +22,9 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "scripts": {
25
- "build": "vue-tsc --noEmit && vite build"
25
+ "build": "npm run build:type && vite build",
26
+ "build:type": "npm run clear:type && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
27
+ "clear:type": "rimraf ./types"
26
28
  },
27
29
  "engines": {
28
30
  "node": ">=14"
@@ -43,11 +45,11 @@
43
45
  "dependencies": {
44
46
  "@babel/core": "^7.18.0",
45
47
  "@element-plus/icons-vue": "^2.0.6",
46
- "@tmagic/core": "1.1.0-beta.4",
47
- "@tmagic/form": "1.1.0-beta.4",
48
- "@tmagic/schema": "1.1.0-beta.4",
49
- "@tmagic/stage": "1.1.0-beta.4",
50
- "@tmagic/utils": "1.1.0-beta.4",
48
+ "@tmagic/core": "1.1.0-beta.7",
49
+ "@tmagic/form": "1.1.0-beta.7",
50
+ "@tmagic/schema": "1.1.0-beta.7",
51
+ "@tmagic/stage": "1.1.0-beta.7",
52
+ "@tmagic/utils": "1.1.0-beta.7",
51
53
  "buffer": "^6.0.3",
52
54
  "color": "^3.1.3",
53
55
  "element-plus": "^2.2.6",
@@ -57,26 +59,26 @@
57
59
  "lodash-es": "^4.17.21",
58
60
  "monaco-editor": "^0.32.1",
59
61
  "serialize-javascript": "^6.0.0",
60
- "vue": "^3.2.0"
62
+ "vue": "^3.2.37"
61
63
  },
62
64
  "peerDependencies": {
63
- "@tmagic/form": "1.1.0-beta.4",
65
+ "@tmagic/form": "1.1.0-beta.7",
64
66
  "element-plus": "^2.2.6",
65
67
  "monaco-editor": "^0.32.1",
66
- "vue": "^3.2.0"
68
+ "vue": "^3.2.37"
67
69
  },
68
70
  "devDependencies": {
69
71
  "@types/events": "^3.0.0",
70
72
  "@types/lodash-es": "^4.17.4",
71
73
  "@types/node": "^15.12.4",
72
74
  "@types/serialize-javascript": "^5.0.1",
73
- "@vitejs/plugin-vue": "^2.3.3",
74
- "@vue/compiler-sfc": "^3.2.0",
75
+ "@vitejs/plugin-vue": "^3.0.1",
76
+ "@vue/compiler-sfc": "^3.2.37",
75
77
  "@vue/test-utils": "^2.0.0",
78
+ "rimraf": "^3.0.2",
76
79
  "sass": "^1.35.1",
77
- "typescript": "^4.3.4",
78
- "vite": "^2.9.13",
79
- "vite-plugin-dts": "^0.9.6",
80
- "vue-tsc": "^0.38.2"
80
+ "typescript": "^4.7.4",
81
+ "vite": "^3.0.4",
82
+ "vue-tsc": "^0.39.4"
81
83
  }
82
84
  }
package/src/Editor.vue CHANGED
@@ -51,18 +51,19 @@ import type { MApp, MNode } from '@tmagic/schema';
51
51
  import type StageCore from '@tmagic/stage';
52
52
  import { CONTAINER_HIGHLIGHT_CLASS, MoveableOptions } from '@tmagic/stage';
53
53
 
54
- import Framework from '@editor/layouts/Framework.vue';
55
- import NavMenu from '@editor/layouts/NavMenu.vue';
56
- import PropsPanel from '@editor/layouts/PropsPanel.vue';
57
- import Sidebar from '@editor/layouts/sidebar/Sidebar.vue';
58
- import Workspace from '@editor/layouts/workspace/Workspace.vue';
59
- import componentListService from '@editor/services/componentList';
60
- import editorService from '@editor/services/editor';
61
- import eventsService from '@editor/services/events';
62
- import historyService from '@editor/services/history';
63
- import propsService from '@editor/services/props';
64
- import uiService from '@editor/services/ui';
65
- import type { ComponentGroup, MenuBarData, MenuItem, Services, SideBarData, StageRect } from '@editor/type';
54
+ import Framework from './layouts/Framework.vue';
55
+ import NavMenu from './layouts/NavMenu.vue';
56
+ import PropsPanel from './layouts/PropsPanel.vue';
57
+ import Sidebar from './layouts/sidebar/Sidebar.vue';
58
+ import Workspace from './layouts/workspace/Workspace.vue';
59
+ import componentListService from './services/componentList';
60
+ import editorService from './services/editor';
61
+ import eventsService from './services/events';
62
+ import historyService from './services/history';
63
+ import propsService from './services/props';
64
+ import storageService from './services/storage';
65
+ import uiService from './services/ui';
66
+ import type { ComponentGroup, MenuBarData, MenuItem, Services, SideBarData, StageRect } from './type';
66
67
 
67
68
  export default defineComponent({
68
69
  name: 'm-editor',
@@ -269,6 +270,7 @@ export default defineComponent({
269
270
  propsService,
270
271
  editorService,
271
272
  uiService,
273
+ storageService,
272
274
  };
273
275
 
274
276
  provide('services', services);
@@ -22,119 +22,107 @@
22
22
  </div>
23
23
  </template>
24
24
 
25
- <script lang="ts">
26
- import { defineComponent, nextTick, onMounted, onUnmounted, PropType, ref } from 'vue';
25
+ <script lang="ts" setup>
26
+ import { nextTick, onMounted, onUnmounted, ref } from 'vue';
27
27
 
28
- import { MenuButton, MenuItem } from '@editor/type';
28
+ import { MenuButton, MenuItem } from '../type';
29
29
 
30
30
  import ToolButton from './ToolButton.vue';
31
31
 
32
- export default defineComponent({
33
- components: { ToolButton },
34
-
35
- props: {
36
- menuData: {
37
- type: Array as PropType<MenuItem[]>,
38
- default: () => [],
39
- },
40
-
41
- isSubMenu: {
42
- type: Boolean,
43
- default: false,
44
- },
32
+ const props = withDefaults(
33
+ defineProps<{
34
+ menuData?: MenuItem[];
35
+ isSubMenu?: boolean;
36
+ }>(),
37
+ {
38
+ menuData: () => [],
39
+ isSubMenu: false,
45
40
  },
41
+ );
46
42
 
47
- emits: ['hide', 'show'],
48
-
49
- setup(props, { emit }) {
50
- const menu = ref<HTMLDivElement>();
51
- const subMenu = ref<any>();
52
- const visible = ref(false);
53
- const subMenuData = ref<MenuItem[]>([]);
54
- const menuStyle = ref({
55
- left: '0',
56
- top: '0',
57
- });
58
-
59
- const hide = () => {
60
- if (!visible.value) return;
61
-
62
- visible.value = false;
63
- subMenu.value?.hide();
43
+ const emit = defineEmits(['hide', 'show']);
64
44
 
65
- emit('hide');
66
- };
45
+ const menu = ref<HTMLDivElement>();
46
+ const subMenu = ref<any>();
47
+ const visible = ref(false);
48
+ const subMenuData = ref<MenuItem[]>([]);
49
+ const menuStyle = ref({
50
+ left: '0',
51
+ top: '0',
52
+ });
67
53
 
68
- const hideHandler = (e: MouseEvent) => {
69
- const target = e.target as HTMLElement | undefined;
70
- if (!visible.value || !target) {
71
- return;
72
- }
73
- if (menu.value?.contains(target) || subMenu.value?.$el?.contains(target)) {
74
- return;
54
+ const hide = () => {
55
+ if (!visible.value) return;
56
+
57
+ visible.value = false;
58
+ subMenu.value?.hide();
59
+
60
+ emit('hide');
61
+ };
62
+
63
+ const hideHandler = (e: MouseEvent) => {
64
+ const target = e.target as HTMLElement | undefined;
65
+ if (!visible.value || !target) {
66
+ return;
67
+ }
68
+ if (menu.value?.contains(target) || subMenu.value?.$el?.contains(target)) {
69
+ return;
70
+ }
71
+ hide();
72
+ };
73
+
74
+ const show = (e: MouseEvent) => {
75
+ // 加settimeout是以为,如果菜单中的按钮监听的是mouseup,那么菜单显示出来时鼠标如果正好在菜单上就会马上触发按钮的mouseup
76
+ setTimeout(() => {
77
+ visible.value = true;
78
+
79
+ nextTick(() => {
80
+ const menuHeight = menu.value?.clientHeight || 0;
81
+
82
+ let top = e.clientY;
83
+ if (menuHeight + e.clientY > document.body.clientHeight) {
84
+ top = document.body.clientHeight - menuHeight;
75
85
  }
76
- hide();
77
- };
78
86
 
79
- onMounted(() => {
80
- if (props.isSubMenu) return;
87
+ menuStyle.value = {
88
+ top: `${top}px`,
89
+ left: `${e.clientX}px`,
90
+ };
81
91
 
82
- globalThis.addEventListener('mousedown', hideHandler, true);
92
+ emit('show');
83
93
  });
94
+ }, 300);
95
+ };
96
+
97
+ const showSubMenu = (item: MenuItem) => {
98
+ const menuItem = item as MenuButton;
99
+ if (typeof item !== 'object' || !menuItem.items?.length) {
100
+ return;
101
+ }
102
+
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
+ }
110
+ };
84
111
 
85
- onUnmounted(() => {
86
- if (props.isSubMenu) return;
112
+ onMounted(() => {
113
+ if (props.isSubMenu) return;
87
114
 
88
- globalThis.removeEventListener('mousedown', hideHandler, true);
89
- });
115
+ globalThis.addEventListener('mousedown', hideHandler, true);
116
+ });
90
117
 
91
- return {
92
- menu,
93
- subMenu,
94
- visible,
95
- menuStyle,
96
- subMenuData,
97
-
98
- hide,
99
-
100
- show(e: MouseEvent) {
101
- // 加settimeout是以为,如果菜单中的按钮监听的是mouseup,那么菜单显示出来时鼠标如果正好在菜单上就会马上触发按钮的mouseup
102
- setTimeout(() => {
103
- visible.value = true;
104
-
105
- nextTick(() => {
106
- const menuHeight = menu.value?.clientHeight || 0;
107
-
108
- let top = e.clientY;
109
- if (menuHeight + e.clientY > document.body.clientHeight) {
110
- top = document.body.clientHeight - menuHeight;
111
- }
112
-
113
- menuStyle.value = {
114
- top: `${top}px`,
115
- left: `${e.clientX}px`,
116
- };
117
-
118
- emit('show');
119
- });
120
- }, 300);
121
- },
122
-
123
- showSubMenu(item: MenuItem) {
124
- const menuItem = item as MenuButton;
125
- if (typeof item !== 'object' || !menuItem.items?.length) {
126
- return;
127
- }
128
-
129
- subMenuData.value = menuItem.items;
130
- if (menu.value) {
131
- subMenu.value.show({
132
- clientX: menu.value.offsetLeft + menu.value.clientWidth,
133
- clientY: menu.value.offsetTop,
134
- });
135
- }
136
- },
137
- };
138
- },
118
+ onUnmounted(() => {
119
+ if (props.isSubMenu) return;
120
+
121
+ globalThis.removeEventListener('mousedown', hideHandler, true);
122
+ });
123
+
124
+ defineExpose({
125
+ hide,
126
+ show,
139
127
  });
140
128
  </script>
@@ -9,7 +9,7 @@
9
9
  <script lang="ts">
10
10
  import { computed, defineComponent, onMounted, onUnmounted, ref, watch } from 'vue';
11
11
 
12
- import { ScrollViewer } from '@editor/utils/scroll-viewer';
12
+ import { ScrollViewer } from '../utils/scroll-viewer';
13
13
 
14
14
  export default defineComponent({
15
15
  name: 'm-editor-scroll-viewer',
@@ -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';
53
+ <script lang="ts" setup>
54
+ import { computed, inject, markRaw, PropType } from 'vue';
55
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>