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

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.
@@ -29,7 +29,7 @@ declare class Props extends BaseService {
29
29
  * @param type 组件类型
30
30
  * @returns 组件初始值
31
31
  */
32
- getPropsValue(type: string, defaultValue?: Record<string, any>): Promise<any>;
32
+ getPropsValue(type: string, { inputEvent, ...defaultValue }?: Record<string, any>): Promise<any>;
33
33
  createId(type: string | number): Promise<string>;
34
34
  /**
35
35
  * 将组件与组件的子元素配置中的id都设置成一个新的ID
@@ -92,6 +92,7 @@ export interface EditorNodeInfo {
92
92
  export interface AddMNode {
93
93
  type: string;
94
94
  name?: string;
95
+ inputEvent?: DragEvent;
95
96
  [key: string]: any;
96
97
  }
97
98
  /**
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.0-beta.3",
2
+ "version": "1.1.0-beta.4",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -43,11 +43,11 @@
43
43
  "dependencies": {
44
44
  "@babel/core": "^7.18.0",
45
45
  "@element-plus/icons-vue": "^2.0.6",
46
- "@tmagic/core": "1.1.0-beta.3",
47
- "@tmagic/form": "1.1.0-beta.3",
48
- "@tmagic/schema": "1.1.0-beta.3",
49
- "@tmagic/stage": "1.1.0-beta.3",
50
- "@tmagic/utils": "1.1.0-beta.3",
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",
51
51
  "buffer": "^6.0.3",
52
52
  "color": "^3.1.3",
53
53
  "element-plus": "^2.2.6",
@@ -60,7 +60,7 @@
60
60
  "vue": "^3.2.0"
61
61
  },
62
62
  "peerDependencies": {
63
- "@tmagic/form": "1.1.0-beta.3",
63
+ "@tmagic/form": "1.1.0-beta.4",
64
64
  "element-plus": "^2.2.6",
65
65
  "monaco-editor": "^0.32.1",
66
66
  "vue": "^3.2.0"
@@ -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
  `,
@@ -264,6 +264,8 @@ export default defineComponent({
264
264
  left,
265
265
  };
266
266
 
267
+ config.inputEvent = e;
268
+
267
269
  services?.editorService.add(config, parent);
268
270
  }
269
271
  },
@@ -271,7 +271,8 @@ class Editor extends BaseService {
271
271
  * @returns 添加后的节点
272
272
  */
273
273
  public async add(addNode: AddMNode, parent?: MContainer | null): Promise<MNode> {
274
- const { type, ...config } = addNode;
274
+ // 加入inputEvent是为给业务扩展时可以获取到更多的信息,只有在使用拖拽添加组件时才有改对象
275
+ const { type, inputEvent, ...config } = addNode;
275
276
  const curNode = this.get<MContainer>('node');
276
277
 
277
278
  let parentNode: MContainer | undefined;
@@ -539,8 +540,8 @@ class Editor extends BaseService {
539
540
  const doc = stage?.renderer.contentWindow?.document;
540
541
 
541
542
  if (doc) {
542
- const parentEl = doc.getElementById(`${parent.id}`);
543
543
  const el = doc.getElementById(`${node.id}`);
544
+ const parentEl = el?.offsetParent;
544
545
  if (parentEl && el) {
545
546
  node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
546
547
  }
@@ -88,7 +88,7 @@ class Props extends BaseService {
88
88
  * @param type 组件类型
89
89
  * @returns 组件初始值
90
90
  */
91
- public async getPropsValue(type: string, defaultValue: Record<string, any> = {}) {
91
+ public async getPropsValue(type: string, { inputEvent, ...defaultValue }: Record<string, any> = {}) {
92
92
  if (type === 'area') {
93
93
  const value = (await this.getPropsValue('button')) as MComponent;
94
94
  value.className = 'action-area';
@@ -155,10 +155,16 @@ class Ui extends BaseService {
155
155
  const { stageRect, stageContainerRect } = state;
156
156
  const { height, width } = stageContainerRect;
157
157
  if (!width || !height) return 1;
158
- if (width > stageRect.width && height > stageRect.height) {
158
+
159
+ // 30为标尺的大小
160
+ const stageWidth = stageRect.width + 30;
161
+ const stageHeight = stageRect.height + 30;
162
+
163
+ if (width > stageWidth && height > stageHeight) {
159
164
  return 1;
160
165
  }
161
- return Math.min((width - 100) / stageRect.width || 1, (height - 100) / stageRect.height || 1);
166
+ // 60/80是为了不要让画布太过去贴住四周(这样好看些)
167
+ return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
162
168
  }
163
169
  }
164
170
 
@@ -35,7 +35,7 @@
35
35
  justify-content: center;
36
36
  align-items: center;
37
37
  flex-direction: column;
38
- height: calc(100% - $--page-bar-height);
38
+ height: calc(100% - #{$--page-bar-height});
39
39
  }
40
40
 
41
41
  &-content {
@@ -1,7 +1,7 @@
1
1
  .m-editor-stage {
2
2
  position: relative;
3
3
  width: 100%;
4
- height: calc(100% - $--page-bar-height);
4
+ height: calc(100% - #{$--page-bar-height});
5
5
  overflow: hidden;
6
6
  display: flex;
7
7
  justify-content: center;
@@ -13,9 +13,9 @@
13
13
  height: 100%;
14
14
  z-index: 0;
15
15
  position: relative;
16
- border: 1px solid $--border-color;
17
16
  transition: transform 0.3s;
18
17
  box-sizing: content-box;
18
+ box-shadow: rgba(0, 0, 0, 0.04) 0px 3px 5px;
19
19
 
20
20
  &::-webkit-scrollbar {
21
21
  width: 0 !important;
package/src/type.ts CHANGED
@@ -125,6 +125,7 @@ export interface EditorNodeInfo {
125
125
  export interface AddMNode {
126
126
  type: string;
127
127
  name?: string;
128
+ inputEvent?: DragEvent;
128
129
  [key: string]: any;
129
130
  }
130
131