@tmagic/editor 1.4.0-beta.1 → 1.4.0-beta.2

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 (34) hide show
  1. package/dist/style.css +14 -6
  2. package/dist/tmagic-editor.js +259 -167
  3. package/dist/tmagic-editor.umd.cjs +258 -164
  4. package/package.json +11 -11
  5. package/src/components/CodeBlockEditor.vue +43 -46
  6. package/src/components/FloatingBox.vue +38 -33
  7. package/src/components/SplitView.vue +46 -35
  8. package/src/hooks/index.ts +2 -0
  9. package/src/hooks/use-code-block-edit.ts +1 -1
  10. package/src/hooks/use-editor-content-height.ts +20 -0
  11. package/src/hooks/use-float-box.ts +8 -8
  12. package/src/hooks/use-window-rect.ts +20 -0
  13. package/src/layouts/Framework.vue +33 -34
  14. package/src/layouts/PropsPanel.vue +35 -0
  15. package/src/layouts/sidebar/Sidebar.vue +13 -8
  16. package/src/layouts/workspace/viewer/NodeListMenu.vue +1 -0
  17. package/src/services/stageOverlay.ts +2 -2
  18. package/src/services/ui.ts +6 -0
  19. package/src/theme/code-block.scss +0 -5
  20. package/src/theme/floating-box.scss +2 -2
  21. package/src/theme/props-panel.scss +14 -0
  22. package/src/type.ts +6 -0
  23. package/types/components/CodeBlockEditor.vue.d.ts +45 -24
  24. package/types/components/FloatingBox.vue.d.ts +42 -57
  25. package/types/components/SplitView.vue.d.ts +2 -0
  26. package/types/hooks/index.d.ts +2 -0
  27. package/types/hooks/use-code-block-edit.d.ts +16 -2
  28. package/types/hooks/use-data-source-method.d.ts +16 -2
  29. package/types/hooks/use-editor-content-height.d.ts +3 -0
  30. package/types/hooks/use-window-rect.d.ts +6 -0
  31. package/types/layouts/sidebar/Sidebar.vue.d.ts +1 -1
  32. package/types/services/stageOverlay.d.ts +1 -1
  33. package/types/services/ui.d.ts +6 -0
  34. package/types/type.d.ts +6 -0
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.4.0-beta.1",
2
+ "version": "1.4.0-beta.2",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -42,14 +42,14 @@
42
42
  "dependencies": {
43
43
  "@babel/core": "^7.18.0",
44
44
  "@element-plus/icons-vue": "^2.3.1",
45
- "@tmagic/core": "1.4.0-beta.1",
46
- "@tmagic/dep": "1.4.0-beta.1",
47
- "@tmagic/design": "1.4.0-beta.1",
48
- "@tmagic/form": "1.4.0-beta.1",
49
- "@tmagic/schema": "1.4.0-beta.1",
50
- "@tmagic/stage": "1.4.0-beta.1",
51
- "@tmagic/table": "1.4.0-beta.1",
52
- "@tmagic/utils": "1.4.0-beta.1",
45
+ "@tmagic/core": "1.4.0-beta.2",
46
+ "@tmagic/dep": "1.4.0-beta.2",
47
+ "@tmagic/design": "1.4.0-beta.2",
48
+ "@tmagic/form": "1.4.0-beta.2",
49
+ "@tmagic/schema": "1.4.0-beta.2",
50
+ "@tmagic/stage": "1.4.0-beta.2",
51
+ "@tmagic/table": "1.4.0-beta.2",
52
+ "@tmagic/utils": "1.4.0-beta.2",
53
53
  "buffer": "^6.0.3",
54
54
  "color": "^3.1.3",
55
55
  "emmet-monaco-es": "^5.3.0",
@@ -63,8 +63,8 @@
63
63
  "vue": "^3.4.21"
64
64
  },
