@tmagic/editor 1.0.0-beta.3 → 1.0.0-beta.6

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 (53) hide show
  1. package/dist/style.css +506 -0
  2. package/dist/tmagic-editor.es.js +4463 -0
  3. package/dist/tmagic-editor.es.js.map +1 -0
  4. package/dist/tmagic-editor.umd.js +4524 -0
  5. package/dist/tmagic-editor.umd.js.map +1 -0
  6. package/dist/types/src/Editor.vue.d.ts +136 -0
  7. package/dist/types/src/components/Icon.vue.d.ts +13 -0
  8. package/dist/types/src/components/ScrollViewer.vue.d.ts +23 -0
  9. package/dist/types/src/components/ToolButton.vue.d.ts +35 -0
  10. package/dist/types/src/fields/Code.vue.d.ts +24 -0
  11. package/dist/types/src/fields/CodeLink.vue.d.ts +54 -0
  12. package/dist/types/src/fields/UISelect.vue.d.ts +32 -0
  13. package/dist/types/src/index.d.ts +19 -0
  14. package/dist/types/src/layouts/AddPageBox.vue.d.ts +5 -0
  15. package/dist/types/src/layouts/CodeEditor.vue.d.ts +47 -0
  16. package/dist/types/src/layouts/Framework.vue.d.ts +11 -0
  17. package/dist/types/src/layouts/NavMenu.vue.d.ts +25 -0
  18. package/dist/types/src/layouts/PropsPanel.vue.d.ts +13 -0
  19. package/dist/types/src/layouts/Resizer.vue.d.ts +13 -0
  20. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +12 -0
  21. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +31 -0
  22. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +973 -0
  23. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +27 -0
  24. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +11 -0
  25. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +192 -0
  26. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +18 -0
  27. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +33 -0
  28. package/dist/types/src/services/BaseService.d.ts +56 -0
  29. package/dist/types/src/services/editor.d.ts +122 -0
  30. package/dist/types/src/services/events.d.ts +16 -0
  31. package/dist/types/src/services/history.d.ts +51 -0
  32. package/dist/types/src/services/props.d.ts +36 -0
  33. package/dist/types/src/services/ui.d.ts +33 -0
  34. package/dist/types/src/shims-vue.d.ts +6 -0
  35. package/dist/types/src/type.d.ts +192 -0
  36. package/dist/types/src/utils/compose.d.ts +5 -0
  37. package/dist/types/src/utils/config.d.ts +4 -0
  38. package/dist/types/src/utils/editor.d.ts +44 -0
  39. package/dist/types/src/utils/index.d.ts +4 -0
  40. package/dist/types/src/utils/logger.d.ts +5 -0
  41. package/dist/types/src/utils/props.d.ts +49 -0
  42. package/dist/types/src/utils/scroll-viewer.d.ts +35 -0
  43. package/dist/types/src/utils/undo-redo.d.ts +12 -0
  44. package/dist/types/src/vite-env.d.ts +1 -0
  45. package/package.json +6 -6
  46. package/src/components/ScrollViewer.vue +1 -0
  47. package/src/layouts/NavMenu.vue +7 -3
  48. package/src/layouts/PropsPanel.vue +5 -10
  49. package/src/services/editor.ts +10 -3
  50. package/src/theme/nav-menu.scss +3 -3
  51. package/src/theme/stage.scss +1 -0
  52. package/src/utils/editor.ts +1 -20
  53. package/src/utils/scroll-viewer.ts +7 -4
