@tmagic/editor 1.2.0-beta.13 → 1.2.0-beta.14

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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.0-beta.13",
2
+ "version": "1.2.0-beta.14",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -45,12 +45,12 @@
45
45
  "dependencies": {
46
46
  "@babel/core": "^7.18.0",
47
47
  "@element-plus/icons-vue": "^2.0.9",
48
- "@tmagic/core": "1.2.0-beta.13",
49
- "@tmagic/design": "1.2.0-beta.13",
50
- "@tmagic/form": "1.2.0-beta.13",
51
- "@tmagic/schema": "1.2.0-beta.13",
52
- "@tmagic/stage": "1.2.0-beta.13",
53
- "@tmagic/utils": "1.2.0-beta.13",
48
+ "@tmagic/core": "1.2.0-beta.14",
49
+ "@tmagic/design": "1.2.0-beta.14",
50
+ "@tmagic/form": "1.2.0-beta.14",
51
+ "@tmagic/schema": "1.2.0-beta.14",
52
+ "@tmagic/stage": "1.2.0-beta.14",
53
+ "@tmagic/utils": "1.2.0-beta.14",
54
54
  "buffer": "^6.0.3",
55
55
  "color": "^3.1.3",
56
56
  "events": "^3.3.0",
@@ -62,8 +62,8 @@
62
62
  "vue": "^3.2.37"
63
63
  },
64
64
  "peerDependencies": {
65
- "@tmagic/design": "1.2.0-beta.13",
66
- "@tmagic/form": "1.2.0-beta.13",
65
+ "@tmagic/design": "1.2.0-beta.14",
66
+ "@tmagic/form": "1.2.0-beta.14",
67
67
  "monaco-editor": "^0.34.0",
68
68
  "vue": "^3.2.37"
69
69
  },
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <div class="m-editor-wrapper">
2
+ <div class="m-editor-wrapper" :class="isFullScreen ? 'fullScreen' : 'normal'">
3
3
  <magic-code-editor
4
4
  ref="codeEditor"
5
5
  class="m-editor-container"
@@ -9,10 +9,16 @@
9
9
  :options="codeOptions"
10
10
  ></magic-code-editor>
11
11
  <div class="m-editor-content-bottom" v-if="editable">
12
+ <TMagicButton type="primary" class="button" @click="toggleFullScreen">
13
+ {{ isFullScreen ? '退出全屏' : '全屏' }}</TMagicButton
14
+ >
12
15
  <TMagicButton type="primary" class="button" @click="saveCode">保存</TMagicButton>
13
16
  <TMagicButton type="primary" class="button" @click="close">关闭</TMagicButton>
14
17
  </div>
15
18
  <div class="m-editor-content-bottom" v-else>
19
+ <TMagicButton type="primary" class="button" @click="toggleFullScreen">
20
+ {{ isFullScreen ? '退出全屏' : '全屏' }}</TMagicButton
21
+ >
16
22
  <TMagicButton type="primary" class="button" @click="close">关闭</TMagicButton>
17
23
  </div>
18
24
  </div>
@@ -57,6 +63,7 @@ const editorContent = ref<string>('');
57
63
  const codeEditor = ref<InstanceType<typeof MagicCodeEditor>>();
58
64
  // 原始代码内容
59
65
  const originCodeContent = ref<string>('');
66
+ const isFullScreen = ref<boolean>(false);
60
67
 