65
65
  "peerDependencies": {
66
- "@tmagic/design": "1.4.0-beta.1",
67
- "@tmagic/form": "1.4.0-beta.1",
66
+ "@tmagic/design": "1.4.0-beta.2",
67
+ "@tmagic/form": "1.4.0-beta.2",
68
68
  "monaco-editor": "^0.47.0",
69
69
  "vue": "^3.4.21"
70
70
  },
@@ -1,30 +1,36 @@
1
1
  <template>
2
2
  <!-- 代码块编辑区 -->
3
- <FloatingBox v-model:visible="boxVisible" title="代码编辑" :position="boxPosition" :before-close="beforeClose">
3
+ <FloatingBox
4
+ v-model:visible="boxVisible"
5
+ v-model:width="width"
6
+ v-model:height="codeBlockEditorHeight"
7
+ :title="content.name ? `${disabled ? '查看' : '编辑'}${content.name}` : '新增代码'"
8
+ :position="boxPosition"
9
+ :before-close="beforeClose"
10
+ >
4
11
  <template #body>
5
- <div ref="floatingBoxBody"></div>
12
+ <div ref="floatingBoxBody" style="height: 100%"></div>
6
13
  </template>
7
14
  </FloatingBox>
8
15
 
9
16
  <Teleport :to="floatingBoxBody" :disabled="slideType === 'box'" v-if="editVisible">
10
17
  <MFormBox
11
18
  class="m-editor-code-block-editor"
12
- ref="fomDrawer"
19
+ ref="formBox"
13
20
  label-width="80px"
14
21
  :close-on-press-escape="false"
15
22
  :title="content.name"
16
- :width="size"
17
23
  :config="functionConfig"
18
24
  :values="content"
19
25
  :disabled="disabled"
26
+ :height="floatingBoxBody?.clientHeight"
20
27
  @change="changeHandler"
21
28
  @submit="submitForm"
22
29
  @error="errorHandler"
23
- @open="openHandler"
24
30
  @closed="closedHandler"
25
31
  >
26
32
  <template #left>
27
- <TMagicButton type="primary" link @click="difVisible = true">查看修改</TMagicButton>
33
+ <TMagicButton v-if="!disabled" type="primary" link @click="difVisible = true">查看修改</TMagicButton>
28
34
  </template>
29
35
  </MFormBox>
30
36
  </Teleport>
@@ -41,8 +47,8 @@
41
47
  type="diff"
42
48
  language="json"
43
49
  :initValues="content.content"
44
- :modifiedValues="fomDrawer?.form?.values.content"
45
- :style="`height: ${height - 200}px`"
50
+ :modifiedValues="formBox?.form?.values.content"
51
+ :style="`height: ${windowRect.height - 150}px`"
46
52
  ></CodeEditor>
47
53
 
48
54
  <template #footer>
@@ -55,13 +61,15 @@
55
61
  </template>
56
62
 
57
63
  <script lang="ts" setup>
58
- import { computed, inject, nextTick, onBeforeUnmount, ref } from 'vue';
64
+ import { computed, inject, nextTick, ref } from 'vue';
59
65
 
60
66
  import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
61
- import { ColumnConfig, FormConfig, FormState, MFormBox, MFormDrawer } from '@tmagic/form';
67
+ import { ColumnConfig, FormConfig, FormState, MFormBox } from '@tmagic/form';
62
68
  import type { CodeBlockContent } from '@tmagic/schema';
63
69
 
64
70
  import FloatingBox from '@editor/components/FloatingBox.vue';
71
+ import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
72
+ import { useWindowRect } from '@editor/hooks/use-window-rect';
65
73
  import CodeEditor from '@editor/layouts/CodeEditor.vue';
66
74
  import type { Services, SlideType } from '@editor/type';
67
75
  import { getConfig } from '@editor/utils/config';
@@ -70,6 +78,9 @@ defineOptions({
70
78
  name: 'MEditorCodeBlockEditor',
71
79
  });
72
80
 
