@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
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "version": "1.0.6",
2
+ "version": "1.1.0-beta.10",
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"
@@ -42,12 +44,12 @@
42
44
  ],
43
45
  "dependencies": {
44
46
  "@babel/core": "^7.18.0",
45
- "@element-plus/icons": "0.0.11",
46
- "@tmagic/core": "1.0.6",
47
- "@tmagic/form": "1.0.6",
48
- "@tmagic/schema": "1.0.6",
49
- "@tmagic/stage": "1.0.6",
50
- "@tmagic/utils": "1.0.6",
47
+ "@element-plus/icons-vue": "^2.0.6",
48
+ "@tmagic/core": "1.1.0-beta.10",
49
+ "@tmagic/form": "1.1.0-beta.10",
50
+ "@tmagic/schema": "1.1.0-beta.10",
51
+ "@tmagic/stage": "1.1.0-beta.10",
52
+ "@tmagic/utils": "1.1.0-beta.10",
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.0.6",
65
+ "@tmagic/form": "1.1.0-beta.10",
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
@@ -30,7 +30,7 @@
30
30
 
31
31
  <template #props-panel>
32
32
  <slot name="props-panel">
33
- <props-panel ref="propsPanel" @mounted="(instance) => $emit('props-panel-mounted', instance)">
33
+ <props-panel ref="propsPanel" @mounted="(instance: any) => $emit('props-panel-mounted', instance)">
34
34
  <template #props-panel-header>
35
35
  <slot name="props-panel-header"></slot>
36
36
  </template>
@@ -49,20 +49,21 @@ import { EventOption } from '@tmagic/core';
49
49
  import type { FormConfig } from '@tmagic/form';
50
50
  import type { MApp, MNode } from '@tmagic/schema';
51
51
  import type StageCore from '@tmagic/stage';
52
- import type { MoveableOptions } from '@tmagic/stage';
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';
52
+ import { CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
53
+
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',
@@ -154,6 +155,26 @@ export default defineComponent({
154
155
  default: (el: HTMLElement) => Boolean(el.id),
155
156
  },
156
157
 
158
+ isContainer: {
159
+ type: Function as PropType<(el: HTMLElement) => boolean | Promise<boolean>>,
160
+ default: (el: HTMLElement) => el.classList.contains('magic-ui-container'),
161
+ },
162
+
163
+ containerHighlightClassName: {
164
+ type: String,
165
+ default: CONTAINER_HIGHLIGHT_CLASS,
166
+ },
167
+
168
+ containerHighlightDuration: {
169
+ type: Number,
170
+ default: 800,
171
+ },
172
+
173
+ containerHighlightType: {
174
+ type: String as PropType<ContainerHighlightType>,
175
+ default: ContainerHighlightType.DEFAULT,
176
+ },
177
+
157
178
  stageRect: {
158
179
  type: [String, Object] as PropType<StageRect>,
159
180
  },
@@ -254,6 +275,7 @@ export default defineComponent({
254
275
  propsService,
255
276
  editorService,
256
277
  uiService,
278
+ storageService,
257
279
  };
258
280
 
259
281
  provide('services', services);
@@ -269,6 +291,10 @@ export default defineComponent({
269
291
  moveableOptions: props.moveableOptions,
270
292
  canSelect: props.canSelect,
271
293
  updateDragEl: props.updateDragEl,
294
+ isContainer: props.isContainer,
295
+ containerHighlightClassName: props.containerHighlightClassName,
296
+ containerHighlightDuration: props.containerHighlightDuration,
297
+ containerHighlightType: props.containerHighlightType,
272
298
  }),
273
299
  );
274
300
 
@@ -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>
@@ -1,13 +1,13 @@
1
1
  <template>
2
2
  <el-icon v-if="!icon"><edit></edit></el-icon>
3
- <img v-else-if="typeof icon === 'string' && icon.startsWith('http')" :src="icon" />
3
+ <el-icon v-else-if="typeof icon === 'string' && icon.startsWith('http')"><img :src="icon" /></el-icon>
4
4
  <i v-else-if="typeof icon === 'string'" :class="icon"></i>
5
5
  <el-icon v-else><component :is="toRaw(icon)"></component></el-icon>
6
6
  </template>
7
7
 
8
8
  <script lang="ts">
9
9
  import { Component, defineComponent, PropType, toRaw } from 'vue';
10
- import { Edit } from '@element-plus/icons';
10
+ import { Edit } from '@element-plus/icons-vue';
11
11
 
12
12
  export default defineComponent({
13
13
  name: 'm-icon',
@@ -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',
@@ -55,7 +55,7 @@ export default defineComponent({
55
55
  style: computed(
56
56
  () => `
57
57
  width: ${props.width}px;
58
- height: ${(props.height || 0) - 40}px;
58
+ height: ${props.height}px;
59
59
  position: absolute;
60
60
  margin-top: 30px;
61
61
  `,