61
68
  const codeOptions = computed(() => ({
62
69
  ...props.codeOptions,
@@ -105,7 +112,7 @@ const saveAndClose = (): void => {
105
112
  };
106
113
 
107
114
  // 关闭弹窗
108
- const close = async () => {
115
+ const close = async (): Promise<void> => {
109
116
  const codeDraft = services?.codeBlockService.getCodeDraft(props.id);
110
117
  if (codeDraft) {
111
118
  tMagicMessageBox
@@ -127,4 +134,12 @@ const close = async () => {
127
134
  emit('close');
128
135
  }
129
136
  };
137
+
138
+ // 切换全屏
139
+ const toggleFullScreen = (): void => {
140
+ isFullScreen.value = !isFullScreen.value;
141
+ if (codeEditor.value) {
142
+ codeEditor.value.focus();
143
+ }
144
+ };
130
145
  </script>
@@ -46,6 +46,7 @@ const tableConfig = {
46
46
  border: true,
47
47
  enableFullscreen: false,
48
48
  name: 'params',
49
+ maxHeight: '150px',
49
50
  items: [
50
51
  {
51
52
  type: 'text',
@@ -89,7 +90,7 @@ watchEffect(() => {
89
90
  codeContent.value = props.content;
90
91
  });
91
92
 
92
- const initTableModel = () => {
93
+ const initTableModel = (): void => {
93
94
  const codeDsl = services?.codeBlockService.getCodeDslSync();
94
95
  if (!codeDsl) return;
95
96
  tableModel.value = {
@@ -130,7 +131,7 @@ const saveCode = async (codeValue: string): Promise<void> => {
130
131
  };
131
132
 
132
133
  // 保存并关闭
133
- const saveAndClose = async (codeValue: string) => {
134
+ const saveAndClose = async (codeValue: string): Promise<void> => {
134
135
  await saveCode(codeValue);
135
136
  if (evalRes.value) {
136
137
  close();
@@ -138,7 +139,7 @@ const saveAndClose = async (codeValue: string) => {
138
139
  };
139
140
 
140
141
  // 关闭弹窗
141
- const close = () => {
142
+ const close = (): void => {
142
143
  services?.codeBlockService.setCodeEditorShowStatus(false);
143
144
  };
144
145
  </script>
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <div ref="el" class="m-editor-layout">
3
- <template v-if="typeof props.left !== 'undefined'">
3
+ <template v-if="hasLeft">
4
4
  <div class="m-editor-layout-left" :class="leftClass" :style="`width: ${left}px`">
5
5
  <slot name="left"></slot>
6
6
  </div>
@@ -11,7 +11,7 @@
11
11
  <slot name="center"></slot>
12
12
  </div>
13
13
 
14
- <template v-if="typeof props.right !== 'undefined'">
14
+ <template v-if="hasRight">
15
15
  <Resizer @change="changeRight"></Resizer>
16
16
  <div class="m-editor-layout-right" :class="rightClass" :style="`width: ${right}px`">
17
17
  <slot name="right"></slot>
@@ -21,7 +21,7 @@
21
21
  </template>
22
22
 
23
23
  <script lang="ts" setup name="MEditorLayout">
24
- import { onMounted, onUnmounted, ref } from 'vue';
24
+ import { computed, onMounted, onUnmounted, ref } from 'vue';
25
25
 
26
26
  import Resizer from '../layouts/Resizer.vue';
27
27
 
@@ -33,29 +33,64 @@ const props = withDefaults(
33
33
  right?: number;
34
34
  minLeft?: number;
35
35
  minRight?: number;
36
+ minCenter?: number;
36
37
  leftClass?: string;
37
38
  rightClass?: string;
38
39
  centerClass?: string;
39
40
  }>(),
40
41
  {
41
- minLeft: 1,
42
+ minLeft: 46,
42
43
  minRight: 1,
44
+ minCenter: 1,
43
45
  },
44
46
  );
45
47
 
46
48
  const el = ref<HTMLElement>();
47
49
 
50
+ const hasLeft = computed(() => typeof props.left !== 'undefined');
51
+ const hasRight = computed(() => typeof props.left !== 'undefined');
52
+
53
+ const getCenterWidth = (clientWidth: number, left: number, right: number) => {
54
+ let center = clientWidth - left - right;
55
+ if (center < props.minCenter) {
56
+ center = props.minCenter;
57
+ if (left < right) {
58
+ right = clientWidth - left - props.minCenter;
59
+ } else {
60
+ left = clientWidth - right - props.minCenter;
61
+ }
62
+ }
63
+ return {
64
+ center,
65
+ left,
66
+ right,
67
+ };
68
+ };
69
+
48
70
  let clientWidth = 0;
49
71
  const resizerObserver = new ResizeObserver((entries) => {
50
72
  for (const { contentRect } of entries) {
51
73
  clientWidth = contentRect.width;
52
74
 
53
- center.value = clientWidth - (props.left || 0) - (props.right || 0);
75
+ let left = props.left || 0;
76
+ let right = props.right || 0;
77
+
78
+ if (left > clientWidth) {
79
+ left = clientWidth / 3;
80
+ }
81
+
82
+ if (right > clientWidth) {
83
+ right = clientWidth / 3;
84
+ }
85
+
86
+ const columnWidth = getCenterWidth(clientWidth, left, right);
87
+
88
+ center.value = columnWidth.center;
54
89
 
55
90
  emit('change', {
56
- left: props.left,
91
+ left: columnWidth.left,
57
92
  center: center.value,
58
- right: props.right,
93
+ right: columnWidth.right,
59
94
  });
60
95
  }
61
96
  });
@@ -81,12 +116,14 @@ const changeLeft = (deltaX: number) => {
81
116
  left = props.left;
82
117
  }
83
118
 
84
- center.value = clientWidth - left - (props.right || 0);
119
+ const columnWidth = getCenterWidth(clientWidth, left, props.right || 0);
120
+
121
+ center.value = columnWidth.center;
85
122
 
86
123
  emit('change', {
87
- left,
124
+ left: columnWidth.left,
88
125
  center: center.value,
89
- right: props.right,
126
+ right: columnWidth.right,
90
127
  });
91
128
  };
92
129
 
@@ -99,12 +136,14 @@ const changeRight = (deltaX: number) => {
99
136
  right = props.right;
100
137
  }
101
138
 
102
- center.value = clientWidth - (props.left || 0) - right;
139
+ const columnWidth = getCenterWidth(clientWidth, props.left || 0, right);
140
+
141
+ center.value = columnWidth.center;
103
142
 
104
143
  emit('change', {
105
- left: props.left,
144
+ left: columnWidth.left,
106
145
  center: center.value,
107
- right,
146
+ right: columnWidth.right,
108
147
  });
109
148
  };
110
149
  </script>
@@ -4,7 +4,7 @@
4
4
 
5
5
  <script lang="ts" setup name="MEditorLayerMenu">
6
6
  import { computed, inject, markRaw, ref } from 'vue';
7
- import { Delete, DocumentCopy, Files, Plus } from '@element-plus/icons-vue';
7
+ import { CopyDocument, Delete, Files, Plus } from '@element-plus/icons-vue';
8
8
 
9
9
  import { NodeType } from '@tmagic/schema';
10
10
 
@@ -84,7 +84,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
84
84
  {
85
85
  type: 'button',
86
86
  text: '复制',
87
- icon: markRaw(DocumentCopy),
87
+ icon: markRaw(CopyDocument),
88
88
  display: () => !isRoot.value,
89
89
  handler: () => {
90
90
  node.value && services?.editorService.copy(node.value);
@@ -4,7 +4,7 @@
4
4
 
5
5
  <script lang="ts" setup name="MEditorViewerMenu">
6
6
  import { computed, inject, markRaw, ref, watch } from 'vue';
7
- import { Bottom, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
7
+ import { Bottom, CopyDocument, Delete, DocumentCopy, Top } from '@element-plus/icons-vue';
8
8
 
9
9
  import { MNode, NodeType } from '@tmagic/schema';
10
10
  import StageCore from '@tmagic/stage';
@@ -44,7 +44,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
44
44
  {
45
45
  type: 'button',
46
46
  text: '复制',
47
- icon: markRaw(DocumentCopy),
47
+ icon: markRaw(CopyDocument),
48
48
  handler: () => {
49
49
  nodes.value && editorService?.copy(nodes.value);
50
50
  canPaste.value = true;
@@ -53,6 +53,7 @@ const menuData = computed<(MenuButton | MenuComponent)[]>(() => [
53
53
  {
54
54
  type: 'button',
55
55
  text: '粘贴',
56
+ icon: markRaw(DocumentCopy),
56
57
  display: () => canPaste.value,
57
58
  handler: () => {
58
59
  const rect = menu.value?.$el.getBoundingClientRect();
@@ -77,7 +77,7 @@ const doAction = async (
77
77
  *
78
78
  * editorService.usePlugin({
79
79
  * beforeAdd(value) { return [value] },
80
- * afterAdd(value, result) {},
80
+ * afterAdd(result, value) { return result },
81
81
  * });
82
82
  *
83
83
  * editorService.add(); 最终会变成 () => {
@@ -173,7 +173,7 @@ class CodeBlock extends BaseService {
173
173
  * 获取当前选中的代码块内容
174
174
  * @returns {CodeBlockContent | null}
175
175
  */
176
- public async getCurrentDsl() {
176
+ public async getCurrentDsl(): Promise<CodeBlockContent | null> {
177
177
  return await this.getCodeContentById(this.state.id);
178
178
  }
179
179
 
@@ -199,7 +199,7 @@ class CodeBlock extends BaseService {
199
199
  * @param {Id} id 代码块id
200
200
  * @returns {void}
201
201
  */
202
- public setId(id: Id) {
202
+ public setId(id: Id): void {
203
203
  if (!id) return;
204
204
  this.state.id = id;
205
205
  }
@@ -248,7 +248,7 @@ class CodeBlock extends BaseService {
248
248
 
249
249
  /**
250
250
  * 刷新绑定关系
251
- * @returns {void}
251
+ * @returns {CodeRelation | null}
252
252
  */
253
253
  public refreshCombineInfo(): CodeRelation | null {
254
254
  const root = editorService.get<MApp | null>('root');
@@ -335,14 +335,14 @@ class CodeBlock extends BaseService {
335
335
  * @param {MNode} compId 组件节点
336
336
  * @returns void
337
337
  */
338
- public async deleteCompsInRelation(node: MNode) {
338
+ public async deleteCompsInRelation(node: MNode): Promise<void> {
339
339
  const codeDsl = cloneDeep(await this.getCodeDsl());
340
340
  if (!codeDsl) return;
341
341
  this.refreshRelationDeep(node, codeDsl);
342
342
  this.setCodeDsl(codeDsl);
343
343
  }
344
344
 
345
- public destroy() {
345
+ public destroy(): void {
346
346
  this.state.isShowCodeEditor = false;
347
347
  this.state.codeDsl = null;
348
348
  this.state.id = '';
@@ -358,7 +358,7 @@ class CodeBlock extends BaseService {
358
358
  * @param {CodeBlockDSL} codeDsl 代码块
359
359
  * @returns void
360
360
  */
361
- private refreshRelationDeep(node: MNode, codeDsl: CodeBlockDSL) {
361
+ private refreshRelationDeep(node: MNode, codeDsl: CodeBlockDSL): void {
362
362
  if (!node.id) return;
363
363
  forIn(codeDsl, (codeBlockContent) => {
364
364
  const compsContent = codeBlockContent.comps || {};
@@ -376,7 +376,7 @@ class CodeBlock extends BaseService {
376
376
  * @param {MContainer} node 节点信息
377
377
  * @returns void
378
378
  */
379
- private recurseMNode(node: MNode, relations: CodeRelation) {
379
+ private recurseMNode(node: MNode, relations: CodeRelation): void {
380
380
  forIn(node, (value, key) => {
381
381
  if (value?.hookType === HookType.CODE && !isEmpty(value.hookData)) {
382
382
  value.hookData.forEach((relationItem: HookData) => {
@@ -78,6 +78,11 @@
78
78
  .m-fields-code-select {
79
79
  width: 100%;
80
80
  }
81
+
82
+ .el-dialog.is-fullscreen.code-editor-dialog {
83
+ overflow: hidden;
84
+ }
85
+
81
86
  .code-editor-dialog {
82
87
  .el-dialog__body {
83
88
  height: 90%;
@@ -149,7 +154,7 @@
149
154
  position: absolute;
150
155
  top: 0;
151
156
  left: 4px;
152
- width: 100%;
157
+ width: calc(100% - 9px);
153
158
  height: 100%;
154
159
  z-index: 10;
155
160
  background: #fff;
@@ -160,8 +165,16 @@
160
165
 
161
166
  .m-editor-wrapper {
162
167
  height: 100%;
168
+ &.fullScreen {
169
+ height: 100%;
170
+ width: 100%;
171
+ position: fixed;
172
+ top: 0;
173
+ left: 0;
174
+ z-index: 100;
175
+ }
163
176
  .m-editor-container {
164
- height: calc(100% - 65px);
177
+ height: calc(100% - 45px);
165
178
  }
166
179
  .m-editor-content-bottom {
167
180
  height: 45px;
@@ -174,7 +187,7 @@
174
187
  bottom: 0;
175
188
  > button {
176
189
  height: 30px;
177
- margin-top: 15px;
190
+ margin-top: 5px;
178
191
  }
179
192
  }
180
193
  }
@@ -5,22 +5,25 @@ declare const _default: {
5
5
  $props: Partial<{
6
6
  minLeft: number;
7
7
  minRight: number;
8
+ minCenter: number;
8
9
  }> & Omit<Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
9
10
  left?: number | undefined;
10
11
  right?: number | undefined;
11
12
  minLeft?: number | undefined;
12
13
  minRight?: number | undefined;
14
+ minCenter?: number | undefined;
13
15
  leftClass?: string | undefined;
14
16
  rightClass?: string | undefined;
15
17
  centerClass?: string | undefined;
16
18
  }>, {
17
19
  minLeft: number;
18
20
  minRight: number;
21
+ minCenter: number;
19
22
  }>>> & {
20
23
  onChange?: ((...args: any[]) => any) | undefined;
21
24
  "onUpdate:left"?: ((...args: any[]) => any) | undefined;
22
25
  "onUpdate:right"?: ((...args: any[]) => any) | undefined;
23
- } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "minLeft" | "minRight">;
26
+ } & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, "minLeft" | "minRight" | "minCenter">;
24
27
  $attrs: {
25
28
  [x: string]: unknown;
26
29
  };
@@ -39,12 +42,14 @@ declare const _default: {
39
42
  right?: number | undefined;
40
43
  minLeft?: number | undefined;
41
44
  minRight?: number | undefined;
45
+ minCenter?: number | undefined;
42
46
  leftClass?: string | undefined;
43
47
  rightClass?: string | undefined;
44
48
  centerClass?: string | undefined;
45
49
  }>, {
46
50
  minLeft: number;
47
51
  minRight: number;
52
+ minCenter: number;
48
53
  }>>> & {
49
54
  onChange?: ((...args: any[]) => any) | undefined;
50
55
  "onUpdate:left"?: ((...args: any[]) => any) | undefined;
@@ -52,6 +57,7 @@ declare const _default: {
52
57
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "update:left" | "update:right")[], string, {
53
58
  minLeft: number;
54
59
  minRight: number;
60
+ minCenter: number;
55
61
  }> & {
56
62
  beforeCreate?: ((() => void) | (() => void)[]) | undefined;
57
63
  created?: ((() => void) | (() => void)[]) | undefined;
@@ -77,12 +83,14 @@ declare const _default: {
77
83
  right?: number | undefined;
78
84
  minLeft?: number | undefined;
79
85
  minRight?: number | undefined;
86
+ minCenter?: number | undefined;
80
87
  leftClass?: string | undefined;
81
88
  rightClass?: string | undefined;
82
89
  centerClass?: string | undefined;
83
90
  }>, {
84
91
  minLeft: number;
85
92
  minRight: number;
93
+ minCenter: number;
86
94
  }>>> & {
87
95
  onChange?: ((...args: any[]) => any) | undefined;
88
96
  "onUpdate:left"?: ((...args: any[]) => any) | undefined;
@@ -96,12 +104,14 @@ declare const _default: {
96
104
  right?: number | undefined;
97
105
  minLeft?: number | undefined;
98
106
  minRight?: number | undefined;
107
+ minCenter?: number | undefined;
99
108
  leftClass?: string | undefined;
100
109
  rightClass?: string | undefined;
101
110
  centerClass?: string | undefined;
102
111
  }>, {
103
112
  minLeft: number;
104
113
  minRight: number;
114
+ minCenter: number;
105
115
  }>>> & {
106
116
  onChange?: ((...args: any[]) => any) | undefined;
107
117
  "onUpdate:left"?: ((...args: any[]) => any) | undefined;
@@ -109,6 +119,7 @@ declare const _default: {
109
119
  }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("change" | "update:left" | "update:right")[], "change" | "update:left" | "update:right", {
110
120
  minLeft: number;
111
121
  minRight: number;
122
+ minCenter: number;
112
123
  }> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
113
124
  $slots: {
114
125
  left: (_: {}) => any;
@@ -18,7 +18,7 @@ import { EventEmitter } from 'events';
18
18
  *
19
19
  * editorService.usePlugin({
20
20
  * beforeAdd(value) { return [value] },
21
- * afterAdd(value, result) {},
21
+ * afterAdd(result, value) { return result },
22
22
  * });
23
23
  *
24
24
  * editorService.add(); 最终会变成 () => {
@@ -107,7 +107,7 @@ declare class CodeBlock extends BaseService {
107
107
  getCombineIds(): string[];
108
108
  /**
109
109
  * 刷新绑定关系
110
- * @returns {void}
110
+ * @returns {CodeRelation | null}
111
111
  */
112
112
  refreshCombineInfo(): CodeRelation | null;
113
113
  /**