81
+ const width = defineModel<number>('width', { default: 670 });
82
+ const boxVisible = defineModel<boolean>('visible', { default: false });
83
+
73
84
  const props = defineProps<{
74
85
  content: CodeBlockContent;
75
86
  disabled?: boolean;
@@ -84,38 +95,23 @@ const emit = defineEmits<{
84
95
 
85
96
  const services = inject<Services>('services');
86
97
 
87
- const difVisible = ref(false);
88
- const height = ref(globalThis.innerHeight);
89
-
90
- const windowReizehandler = () => {
91
- height.value = globalThis.innerHeight;
92
- };
93
-
94
- globalThis.addEventListener('resize', windowReizehandler);
98
+ const { height: codeBlockEditorHeight } = useEditorContentHeight();
95
99
 
96
- onBeforeUnmount(() => {
97
- globalThis.removeEventListener('resize', windowReizehandler);
98
- });
100
+ const difVisible = ref(false);
101
+ const { rect: windowRect } = useWindowRect();
99
102
 
100
103
  const magicVsEditor = ref<InstanceType<typeof CodeEditor>>();
101
104
 
102
105
  const diffChange = () => {
103
- if (!magicVsEditor.value || !fomDrawer.value?.form) {
106
+ if (!magicVsEditor.value || !formBox.value?.form) {
104
107
  return;
105
108
  }
106
109
 
107
- fomDrawer.value.form.values.content = magicVsEditor.value.getEditorValue();
110
+ formBox.value.form.values.content = magicVsEditor.value.getEditorValue();
108
111
 
109
112
  difVisible.value = false;
110
113
  };
111
114
 
112
- const columnWidth = computed(() => services?.uiService.get('columnWidth'));
113
- const size = computed(() =>
114
- columnWidth.value ? columnWidth.value.center + columnWidth.value.right - (props.isDataSource ? 100 : 0) : 600,
115
- );
116
-
117
- const codeEditorHeight = ref('600px');
118
-
119
115
  const defaultParamColConfig: ColumnConfig = {
120
116
  type: 'row',
121
117
  label: '参数类型',
@@ -199,7 +195,7 @@ const functionConfig = computed<FormConfig>(() => [
199
195
  name: 'content',
200
196
  type: 'vs-code',
201
197
  options: inject('codeOptions', {}),
202
- height: codeEditorHeight.value,
198
+ height: '500px',
203
199
  onChange: (formState: FormState | undefined, code: string) => {
204
200
  try {
205
201
  // 检测js代码是否存在语法错误
@@ -216,6 +212,7 @@ const functionConfig = computed<FormConfig>(() => [
216
212
  ]);
217
213
 
218
214
  const submitForm = (values: CodeBlockContent) => {
215
+ changedValue.value = undefined;
219
216
  emit('submit', values);
220
217
  };
221
218
 
@@ -223,16 +220,7 @@ const errorHandler = (error: any) => {
223
220
  tMagicMessage.error(error.message);
224
221
  };
225
222
 
226
- const fomDrawer = ref<InstanceType<typeof MFormDrawer>>();
227
-
228
- const openHandler = () => {
229
- setTimeout(() => {
230
- if (fomDrawer.value) {
231
- const height = fomDrawer.value?.bodyHeight - 348 - (props.isDataSource ? 50 : 0);
232
- codeEditorHeight.value = `${height > 100 ? height : 600}px`;
233
- }
234
- });
235
- };
223
+ const formBox = ref<InstanceType<typeof MFormBox>>();
236
224
 
237
225
  const changedValue = ref<CodeBlockContent>();
238
226
  const changeHandler = (values: CodeBlockContent) => {
@@ -241,6 +229,7 @@ const changeHandler = (values: CodeBlockContent) => {
241
229
 
242
230
  const beforeClose = (done: (cancel?: boolean) => void) => {
243
231
  if (!changedValue.value) {
232
+ editVisible.value = false;
244
233
  done();
245
234
  return;
246
235
  }
@@ -253,9 +242,13 @@ const beforeClose = (done: (cancel?: boolean) => void) => {
253
242
  })
254
243
  .then(() => {
255
244
  changedValue.value && submitForm(changedValue.value);
245
+ editVisible.value = false;
256
246
  done();
257
247
  })
258
248
  .catch((action: string) => {
249
+ if (action === 'cancel') {
250
+ editVisible.value = false;
251
+ }
259
252
  done(action === 'cancel');
260
253
  });
261
254
  };
@@ -264,7 +257,6 @@ const closedHandler = () => {
264
257
  changedValue.value = undefined;
265
258
  };
266
259
 
267
- const boxVisible = ref<boolean>(false);
268
260
  const editVisible = ref<boolean>(false);
269
261
  const floatingBoxBody = ref<HTMLDivElement>();
270
262
 
@@ -281,14 +273,19 @@ defineExpose({
281
273
  async show() {
282
274
  if (props.slideType !== 'box') {
283
275
  boxVisible.value = true;
276
+ await nextTick();
284
277
  }
285
- await nextTick();
278
+
286
279
  editVisible.value = true;
287
- fomDrawer.value?.show();
288
280
  },
289
281
 
290
- hide() {
291
- fomDrawer.value?.hide();
282
+ async hide() {
283
+ editVisible.value = false;
284
+
285
+ if (props.slideType !== 'box') {
286
+ await nextTick();
287
+ boxVisible.value = false;
288
+ }
292
289
  },
293
290
  });
294
291
  </script>
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <Teleport to="body" v-if="visible">
3
3
  <div ref="target" class="m-editor-float-box" :style="{ ...style, zIndex: curZIndex }" @mousedown="nextZIndex">
4
- <div ref="dragTarget" class="m-editor-float-box-title">
4
+ <div ref="titleEl" class="m-editor-float-box-title">
5
5
  <slot name="title">
6
6
  <span>{{ title }}</span>
7
7
  </slot>
@@ -9,7 +9,7 @@
9
9
  <TMagicButton link size="small" :icon="Close" @click="closeHandler"></TMagicButton>
10
10
  </div>
11
11
  </div>
12
- <div class="m-editor-float-box-body">
12
+ <div class="m-editor-float-box-body" :style="{ height: `${bodyHeight}px` }">
13
13
  <slot name="body"></slot>
14
14
  </div>
15
15
  </div>
@@ -17,7 +17,7 @@
17
17
  </template>
18
18
 
19
19
  <script setup lang="ts">
20
- import { computed, nextTick, onBeforeUnmount, ref, watch, watchEffect } from 'vue';
20
+ import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
21
21
  import { Close } from '@element-plus/icons-vue';
22
22
  import VanillaMoveable from 'moveable';
23
23
 
@@ -28,54 +28,46 @@ interface Position {
28
28
  top: number;
29
29
  }
30
30
 
31
- interface Rect {
32
- width: number | string;
33
- height: number | string;
34
- }
31
+ const width = defineModel<number>('width', { default: 0 });
32
+ const height = defineModel<number>('height', { default: 0 });
33
+ const visible = defineModel<boolean>('visible', { default: false });
35
34
 
36
35
  const props = withDefaults(
37
36
  defineProps<{
38
- visible: boolean;
39
37
  position?: Position;
40
- rect?: Rect;
41
38
  title?: string;
42
39
  beforeClose?: (done: (cancel?: boolean) => void) => void;
43
40
  }>(),
44
41
  {
45
- visible: false,
46
42
  title: '',
47
43
  position: () => ({ left: 0, top: 0 }),
48
- rect: () => ({ width: 'auto', height: 'auto' }),
49
44
  },
50
45
  );
51
46
 
52
- const emit = defineEmits<{
53
- 'update:visible': [boolean];
54
- }>();
55
-
56
47
  const target = ref<HTMLDivElement>();
57
- const dragTarget = ref<HTMLDivElement>();
48
+ const titleEl = ref<HTMLDivElement>();
58
49
 
59
50
  const zIndex = useZIndex();
60
51
  const curZIndex = ref<number>(zIndex.nextZIndex());
61
52
 
62
- const rect = ref({
63
- width: props.rect.width,
64
- height: props.rect.height,
65
- });
53
+ const titleHeight = ref(0);
54
+ const bodyHeight = computed(() => {
55
+ if (height.value) {
56
+ return height.value - titleHeight.value;
57
+ }
66
58
 
67
- watchEffect(() => {
68
- rect.value = {
69
- width: props.rect.width,
70
- height: props.rect.height,
71
- };
59
+ if (target.value) {
60
+ return target.value.clientHeight - titleHeight.value;
61
+ }
62
+
63
+ return 'auto';
72
64
  });
73
65
 
74
66
  const style = computed(() => ({
75
67
  left: `${props.position.left}px`,
76
68
  top: `${props.position.top}px`,
77
- width: typeof rect.value.width === 'string' ? rect.value.width : `${rect.value.width}px`,
78
- height: typeof rect.value.height === 'string' ? rect.value.height : `${rect.value.height}px`,
69
+ width: width.value ? `${width.value}px` : 'auto',
70
+ height: height.value ? `${height.value}px` : 'auto',
79
71
  }));
80
72
 
81
73
  let moveable: VanillaMoveable | null = null;
@@ -90,7 +82,7 @@ const initMoveable = () => {
90
82
  keepRatio: false,
91
83
  origin: false,
92
84
  snappable: true,
93
- dragTarget: dragTarget.value,
85
+ dragTarget: titleEl.value,
94
86
  dragTargetSelf: false,
95
87
  linePadding: 10,
96
88
  controlPadding: 10,
@@ -102,8 +94,8 @@ const initMoveable = () => {
102
94
  });
103
95
 
104
96
  moveable.on('resize', (e) => {
105
- rect.value.width = e.width;
106
- rect.value.height = e.height;
97
+ width.value = e.width;
98
+ height.value = e.height;
107
99
  e.target.style.width = `${e.width}px`;
108
100
  e.target.style.height = `${e.height}px`;
109
101
  e.target.style.transform = e.drag.transform;
@@ -116,11 +108,22 @@ const destroyMoveable = () => {
116
108
  };
117
109
 
118
110
  watch(
119
- () => props.visible,
111
+ visible,
120
112
  async (visible) => {
121
113
  if (visible) {
122
114
  await nextTick();
123
- initMoveable();
115
+
116
+ const targetRect = target.value?.getBoundingClientRect();
117
+ if (targetRect) {
118
+ width.value = targetRect.width;
119
+ height.value = targetRect.height;
120
+ initMoveable();
121
+ }
122
+
123
+ if (titleEl.value) {
124
+ const titleRect = titleEl.value.getBoundingClientRect();
125
+ titleHeight.value = titleRect.height;
126
+ }
124
127
  } else {
125
128
  destroyMoveable();
126
129
  }
@@ -136,7 +139,7 @@ onBeforeUnmount(() => {
136
139
 
137
140
  const hide = (cancel?: boolean) => {
138
141
  if (cancel !== false) {
139
- emit('update:visible', false);
142
+ visible.value = false;
140
143
  }
141
144
  };
142
145
 
@@ -153,6 +156,8 @@ const nextZIndex = () => {
153
156
  };
154
157
 
155
158
  defineExpose({
159
+ bodyHeight,
156
160
  target,
161
+ titleEl,
157
162
  });
158
163
  </script>
@@ -21,7 +21,7 @@
21
21
  </template>
22
22
 
23
23
  <script lang="ts" setup>
24
- import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
24
+ import { computed, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
25
25
  import { OnDrag } from 'gesto';
26
26
 
27
27
  import Resizer from './Resizer.vue';
@@ -34,6 +34,7 @@ const emit = defineEmits(['update:left', 'change', 'update:right']);
34
34
 
35
35
  const props = withDefaults(
36
36
  defineProps<{
37
+ width?: number;
37
38
  left?: number;
38
39
  right?: number;
39
40
  minLeft?: number;
@@ -54,8 +55,11 @@ const el = ref<HTMLElement>();
54
55
 
55
56
  const hasLeft = computed(() => typeof props.left !== 'undefined');
56
57
  const hasRight = computed(() => typeof props.right !== 'undefined');
58
+ const center = ref(0);
59
+
60
+ let clientWidth = 0;
57
61
 
58
- const getCenterWidth = (clientWidth: number, l = 0, r = 0) => {
62
+ const getCenterWidth = (l = 0, r = 0) => {
59
63
  let right = r > 0 ? r : 0;
60
64
  let left = l > 0 ? l : 0;
61
65
  let center = clientWidth - left - right;
@@ -76,45 +80,51 @@ const getCenterWidth = (clientWidth: number, l = 0, r = 0) => {
76
80
  };
77
81
  };
78
82
 
79
- let clientWidth = 0;
80
- const resizerObserver = new ResizeObserver((entries) => {
81
- for (const { contentRect } of entries) {
82
- clientWidth = contentRect.width;
83
+ const widthChange = (width: number) => {
84
+ if (width <= 0) {
85
+ return;
86
+ }
83
87
 
84
- let left = props.left || 0;
85
- let right = props.right || 0;
88
+ clientWidth = width;
89
+ let left = props.left || 0;
90
+ let right = props.right || 0;
86
91
 
87
- if (left > clientWidth) {
88
- left = clientWidth / 3;
89
- }
92
+ if (left > clientWidth) {
93
+ left = clientWidth / 3;
94
+ }
90
95
 
91
- if (right > clientWidth) {
92
- right = clientWidth / 3;
93
- }
96
+ if (right > clientWidth) {
97
+ right = clientWidth / 3;
98
+ }
94
99
 
95
- const columnWidth = getCenterWidth(clientWidth, left, right);
100
+ const columnWidth = getCenterWidth(left, right);
96
101
 
97
- center.value = columnWidth.center;
102
+ center.value = columnWidth.center;
98
103
 
99
- emit('change', {
100
- left: columnWidth.left,
101
- center: center.value,
102
- right: columnWidth.right,
103
- });
104
- }
105
- });
104
+ emit('change', columnWidth);
105
+ };
106
106
 
107
- onMounted(() => {
108
- if (el.value) {
109
- resizerObserver.observe(el.value);
110
- }
111
- });
107
+ if (typeof props.width !== 'number') {
108
+ const resizerObserver = new ResizeObserver((entries) => {
109
+ for (const { contentRect } of entries) {
110
+ widthChange(contentRect.width);
111
+ }
112
+ });
112
113
 
113
- onBeforeUnmount(() => {
114
- resizerObserver.disconnect();
115
- });
114
+ onMounted(() => {
115
+ if (el.value) {
116
+ resizerObserver.observe(el.value);
117
+ }
118
+ });
116
119
 
117
- const center = ref(0);
120
+ onBeforeUnmount(() => {
121
+ resizerObserver.disconnect();
122
+ });
123
+ } else {
124
+ watchEffect(() => {
125
+ if (typeof props.width === 'number') widthChange(props.width);
126
+ });
127
+ }
118
128
 
119
129
  const changeLeft = ({ deltaX }: OnDrag) => {
120
130
  if (typeof props.left === 'undefined') return;
@@ -125,7 +135,7 @@ const changeLeft = ({ deltaX }: OnDrag) => {
125
135
  left = props.left;
126
136
  }
127
137
 
128
- const columnWidth = getCenterWidth(clientWidth, left, props.right || 0);
138
+ const columnWidth = getCenterWidth(left, props.right || 0);
129
139
 
130
140
  center.value = columnWidth.center;
131
141
 
@@ -145,7 +155,7 @@ const changeRight = ({ deltaX }: OnDrag) => {
145
155
  right = props.right;
146
156
  }
147
157
 
148
- const columnWidth = getCenterWidth(clientWidth, props.left, right);
158
+ const columnWidth = getCenterWidth(props.left, right);
149
159
 
150
160
  center.value = columnWidth.center;
151
161
 
@@ -158,7 +168,8 @@ const changeRight = ({ deltaX }: OnDrag) => {
158
168
 
159
169
  defineExpose({
160
170
  updateWidth() {
161
- const columnWidth = getCenterWidth(el.value?.clientWidth || clientWidth, props.left, props.right);
171
+ clientWidth = props.width ?? el.value?.clientWidth ?? clientWidth;
172
+ const columnWidth = getCenterWidth(props.left, props.right);
162
173
 
163
174
  emit('change', {
164
175
  left: columnWidth.left,
@@ -20,3 +20,5 @@ export * from './use-code-block-edit';
20
20
  export * from './use-data-source-method';
21
21
  export * from './use-stage';
22
22
  export * from './use-float-box';
23
+ export * from './use-window-rect';
24
+ export * from './use-editor-content-height';
@@ -20,7 +20,7 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
20
20
  }
21
21
 
22
22
  codeConfig.value = {
23
- name: '代码块',
23
+ name: '',
24
24
  content: `({app, params}) => {\n // place your code here\n}`,
25
25
  params: [],
26
26
  };
@@ -0,0 +1,20 @@
1
+ import { computed, inject, ref, watchEffect } from 'vue';
2
+
3
+ import type { Services } from '@editor/type';
4
+
5
+ export const useEditorContentHeight = () => {
6
+ const services = inject<Services>('services');
7
+ const frameworkHeight = computed(() => services?.uiService.get('frameworkRect').height || 0);
8
+ const navMenuHeight = computed(() => services?.uiService.get('navMenuRect').height || 0);
9
+ const editorContentHeight = computed(() => frameworkHeight.value - navMenuHeight.value);
10
+
11
+ const height = ref(0);
12
+ watchEffect(() => {
13
+ if (height.value > 0) return;
14
+ height.value = editorContentHeight.value;
15
+ });
16
+
17
+ return {
18
+ height,
19
+ };
20
+ };
@@ -26,34 +26,34 @@ export const useFloatBox = (slideKeys: ComputedRef<string[]>) => {
26
26
  const showingBoxKeys = computed(() =>
27
27
  Object.keys(floatBoxStates.value).filter((key) => floatBoxStates.value[key].status),
28
28
  );
29
- const isDraging = ref(false);
29
+ const isDragging = ref(false);
30
30
 
31
- const dragstartHandler = () => (isDraging.value = true);
31
+ const dragstartHandler = () => (isDragging.value = true);
32
32
  const dragendHandler = (key: string, e: DragEvent) => {
33
33
  floatBoxStates.value[key] = {
34
34
  left: e.clientX,
35
35
  top: e.clientY,
36
36
  status: true,
37
37
  };
38
- isDraging.value = false;
38
+ isDragging.value = false;
39
39
  };
40
40
 
41
41
  document.body.addEventListener('dragover', (e: DragEvent) => {
42
- if (!isDraging.value) return;
42
+ if (!isDragging.value) return;
43
43
  e.preventDefault();
44
44
  });
45
45
 
46
46
  watch(
47
47
  () => slideKeys.value,
48
- () => {
49
- for (const key in slideKeys.value) {
50
- if (floatBoxStates.value[key]) continue;
48
+ (slideKeys) => {
49
+ slideKeys.forEach((key) => {
50
+ if (floatBoxStates.value[key]) return;
51
51
  floatBoxStates.value[key] = {
52
52
  status: false,
53
53
  top: 0,
54
54
  left: 0,
55
55
  };
56
- }
56
+ });
57
57
  },
58
58
  {
59
59
  deep: true,
@@ -0,0 +1,20 @@
1
+ import { onBeforeUnmount, reactive } from 'vue';
2
+
3
+ export const useWindowRect = () => {
4
+ const rect = reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
5
+
6
+ const windowResizeHandler = () => {
7
+ rect.width = globalThis.innerWidth;
8
+ rect.height = globalThis.innerHeight;
9
+ };
10
+
11
+ globalThis.addEventListener('resize', windowResizeHandler);
12
+
13
+ onBeforeUnmount(() => {
14
+ globalThis.removeEventListener('resize', windowResizeHandler);
15
+ });
16
+
17
+ return {
18
+ rect,
19
+ };
20
+ };