@tmagic/editor 1.1.0-beta.1 → 1.1.0-beta.12

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 (106) hide show
  1. package/dist/style.css +5 -1
  2. package/dist/{tmagic-editor.es.js → tmagic-editor.mjs} +1449 -1205
  3. package/dist/tmagic-editor.mjs.map +1 -0
  4. package/dist/tmagic-editor.umd.js +1463 -1219
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/package.json +23 -21
  7. package/src/Editor.vue +24 -15
  8. package/src/components/ContentMenu.vue +87 -99
  9. package/src/components/Icon.vue +1 -1
  10. package/src/components/ScrollViewer.vue +2 -2
  11. package/src/components/ToolButton.vue +150 -167
  12. package/src/fields/UISelect.vue +51 -72
  13. package/src/index.ts +2 -1
  14. package/src/layouts/AddPageBox.vue +2 -2
  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 +6 -17
  20. package/src/layouts/sidebar/LayerMenu.vue +2 -2
  21. package/src/layouts/sidebar/LayerPanel.vue +52 -12
  22. package/src/layouts/sidebar/Sidebar.vue +1 -1
  23. package/src/layouts/sidebar/TabPane.vue +2 -2
  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 +198 -219
  27. package/src/layouts/workspace/ViewerMenu.vue +140 -147
  28. package/src/layouts/workspace/Workspace.vue +14 -12
  29. package/src/services/BaseService.ts +5 -10
  30. package/src/services/componentList.ts +3 -3
  31. package/src/services/editor.ts +208 -147
  32. package/src/services/events.ts +1 -1
  33. package/src/services/history.ts +1 -1
  34. package/src/services/props.ts +74 -49
  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 +25 -7
  41. package/src/utils/config.ts +1 -1
  42. package/src/utils/editor.ts +20 -12
  43. package/src/utils/operator.ts +109 -0
  44. package/src/utils/props.ts +2 -27
  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 +17 -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 +1101 -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 +22 -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/types/services/props.d.ts +97 -0
  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 +18 -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 +6 -3
  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 -23
  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 -16
  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/services/props.d.ts +0 -42
  104. package/dist/types/src/shims-vue.d.ts +0 -6
  105. package/dist/types/src/vite-env.d.ts +0 -1
  106. package/src/vite-env.d.ts +0 -1
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "version": "1.1.0-beta.1",
2
+ "version": "1.1.0-beta.12",
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.1",
47
- "@tmagic/form": "1.1.0-beta.1",
48
- "@tmagic/schema": "1.1.0-beta.1",
49
- "@tmagic/stage": "1.1.0-beta.1",
50
- "@tmagic/utils": "1.1.0-beta.1",
48
+ "@tmagic/core": "1.1.0-beta.12",
49
+ "@tmagic/form": "1.1.0-beta.12",
50
+ "@tmagic/schema": "1.1.0-beta.12",
51
+ "@tmagic/stage": "1.1.0-beta.12",
52
+ "@tmagic/utils": "1.1.0-beta.12",
51
53
  "buffer": "^6.0.3",
52
54
  "color": "^3.1.3",
53
55
  "element-plus": "^2.2.6",
@@ -55,28 +57,28 @@
55
57
  "gesto": "^1.7.0",
56
58
  "keycon": "^1.1.2",
57
59
  "lodash-es": "^4.17.21",
58
- "monaco-editor": "^0.32.1",
60
+ "monaco-editor": "^0.34.0",
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.1",
65
+ "@tmagic/form": "1.1.0-beta.12",
64
66
  "element-plus": "^2.2.6",
65
- "monaco-editor": "^0.32.1",
66
- "vue": "^3.2.0"
67
+ "monaco-editor": "^0.34.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
@@ -21,6 +21,7 @@
21
21
  <template #workspace>
22
22
  <slot name="workspace" :editorService="editorService">
23
23
  <workspace>
24
+ <template #stage><slot name="stage"></slot></template>
24
25
  <template #workspace-content><slot name="workspace-content" :editorService="editorService"></slot></template>
25
26
  <template #page-bar-title="{ page }"><slot name="page-bar-title" :page="page"></slot></template>
26
27
  <template #page-bar-popover="{ page }"><slot name="page-bar-popover" :page="page"></slot></template>
@@ -30,7 +31,7 @@
30
31
 
31
32
  <template #props-panel>
32
33
  <slot name="props-panel">
33
- <props-panel ref="propsPanel" @mounted="(instance) => $emit('props-panel-mounted', instance)">
34
+ <props-panel ref="propsPanel" @mounted="(instance: any) => $emit('props-panel-mounted', instance)">
34
35
  <template #props-panel-header>
35
36
  <slot name="props-panel-header"></slot>
36
37
  </template>
@@ -49,20 +50,21 @@ import { EventOption } from '@tmagic/core';
49
50
  import type { FormConfig } from '@tmagic/form';
50
51
  import type { MApp, MNode } from '@tmagic/schema';
51
52
  import type StageCore from '@tmagic/stage';
52
- import { CONTAINER_HIGHLIGHT_CLASS, 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';
53
+ import { CONTAINER_HIGHLIGHT_CLASS, ContainerHighlightType, MoveableOptions } from '@tmagic/stage';
54
+
55
+ import Framework from './layouts/Framework.vue';
56
+ import NavMenu from './layouts/NavMenu.vue';
57
+ import PropsPanel from './layouts/PropsPanel.vue';
58
+ import Sidebar from './layouts/sidebar/Sidebar.vue';
59
+ import Workspace from './layouts/workspace/Workspace.vue';
60
+ import componentListService from './services/componentList';
61
+ import editorService from './services/editor';
62
+ import eventsService from './services/events';
63
+ import historyService from './services/history';
64
+ import propsService from './services/props';
65
+ import storageService from './services/storage';
66
+ import uiService from './services/ui';
67
+ import type { ComponentGroup, MenuBarData, MenuItem, Services, SideBarData, StageRect } from './type';
66
68
 
67
69
  export default defineComponent({
68
70
  name: 'm-editor',
@@ -169,6 +171,11 @@ export default defineComponent({
169
171
  default: 800,
170
172
  },
171
173
 
174
+ containerHighlightType: {
175
+ type: String as PropType<ContainerHighlightType>,
176
+ default: ContainerHighlightType.DEFAULT,
177
+ },
178
+
172
179
  stageRect: {
173
180
  type: [String, Object] as PropType<StageRect>,
174
181
  },
@@ -269,6 +276,7 @@ export default defineComponent({
269
276
  propsService,
270
277
  editorService,
271
278
  uiService,
279
+ storageService,
272
280
  };
273
281
 
274
282
  provide('services', services);
@@ -287,6 +295,7 @@ export default defineComponent({
287
295
  isContainer: props.isContainer,
288
296
  containerHighlightClassName: props.containerHighlightClassName,
289
297
  containerHighlightDuration: props.containerHighlightDuration,
298
+ containerHighlightType: props.containerHighlightType,
290
299
  }),
291
300
  );
292
301
 
@@ -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,6 +1,6 @@
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>
@@ -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
  `,