@@ -0,0 +1,192 @@
1
+ import type { Component } from 'vue';
2
+ import type { FormConfig } from '@tmagic/form';
3
+ import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
4
+ import type StageCore from '@tmagic/stage';
5
+ import type { ComponentListService } from './services/componentList';
6
+ import type { EditorService } from './services/editor';
7
+ import type { EventsService } from './services/events';
8
+ import type { HistoryService } from './services/history';
9
+ import type { PropsService } from './services/props';
10
+ import type { UiService } from './services/ui';
11
+ export declare type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> | MNode;
12
+ export declare type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
13
+ export interface InstallOptions {
14
+ [key: string]: any;
15
+ }
16
+ export interface Services {
17
+ editorService: EditorService;
18
+ historyService: HistoryService;
19
+ eventsService: EventsService;
20
+ propsService: PropsService;
21
+ componentListService: ComponentListService;
22
+ uiService: UiService;
23
+ }
24
+ export interface StoreState {
25
+ root: MApp | null;
26
+ page: MPage | null;
27
+ parent: MContainer | null;
28
+ node: MNode | null;
29
+ stage: StageCore | null;
30
+ modifiedNodeIds: Map<Id, Id>;
31
+ }
32
+ export interface PropsState {
33
+ propsConfigMap: Record<string, FormConfig>;
34
+ propsValueMap: Record<string, MNode>;
35
+ }
36
+ export interface ComponentGroupState {
37
+ list: ComponentGroup[];
38
+ }
39
+ export interface SetColumnWidth {
40
+ left?: number;
41
+ center?: number | 'auto';
42
+ right?: number;
43
+ }
44
+ export interface GetColumnWidth {
45
+ left: number;
46
+ center: number;
47
+ right: number;
48
+ }
49
+ export interface StageRect {
50
+ width: number;
51
+ height: number;
52
+ }
53
+ export interface UiState {
54
+ /** 当前点击画布是否触发选中,true: 不触发,false: 触发,默认为false */
55
+ uiSelectMode: boolean;
56
+ /** 是否显示整个配置源码, true: 显示, false: 不显示,默认为false */
57
+ showSrc: boolean;
58
+ /** 画布显示放大倍数,默认为 1 */
59
+ zoom: number;
60
+ /** 画布容器的宽高 */
61
+ stageContainerRect: StageRect;
62
+ /** 画布顶层div的宽高,可用于改变画布的大小 */
63
+ stageRect: StageRect;
64
+ /** 编辑器列布局每一列的宽度,分为左中右三列 */
65
+ columnWidth: GetColumnWidth;
66
+ /** 是否显示画布参考线,true: 显示,false: 不显示,默认为true */
67
+ showGuides: boolean;
68
+ /** 是否显示标尺,true: 显示,false: 不显示,默认为true */
69
+ showRule: boolean;
70
+ }
71
+ export interface EditorNodeInfo {
72
+ node?: MNode;
73
+ parent?: MContainer;
74
+ page?: MPage;
75
+ }
76
+ export interface AddMNode {
77
+ type: string;
78
+ name?: string;
79
+ [key: string]: any;
80
+ }
81
+ /**
82
+ * 菜单按钮
83
+ */
84
+ export interface MenuButton {
85
+ /**
86
+ * 按钮类型
87
+ * button: 只有文字不带边框的按钮
88
+ * text: 纯文本
89
+ * dropdown: 下拉菜单
90
+ * divider: 分隔线
91
+ * zoom: 放大缩小
92
+ */
93
+ type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
94
+ /** 展示的文案 */
95
+ text?: string;
96
+ /** 鼠标悬浮是显示的气泡中的文案 */
97
+ tooltip?: string;
98
+ /** element-plus icon class */
99
+ icon?: string | Component<{}, {}, any>;
100
+ /** 是否置灰,默认为false */
101
+ disabled?: boolean | ((data?: Services) => boolean);
102
+ /** 是否显示,默认为true */
103
+ display?: boolean | ((data?: Services) => boolean);
104
+ /** type为button/dropdown时点击运行的方法 */
105
+ handler?: (data?: Services) => Promise<any> | any;
106
+ /** type为dropdown时,下拉的菜单列表 */
107
+ items?: {
108
+ /** 展示的文案 */
109
+ text: string;
110
+ /** 点击运行的方法 */
111
+ handler(data: Services): any;
112
+ }[];
113
+ }
114
+ export interface MenuComponent {
115
+ type: 'component';
116
+ /** Vue3组件 */
117
+ component: any;
118
+ /** 传入组件的props对象 */
119
+ props?: Record<string, any>;
120
+ /** 组件监听的事件对象,如:{ click: () => { console.log('click'); } } */
121
+ listeners?: Record<string, Function>;
122
+ slots?: Record<string, any>;
123
+ /** 是否显示,默认为true */
124
+ display?: boolean | ((data?: Services) => Promise<boolean> | boolean);
125
+ }
126
+ /**
127
+ * '/': 分隔符
128
+ * 'delete': 删除按钮
129
+ * 'undo': 撤销按钮
130
+ * 'redo': 恢复按钮
131
+ * 'zoom-in': 放大按钮
132
+ * 'zoom-out': 缩小按钮
133
+ */
134
+ export declare type MenuItem = '/' | 'delete' | 'undo' | 'redo' | 'zoom' | 'zoom-in' | 'zoom-out' | 'guides' | 'rule' | MenuButton | MenuComponent;
135
+ /** 工具栏 */
136
+ export interface MenuBarData {
137
+ /** 顶部工具栏左边项 */
138
+ left?: MenuItem[];
139
+ /** 顶部工具栏中间项 */
140
+ center?: MenuItem[];
141
+ /** 顶部工具栏右边项 */
142
+ right?: MenuItem[];
143
+ }
144
+ export interface SideComponent extends MenuComponent {
145
+ /** 显示文案 */
146
+ text: string;
147
+ /** element-plus icon class */
148
+ icon: Component<{}, {}, any>;
149
+ }
150
+ /**
151
+ * component-list: 组件列表
152
+ * layer: 已选组件树
153
+ */
154
+ export declare type SideItem = 'component-list' | 'layer' | SideComponent;
155
+ /** 工具栏 */
156
+ export interface SideBarData {
157
+ /** 容器类型 */
158
+ type: 'tabs';
159
+ /** 默认激活的内容 */
160
+ status: string;
161
+ /** panel列表 */
162
+ items: SideItem[];
163
+ }
164
+ export interface ComponentItem {
165
+ /** 显示文案 */
166
+ text: string;
167
+ /** 组件类型 */
168
+ type: string;
169
+ /** element-plus icon class */
170
+ icon?: string | Component;
171
+ [key: string]: any;
172
+ }
173
+ export interface ComponentGroup {
174
+ /** 显示文案 */
175
+ title: string;
176
+ /** 组内列表 */
177
+ items: ComponentItem[];
178
+ }
179
+ export declare enum LayerOffset {
180
+ TOP = "top",
181
+ BOTTOM = "bottom"
182
+ }
183
+ /** 容器布局 */
184
+ export declare enum Layout {
185
+ FLEX = "flex",
186
+ FIXED = "fixed",
187
+ RELATIVE = "relative",
188
+ ABSOLUTE = "absolute"
189
+ }
190
+ export declare enum Keys {
191
+ ESCAPE = "Space"
192
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @param {Array} middleware
3
+ * @return {Function}
4
+ */
5
+ export declare const compose: (middleware: Function[]) => (args: any[], next?: Function | undefined) => Promise<void>;
@@ -0,0 +1,4 @@
1
+ import { InstallOptions } from '../type';
2
+ declare const setConfig: (option: InstallOptions) => void;
3
+ declare const getConfig: (key: keyof InstallOptions) => unknown;
4
+ export { getConfig, setConfig };
@@ -0,0 +1,44 @@
1
+ import { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
2
+ import { Layout } from '../type';
3
+ export declare const COPY_STORAGE_KEY = "$MagicEditorCopyData";
4
+ export declare const generateId: (type: string | number) => string;
5
+ /**
6
+ * 获取所有页面配置
7
+ * @param app DSL跟节点
8
+ * @returns 所有页面配置
9
+ */
10
+ export declare const getPageList: (app: MApp) => MPage[];
11
+ /**
12
+ * 获取所有页面名称
13
+ * @param pages 所有页面配置
14
+ * @returns 所有页面名称
15
+ */
16
+ export declare const getPageNameList: (pages: MPage[]) => string[];
17
+ /**
18
+ * 新增页面时,生成页面名称
19
+ * @param {Object} pageNameList 所有页面名称
20
+ * @returns {string}
21
+ */
22
+ export declare const generatePageName: (pageNameList: string[]) => string;
23
+ /**
24
+ * 新增页面时,生成页面名称
25
+ * @param {Object} app 所有页面配置
26
+ * @returns {string}
27
+ */
28
+ export declare const generatePageNameByApp: (app: MApp) => string;
29
+ /**
30
+ * 将组件与组件的子元素配置中的id都设置成一个新的ID
31
+ * @param {Object} config 组件配置
32
+ */
33
+ export declare const setNewItemId: (config: MNode, parent?: MPage | undefined) => void;
34
+ /**
35
+ * @param {Object} node
36
+ * @returns {boolean}
37
+ */
38
+ export declare const isFixed: (node: MNode) => boolean;
39
+ export declare const getNodeIndex: (node: MNode, parent: MContainer) => number;
40
+ export declare const toRelative: (node: MNode) => MNode;
41
+ export declare const initPosition: (node: MNode, layout: Layout) => MNode;
42
+ export declare const setLayout: (node: MNode, layout: Layout) => MNode;
43
+ export declare const change2Fixed: (node: MNode, root: MApp) => MNode;
44
+ export declare const Fixed2Other: (node: MNode, root: MApp, getLayout: (node: MNode) => Promise<Layout>) => Promise<MNode>;
@@ -0,0 +1,4 @@
1
+ export * from './config';
2
+ export * from './props';
3
+ export * from './logger';
4
+ export * from './editor';
@@ -0,0 +1,5 @@
1
+ export declare const log: (...args: any[]) => void;
2
+ export declare const info: (...args: any[]) => void;
3
+ export declare const warn: (...args: any[]) => void;
4
+ export declare const debug: (...args: any[]) => void;
5
+ export declare const error: (...args: any[]) => void;
@@ -0,0 +1,49 @@
1
+ import type { ChildConfig, FormConfig, FormState } from '@tmagic/form';
2
+ /**
3
+ * 统一为组件属性表单加上事件、高级、样式配置
4
+ * @param config 组件属性配置
5
+ * @returns Object
6
+ */
7
+ export declare const fillConfig: (config?: FormConfig) => {
8
+ type: string;
9
+ items: ({
10
+ title: string;
11
+ labelWidth: string;
12
+ items: (ChildConfig & {
13
+ [key: string]: any;
14
+ })[];
15
+ } | {
16
+ title: string;
17
+ items: {
18
+ type: string;
19
+ name: string;
20
+ items: ({
21
+ name: string;
22
+ label: string;
23
+ type: string;
24
+ options: (mForm: FormState, { formValue }: any) => {
25
+ text: string;
26
+ value: string;
27
+ }[];
28
+ } | {
29
+ name: string;
30
+ label: string;
31
+ type: string;
32
+ options?: undefined;
33
+ })[];
34
+ }[];
35
+ labelWidth?: undefined;
36
+ })[];
37
+ }[];
38
+ export declare const DEFAULT_CONFIG: FormConfig;
39
+ /**
40
+ * 获取默认属性配置
41
+ * @param type 组件类型
42
+ * @returns Object
43
+ */
44
+ export declare const getDefaultPropsValue: (type: string) => {
45
+ type: string;
46
+ id: string;
47
+ style: {};
48
+ name: string;
49
+ };
@@ -0,0 +1,35 @@
1
+ interface ScrollViewerOptions {
2
+ container: HTMLDivElement;
3
+ target: HTMLDivElement;
4
+ zoom: number;
5
+ }
6
+ export declare class ScrollViewer {
7
+ private enter;
8
+ private targetEnter;
9
+ private keydown;
10
+ private container;
11
+ private target;
12
+ private zoom;
13
+ private scrollLeft;
14
+ private scrollTop;
15
+ private x;
16
+ private y;
17
+ private resizeObserver;
18
+ constructor(options: ScrollViewerOptions);
19
+ destroy(): void;
20
+ setZoom(zoom: number): void;
21
+ private scroll;
22
+ private removeHandler;
23
+ private wheelHandler;
24
+ private mouseEnterHandler;
25
+ private mouseLeaveHandler;
26
+ private targetMouseEnterHandler;
27
+ private targetMouseLeaveHandler;
28
+ private mousedownHandler;
29
+ private mouseupHandler;
30
+ private mousemoveHandler;
31
+ private keydownHandler;
32
+ private keyupHandler;
33
+ private setScrollOffset;
34
+ }
35
+ export {};
@@ -0,0 +1,12 @@
1
+ export declare class UndoRedo<T = any> {
2
+ private elementList;
3
+ private listCursor;
4
+ private listMaxSize;
5
+ constructor(listMaxSize?: number);
6
+ pushElement(element: T): void;
7
+ canUndo(): boolean;
8
+ undo(): T | null;
9
+ canRedo(): boolean;
10
+ redo(): T | null;
11
+ getCurrentElement(): T | null;
12
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-beta.3",
2
+ "version": "1.0.0-beta.6",
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.3",
32
- "@tmagic/form": "^1.0.0-beta.3",
33
- "@tmagic/schema": "^1.0.0-beta.3",
34
- "@tmagic/stage": "^1.0.0-beta.3",
35
- "@tmagic/utils": "^1.0.0-beta.3",
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.6",
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(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);