@tmagic/editor 1.0.0-beta.4 → 1.0.0-beta.7

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.
@@ -1,5 +1,5 @@
1
1
  import type { DefineComponent, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes, PropType } from 'vue';
2
- import { MenuBarData } from '../type';
2
+ import { GetColumnWidth, MenuBarData } from '../type';
3
3
  declare const _default: DefineComponent<{
4
4
  data: {
5
5
  type: PropType<MenuBarData>;
@@ -10,6 +10,7 @@ declare const _default: DefineComponent<{
10
10
  };
11
11
  }, {
12
12
  keys: ComputedRef<(keyof MenuBarData)[]>;
13
+ columnWidth: ComputedRef<GetColumnWidth | undefined>;
13
14
  }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, Record<string, any>, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
14
15
  data: {
15
16
  type: PropType<MenuBarData>;
@@ -42,4 +42,3 @@ export declare const initPosition: (node: MNode, layout: Layout) => MNode;
42
42
  export declare const setLayout: (node: MNode, layout: Layout) => MNode;
43
43
  export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
44
44
  export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (node: MNode) => Promise<Layout>) => Promise<MNode>;
45
- export declare const defaults: (object: any, source: any) => any;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.4",
2
+ "version": "1.0.0-beta.7",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": false,
5
5
  "main": "dist/tmagic-editor.umd.js",
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@element-plus/icons": "0.0.11",
31
- "@tmagic/core": "^1.0.0-beta.4",
32
- "@tmagic/form": "^1.0.0-beta.4",
33
- "@tmagic/schema": "^1.0.0-beta.4",
34
- "@tmagic/stage": "^1.0.0-beta.4",
35
- "@tmagic/utils": "^1.0.0-beta.4",
31
+ "@tmagic/core": "^1.0.0-beta.6",
32
+ "@tmagic/form": "^1.0.0-beta.6",
33
+ "@tmagic/schema": "^1.0.0-beta.6",
34
+ "@tmagic/stage": "^1.0.0-beta.7",
35
+ "@tmagic/utils": "^1.0.0-beta.6",
36
36
  "color": "^3.1.3",
37
37
  "element-plus": "^2.0.2",
38
38
  "events": "^3.3.0",
@@ -57,6 +57,7 @@ export default defineComponent({
57
57
  width: ${props.width}px;
58
58
  height: ${props.height}px;
59
59
  position: absolute;
60
+ margin-top: 30px;
60
61
  `,
61
62
  ),
62
63
  };
@@ -1,16 +1,16 @@
1
1
  <template>
2
2
  <div class="m-editor-nav-menu" :style="{ height: `${height}px` }">
3
- <div v-for="key in keys" :class="`menu-${key}`" :key="key">
3
+ <div v-for="key in keys" :class="`menu-${key}`" :key="key" :style="`width: ${columnWidth?.[key]}px`">
4
4
  <tool-button :data="item" v-for="(item, index) in data[key]" :key="index"></tool-button>
5
5
  </div>
6
6
  </div>
7
7
  </template>
8
8
 
9
9
  <script lang="ts">
10
- import { computed, defineComponent, PropType } from 'vue';
10
+ import { computed, defineComponent, inject, PropType } from 'vue';
11
11
 
12
12
  import ToolButton from '@editor/components/ToolButton.vue';
13
- import { MenuBarData } from '@editor/type';
13
+ import { GetColumnWidth, MenuBarData, Services } from '@editor/type';
14
14
 
15
15
  export default defineComponent({
16
16
  name: 'nav-menu',
@@ -29,8 +29,12 @@ export default defineComponent({
29
29
  },
30
30
 
31
31
  setup(props) {
32
+ const services = inject<Services>('services');
33
+
32
34
  return {
33
35
  keys: computed(() => Object.keys(props.data) as Array<keyof MenuBarData>),
36
+
37
+ columnWidth: computed(() => services?.uiService.get<GetColumnWidth>('columnWidth')),
34
38
  };
35
39
  },
36
40
  });
@@ -10,7 +10,7 @@
10
10
  </template>
11
11
 
12
12
  <script lang="ts">
13
- import { defineComponent, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
13
+ import { computed, defineComponent, getCurrentInstance, inject, onMounted, ref, watchEffect } from 'vue';
14
14
  import { ElMessage } from 'element-plus';
15
15
 
16
16
  import type { FormValue, MForm } from '@tmagic/form';
@@ -30,21 +30,16 @@ export default defineComponent({
30
30
  // ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
31
31
  const curFormConfig = ref<any>([]);
32
32
  const services = inject<Services>('services');
33
+ const node = computed(() => services?.editorService.get<MNode | null>('node'));
33
34
 
34
35
  const init = async () => {
35
- const node = services?.editorService.get<MNode | null>('node');
36
-
37
- if (!node) {
36
+ if (!node.value) {
38
37
  curFormConfig.value = [];
39
38
  return;
40
39
  }
41
40
 
42
- if (node.devconfig && node.style && !isNaN(+node.style.height) && !isNaN(+node.style.width)) {
43
- node.devconfig.ratio = node.style.height / node.style.width || 1;
44
- }
45
-
46
- values.value = node;
47
- const type = node.type || (node.items ? 'container' : 'text');
41
+ values.value = node.value;
42
+ const type = node.value.type || (node.value.items ? 'container' : 'text');
48
43
  curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
49
44
  };
50
45
 
@@ -17,7 +17,7 @@
17
17
  */
18
18
 
19
19
  import { reactive, toRaw } from 'vue';
20
- import { cloneDeep } from 'lodash-es';
20
+ import { cloneDeep, mergeWith } from 'lodash-es';
21
21
  import serialize from 'serialize-javascript';
22
22
 
23
23
  import type { Id, MApp, MComponent, MContainer, MNode, MPage } from '@tmagic/schema';
@@ -31,7 +31,6 @@ import { LayerOffset, Layout } from '@editor/type';
31
31
  import {
32
32
  change2Fixed,
33
33
  COPY_STORAGE_KEY,
34
- defaults,
35
34
  Fixed2Other,
36
35
  getNodeIndex,
37
36
  initPosition,
@@ -185,6 +184,10 @@ class Editor extends BaseService {
185
184
  const { node, parent, page } = this.getNodeInfo(id);
186
185
  if (!node) throw new Error('获取不到组件信息');
187
186
 
187
+ if (node.id === this.state.root?.id) {
188
+ throw new Error('不能选根节点');
189
+ }
190
+
188
191
  this.set('node', node);
189
192
  this.set('page', page || null);
190
193
  this.set('parent', parent || null);
@@ -292,7 +295,11 @@ class Editor extends BaseService {
292
295
 
293
296
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, this.get<MApp>('root'));
294
297
 
295
- defaults(newConfig, node);
298
+ newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
299
+ if (Array.isArray(srcValue)) {
300
+ return srcValue;
301
+ }
302
+ });
296
303
 
297
304
  if (!newConfig.type) throw new Error('配置缺少type值');
298
305
 
@@ -21,12 +21,12 @@
21
21
  align-items: center;
22
22
  }
23
23
 
24
- .menu-left {
25
- padding-left: 16px;
24
+ .menu-center {
25
+ justify-content: center;
26
26
  }
27
27
 
28
28
  .menu-right {
29
- padding-right: 16px;
29
+ justify-content: flex-end;
30
30
  }
31
31
 
32
32
  .menu-item {
@@ -15,6 +15,7 @@
15
15
  position: relative;
16
16
  border: 1px solid $--border-color;
17
17
  transition: transform 0.3s;
18
+ box-sizing: content-box;
18
19
 
19
20
  &::-webkit-scrollbar {
20
21
  width: 0 !important;
@@ -16,7 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import { cloneDeep, random } from 'lodash-es';
19
+ import { random } from 'lodash-es';
20
20
 
21
21
  import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
22
22
  import { getNodePath, isPop } from '@tmagic/utils';
@@ -223,22 +223,3 @@ export const Fixed2Other = async (node: MNode, root: MApp, getLayout: (node: MNo
223
223
 
224
224
  return toRelative(node);
225
225
  };
226
-
227
- export const defaults = (object: any, source: any) => {
228
- let o = source;
229
- if (Array.isArray(object)) {
230
- o = object;
231
- }
232
-
233
- Object.entries(o).forEach(([key, value]: [string, any]) => {
234
- if (typeof object[key] === 'undefined') {
235
- object[key] = value;
236
- return;
237
- }
238
-
239
- if (value && typeof value !== 'string' && Object.keys(value).length) {
240
- object[key] = defaults(cloneDeep(object[key]), value);
241
- }
242
- });
243
- return object;
244
- };
@@ -25,7 +25,8 @@ export class ScrollViewer {
25
25
  const { width, height } = contentRect;
26
26
  const targetRect = this.target.getBoundingClientRect();
27
27
  const targetWidth = targetRect.width * this.zoom;
28
- const targetHeight = targetRect.height * this.zoom;
28
+ const targetMarginTop = Number(this.target.style.marginTop) || 0;
29
+ const targetHeight = (targetRect.height + targetMarginTop) * this.zoom;
29
30
 
30
31
  if (targetWidth < width) {
31
32
  (this.target as any)._left = 0;
@@ -154,11 +155,13 @@ export class ScrollViewer {
154
155
  event.preventDefault();
155
156
  event.stopImmediatePropagation();
156
157
  event.stopPropagation();
157
- } else if (this.keydown) return;
158
+ }
158
159
 
159
- this.keydown = true;
160
+ if (event.code !== Keys.ESCAPE || !this.enter || this.keydown) {
161
+ return;
162
+ }
160
163
 
161
- event.preventDefault();
164
+ this.keydown = true;
162
165
 
163
166
  this.target.style.cursor = 'grab';
164
167
  this.container.addEventListener('mousedown', this.mousedownHandler);