@tmagic/editor 1.3.16 → 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 (129) hide show
  1. package/dist/style.css +25 -9
  2. package/dist/tmagic-editor.js +1048 -632
  3. package/dist/tmagic-editor.umd.cjs +1065 -647
  4. package/package.json +23 -21
  5. package/src/components/CodeBlockEditor.vue +82 -59
  6. package/src/components/FloatingBox.vue +71 -25
  7. package/src/components/SplitView.vue +46 -35
  8. package/src/fields/Code.vue +12 -10
  9. package/src/fields/CodeLink.vue +9 -9
  10. package/src/fields/CodeSelect.vue +7 -5
  11. package/src/fields/CodeSelectCol.vue +1 -1
  12. package/src/fields/DataSourceFieldSelect.vue +118 -27
  13. package/src/fields/DataSourceFields.vue +10 -3
  14. package/src/fields/DataSourceInput.vue +7 -7
  15. package/src/fields/DataSourceMethodSelect.vue +1 -1
  16. package/src/fields/DataSourceMethods.vue +3 -3
  17. package/src/fields/DataSourceMocks.vue +3 -3
  18. package/src/fields/DataSourceSelect.vue +6 -18
  19. package/src/fields/EventSelect.vue +1 -1
  20. package/src/fields/KeyValue.vue +8 -8
  21. package/src/fields/PageFragmentSelect.vue +1 -1
  22. package/src/fields/UISelect.vue +5 -5
  23. package/src/hooks/index.ts +2 -0
  24. package/src/hooks/use-code-block-edit.ts +1 -2
  25. package/src/hooks/use-editor-content-height.ts +20 -0
  26. package/src/hooks/use-float-box.ts +8 -8
  27. package/src/hooks/use-window-rect.ts +20 -0
  28. package/src/index.ts +2 -2
  29. package/src/layouts/Framework.vue +33 -34
  30. package/src/layouts/NavMenu.vue +21 -2
  31. package/src/layouts/PropsPanel.vue +35 -0
  32. package/src/layouts/sidebar/Sidebar.vue +18 -8
  33. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -1
  34. package/src/layouts/workspace/viewer/NodeListMenu.vue +1 -0
  35. package/src/services/BaseService.ts +5 -2
  36. package/src/services/codeBlock.ts +14 -8
  37. package/src/services/dataSource.ts +39 -26
  38. package/src/services/editor.ts +46 -25
  39. package/src/services/events.ts +4 -4
  40. package/src/services/props.ts +44 -35
  41. package/src/services/stageOverlay.ts +16 -9
  42. package/src/services/storage.ts +14 -8
  43. package/src/services/ui.ts +26 -19
  44. package/src/theme/code-block.scss +0 -5
  45. package/src/theme/code-editor.scss +6 -0
  46. package/src/theme/floating-box.scss +4 -2
  47. package/src/theme/props-panel.scss +14 -0
  48. package/src/theme/sidebar.scss +6 -3
  49. package/src/type.ts +87 -37
  50. package/src/utils/operator.ts +37 -39
  51. package/src/utils/props.ts +174 -37
  52. package/types/components/CodeBlockEditor.vue.d.ts +46 -25
  53. package/types/components/CodeParams.vue.d.ts +5 -5
  54. package/types/components/ContentMenu.vue.d.ts +12 -12
  55. package/types/components/FloatingBox.vue.d.ts +42 -55
  56. package/types/components/Icon.vue.d.ts +3 -3
  57. package/types/components/Resizer.vue.d.ts +3 -3
  58. package/types/components/ScrollBar.vue.d.ts +3 -3
  59. package/types/components/ScrollViewer.vue.d.ts +12 -12
  60. package/types/components/SearchInput.vue.d.ts +1 -1
  61. package/types/components/SplitView.vue.d.ts +13 -11
  62. package/types/components/ToolButton.vue.d.ts +13 -13
  63. package/types/components/Tree.vue.d.ts +24 -14
  64. package/types/components/TreeNode.vue.d.ts +22 -12
  65. package/types/fields/Code.vue.d.ts +14 -14
  66. package/types/fields/CodeLink.vue.d.ts +6 -10
  67. package/types/fields/CodeSelect.vue.d.ts +14 -14
  68. package/types/fields/CodeSelectCol.vue.d.ts +11 -11
  69. package/types/fields/DataSourceFieldSelect.vue.d.ts +11 -11
  70. package/types/fields/DataSourceFields.vue.d.ts +11 -11
  71. package/types/fields/DataSourceInput.vue.d.ts +14 -18
  72. package/types/fields/DataSourceMethodSelect.vue.d.ts +11 -11
  73. package/types/fields/DataSourceMethods.vue.d.ts +11 -11
  74. package/types/fields/DataSourceMocks.vue.d.ts +11 -11
  75. package/types/fields/DataSourceSelect.vue.d.ts +13 -26
  76. package/types/fields/EventSelect.vue.d.ts +3 -3
  77. package/types/fields/KeyValue.vue.d.ts +14 -18
  78. package/types/fields/PageFragmentSelect.vue.d.ts +11 -11
  79. package/types/fields/UISelect.vue.d.ts +8 -4
  80. package/types/hooks/index.d.ts +2 -0
  81. package/types/hooks/use-code-block-edit.d.ts +66 -90
  82. package/types/hooks/use-data-source-method.d.ts +66 -90
  83. package/types/hooks/use-editor-content-height.d.ts +3 -0
  84. package/types/hooks/use-node-status.d.ts +6 -1
  85. package/types/hooks/use-window-rect.d.ts +6 -0
  86. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  87. package/types/icons/CenterIcon.vue.d.ts +1 -1
  88. package/types/icons/CodeIcon.vue.d.ts +1 -1
  89. package/types/icons/FolderMinusIcon.vue.d.ts +1 -1
  90. package/types/icons/PinIcon.vue.d.ts +1 -1
  91. package/types/icons/PinnedIcon.vue.d.ts +1 -1
  92. package/types/layouts/AddPageBox.vue.d.ts +3 -3
  93. package/types/layouts/CodeEditor.vue.d.ts +12 -12
  94. package/types/layouts/Framework.vue.d.ts +9 -9
  95. package/types/layouts/NavMenu.vue.d.ts +11 -11
  96. package/types/layouts/PropsPanel.vue.d.ts +193 -243
  97. package/types/layouts/page-bar/AddButton.vue.d.ts +3 -3
  98. package/types/layouts/page-bar/PageBar.vue.d.ts +8 -8
  99. package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +8 -8
  100. package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +3 -3
  101. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -1
  102. package/types/layouts/sidebar/Sidebar.vue.d.ts +13 -13
  103. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +10 -10
  104. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +9 -9
  105. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -3
  106. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +3 -3
  107. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +9 -9
  108. package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +11 -11
  109. package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +3 -3
  110. package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +9 -9
  111. package/types/layouts/sidebar/layer/use-click.d.ts +42 -76
  112. package/types/layouts/sidebar/layer/use-node-status.d.ts +6 -1
  113. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  114. package/types/layouts/workspace/Workspace.vue.d.ts +12 -12
  115. package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +1 -1
  116. package/types/layouts/workspace/viewer/Stage.vue.d.ts +11 -11
  117. package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +1 -1
  118. package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +12 -12
  119. package/types/services/BaseService.d.ts +5 -2
  120. package/types/services/codeBlock.d.ts +8 -0
  121. package/types/services/dataSource.d.ts +9 -2
  122. package/types/services/editor.d.ts +8 -1
  123. package/types/services/props.d.ts +15 -22
  124. package/types/services/stageOverlay.d.ts +9 -2
  125. package/types/services/storage.d.ts +8 -0
  126. package/types/services/ui.d.ts +20 -8
  127. package/types/type.d.ts +56 -32
  128. package/types/utils/operator.d.ts +1 -1
  129. package/types/utils/props.d.ts +2 -13
@@ -18,6 +18,7 @@
18
18
 
19
19
  import { reactive } from 'vue';
20
20
  import { cloneDeep, mergeWith } from 'lodash-es';
21
+ import { Writable } from 'type-fest';
21
22
 
22
23
  import { DepTargetType } from '@tmagic/dep';
23
24
  import type { FormConfig } from '@tmagic/form';
@@ -26,11 +27,26 @@ import { getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/util
26
27
 
27
28
  import depService from '@editor/services/dep';
28
29
  import editorService from '@editor/services/editor';
29
- import type { PropsState } from '@editor/type';
30
+ import type { AsyncHookPlugin, PropsState, SyncHookPlugin } from '@editor/type';
30
31
  import { fillConfig } from '@editor/utils/props';
31
32
 
32
33
  import BaseService from './BaseService';
33
34
 
35
+ const canUsePluginMethods = {
36
+ async: [
37
+ 'setPropsConfig',
38
+ 'getPropsConfig',
39
+ 'setPropsValue',
40
+ 'getPropsValue',
41
+ 'fillConfig',
42
+ 'getDefaultPropsValue',
43
+ ] as const,
44
+ sync: ['createId', 'setNewItemId'] as const,
45
+ };
46
+
47
+ type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
48
+ type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
49
+
34
50
  class Props extends BaseService {
35
51
  private state = reactive<PropsState>({
36
52
  propsConfigMap: {},
@@ -40,14 +56,8 @@ class Props extends BaseService {
40
56
 
41
57
  constructor() {
42
58
  super([
43
- { name: 'setPropsConfig', isAsync: true },
44
- { name: 'getPropsConfig', isAsync: true },
45
- { name: 'setPropsValue', isAsync: true },
46
- { name: 'getPropsValue', isAsync: true },
47
- { name: 'createId', isAsync: false },
48
- { name: 'setNewItemId', isAsync: true },
49
- { name: 'fillConfig', isAsync: true },
50
- { name: 'getDefaultPropsValue', isAsync: true },
59
+ ...canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })),
60
+ ...canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })),
51
61
  ]);
52
62
  }
53
63
 
@@ -58,17 +68,12 @@ class Props extends BaseService {
58
68
  this.emit('props-configs-change');
59
69
  }
60
70
 
61
- public async fillConfig(config: FormConfig) {
62
- return fillConfig(config);
71
+ public async fillConfig(config: FormConfig, labelWidth?: string) {
72
+ return fillConfig(config, typeof labelWidth !== 'function' ? labelWidth : '80px');
63
73
  }
64
74
 
65
- /**
66
- * 为指定类型组件设置组件属性表单配置
67
- * @param type 组件类型
68
- * @param config 组件属性表单配置
69
- */
70
75
  public async setPropsConfig(type: string, config: FormConfig) {
71
- this.state.propsConfigMap[type] = await this.fillConfig(Array.isArray(config) ? config : [config]);
76
+ this.state.propsConfigMap[toLine(type)] = await this.fillConfig(Array.isArray(config) ? config : [config]);
72
77
  }
73
78
 
74
79
  /**
@@ -81,7 +86,7 @@ class Props extends BaseService {
81
86
  return await this.getPropsConfig('button');
82
87
  }
83
88
 
84
- return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([])));
89
+ return cloneDeep(this.state.propsConfigMap[toLine(type)] || (await this.fillConfig([])));
85
90
  }
86
91
 
87
92
  public setPropsValues(values: Record<string, Partial<MNode>>) {
@@ -96,7 +101,7 @@ class Props extends BaseService {
96
101
  * @param value 组件初始值
97
102
  */
98
103
  public async setPropsValue(type: string, value: Partial<MNode>) {
99
- this.state.propsValueMap[type] = value;
104
+ this.state.propsValueMap[toLine(type)] = value;
100
105
  }
101
106
 
102
107
  /**
@@ -104,7 +109,9 @@ class Props extends BaseService {
104
109
  * @param type 组件类型
105
110
  * @returns 组件初始值
106
111
  */
107
- public async getPropsValue(type: string, { inputEvent, ...defaultValue }: Record<string, any> = {}) {
112
+ public async getPropsValue(componentType: string, { inputEvent, ...defaultValue }: Record<string, any> = {}) {
113
+ const type = toLine(componentType);
114
+
108
115
  if (type === 'area') {
109
116
  const value = (await this.getPropsValue('button')) as MComponent;
110
117
  value.className = 'action-area';
@@ -115,16 +122,14 @@ class Props extends BaseService {
115
122
  return value;
116
123
  }
117
124
 
118
- const [id, defaultPropsValue, data] = await Promise.all([
119
- this.createId(type),
120
- this.getDefaultPropsValue(type),
121
- this.setNewItemId(
122
- cloneDeep({
123
- type,
124
- ...defaultValue,
125
- } as any),
126
- ),
127
- ]);
125
+ const id = this.createId(type);
126
+ const defaultPropsValue = this.getDefaultPropsValue(type);
127
+ const data = this.setNewItemId(
128
+ cloneDeep({
129
+ type,
130
+ ...defaultValue,
131
+ } as any),
132
+ );
128
133
 
129
134
  return {
130
135
  id,
@@ -133,7 +138,7 @@ class Props extends BaseService {
133
138
  };
134
139
  }
135
140
 
136
- public async createId(type: string | number): Promise<string> {
141
+ public createId(type: string | number): string {
137
142
  return `${type}_${guid()}`;
138
143
  }
139
144
 
@@ -144,16 +149,16 @@ class Props extends BaseService {
144
149
  * @param {Boolean} force 是否强制设置新的ID
145
150
  */
146
151
  /* eslint no-param-reassign: ["error", { "props": false }] */
147
- public async setNewItemId(config: MNode, force = true) {
152
+ public setNewItemId(config: MNode, force = true) {
148
153
  if (force || editorService.getNodeById(config.id)) {
149
- const newId = await this.createId(config.type || 'component');
154
+ const newId = this.createId(config.type || 'component');
150
155
  this.setRelateId(config.id, newId);
151
156
  config.id = newId;
152
157
  }
153
158
 
154
159
  if (config.items && Array.isArray(config.items)) {
155
160
  for (const item of config.items) {
156
- await this.setNewItemId(item);
161
+ this.setNewItemId(item);
157
162
  }
158
163
  }
159
164
 
@@ -165,7 +170,7 @@ class Props extends BaseService {
165
170
  * @param type 组件类型
166
171
  * @returns Object
167
172
  */
168
- public async getDefaultPropsValue(type: string) {
173
+ public getDefaultPropsValue(type: string) {
169
174
  return ['page', 'container'].includes(type)
170
175
  ? {
171
176
  type,
@@ -227,6 +232,10 @@ class Props extends BaseService {
227
232
  this.removeAllPlugins();
228
233
  }
229
234
 
235
+ public usePlugin(options: AsyncHookPlugin<AsyncMethodName, Props> & SyncHookPlugin<SyncMethodName, Props>): void {
236
+ super.usePlugin(options);
237
+ }
238
+
230
239
  /**
231
240
  * 获取setNewItemId前后映射关系
232
241
  * @param oldId 原组件ID
@@ -1,11 +1,19 @@
1
1
  import { reactive } from 'vue';
2
+ import type { Writable } from 'type-fest';
2
3
 
3
4
  import StageCore from '@tmagic/stage';
4
5
 
5
6
  import { useStage } from '@editor/hooks/use-stage';
6
7
  import BaseService from '@editor/services//BaseService';
7
8
  import editorService from '@editor/services//editor';
8
- import type { StageOptions, StageOverlayState } from '@editor/type';
9
+ import type { StageOptions, StageOverlayState, SyncHookPlugin } from '@editor/type';
10
+
11
+ const canUsePluginMethods = {
12
+ async: [],
13
+ sync: ['openOverlay', 'closeOverlay', 'updateOverlay', 'createStage'] as const,
14
+ };
15
+
16
+ type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
9
17
 
10
18
  class StageOverlay extends BaseService {
11
19
  private state: StageOverlayState = reactive({
@@ -20,12 +28,7 @@ class StageOverlay extends BaseService {
20
28
  });
21
29
 
22
30
  constructor() {
23
- super([
24
- { name: 'openOverlay', isAsync: false },
25
- { name: 'closeOverlay', isAsync: false },
26
- { name: 'updateOverlay', isAsync: false },
27
- { name: 'createStage', isAsync: false },
28
- ]);
31
+ super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
29
32
 
30
33
  this.get('wrapDiv').classList.add('tmagic-editor-sub-stage-wrap');
31
34
  }
@@ -38,7 +41,7 @@ class StageOverlay extends BaseService {
38
41
  this.state[name] = value;
39
42
  }
40
43
 
41
- public openOverlay(el: HTMLElement | undefined | null) {
44
+ public openOverlay(el: HTMLElement | null) {
42
45
  const stageOptions = this.get('stageOptions');
43
46
  if (!el || !stageOptions) return;
44
47
 
@@ -111,6 +114,10 @@ class StageOverlay extends BaseService {
111
114
  });
112
115
  }
113
116
 
117
+ public usePlugin(options: SyncHookPlugin<SyncMethodName, StageOverlay>): void {
118
+ super.usePlugin(options);
119
+ }
120
+
114
121
  private createContentEl() {
115
122
  const sourceEl = this.get('sourceEl');
116
123
  if (!sourceEl) return;
@@ -161,7 +168,7 @@ class StageOverlay extends BaseService {
161
168
  });
162
169
 
163
170
  if (await stageOptions?.canSelect?.(contentEl)) {
164
- subStage?.select(contentEl);
171
+ subStage?.select(contentEl.id);
165
172
  }
166
173
  }
167
174
 
@@ -1,5 +1,7 @@
1
1
  import serialize from 'serialize-javascript';
2
+ import type { Writable } from 'type-fest';
2
3
 
4
+ import type { SyncHookPlugin } from '@editor/type';
3
5
  import { getConfig } from '@editor/utils/config';
4
6
 
5
7
  import BaseService from './BaseService';
@@ -17,6 +19,13 @@ export enum Protocol {
17
19
  BOOLEAN = 'boolean',
18
20
  }
19
21
 
22
+ const canUsePluginMethods = {
23
+ async: [],
24
+ sync: ['getStorage', 'getNamespace', 'clear', 'getItem', 'removeItem', 'setItem'] as const,
25
+ };
26
+
27
+ type SyncMethodName = Writable<(typeof canUsePluginMethods)['sync']>;
28
+
20
29
  /**
21
30
  * 数据存储服务
22
31
  */
@@ -25,14 +34,7 @@ export class WebStorage extends BaseService {
25
34
  private namespace = 'tmagic';
26
35
 
27
36
  constructor() {
28
- super([
29
- { name: 'getStorage', isAsync: false },
30
- { name: 'getNamespace', isAsync: false },
31
- { name: 'clear', isAsync: false },
32
- { name: 'getItem', isAsync: false },
33
- { name: 'removeItem', isAsync: false },
34
- { name: 'setItem', isAsync: false },
35
- ]);
37
+ super(canUsePluginMethods.sync.map((methodName) => ({ name: methodName, isAsync: false })));
36
38
  }
37
39
 
38
40
  /**
@@ -123,6 +125,10 @@ export class WebStorage extends BaseService {
123
125
  this.removeAllPlugins();
124
126
  }
125
127
 
128
+ public usePlugin(options: SyncHookPlugin<SyncMethodName, WebStorage>): void {
129
+ super.usePlugin(options);
130
+ }
131
+
126
132
  private getValueAndProtocol(value: string | null) {
127
133
  let protocol = '';
128
134
 
@@ -17,11 +17,12 @@
17
17
  */
18
18
 
19
19
  import { reactive } from 'vue';
20
+ import type { Writable } from 'type-fest';
20
21
 
21
22
  import { convertToNumber } from '@tmagic/utils';
22
23
 
23
24
  import editorService from '@editor/services/editor';
24
- import type { StageRect, UiState } from '@editor/type';
25
+ import type { AsyncHookPlugin, StageRect, UiState } from '@editor/type';
25
26
 
26
27
  import BaseService from './BaseService';
27
28
 
@@ -46,16 +47,31 @@ const state = reactive<UiState>({
46
47
  showRule: true,
47
48
  propsPanelSize: 'small',
48
49
  showAddPageButton: true,
49
- floatBox: new Map(),
50
50
  hideSlideBar: false,
51
+ navMenuRect: {
52
+ left: 0,
53
+ top: 0,
54
+ width: 0,
55
+ height: 0,
56
+ },
57
+ frameworkRect: {
58
+ width: 0,
59
+ height: 0,
60
+ left: 0,
61
+ top: 0,
62
+ },
51
63
  });
52
64
 
65
+ const canUsePluginMethods = {
66
+ async: ['zoom', 'calcZoom'] as const,
67
+ sync: [] as const,
68
+ };
69
+
70
+ type AsyncMethodName = Writable<(typeof canUsePluginMethods)['async']>;
71
+
53
72
  class Ui extends BaseService {
54
73
  constructor() {
55
- super([
56
- { name: 'zoom', isAsync: true },
57
- { name: 'calcZoom', isAsync: true },
58
- ]);
74
+ super(canUsePluginMethods.async.map((methodName) => ({ name: methodName, isAsync: true })));
59
75
  }
60
76
 
61
77
  public set<K extends keyof UiState, T extends UiState[K]>(name: K, value: T) {
@@ -105,19 +121,6 @@ class Ui extends BaseService {
105
121
  return Math.min((width - 60) / stageWidth || 1, (height - 80) / stageHeight || 1);
106
122
  }
107
123
 
108
- public async setFloatBox(keys: string[]) {
109
- const map = state.floatBox;
110
- for (const key of keys) {
111
- if (map.get(key)) continue;
112
- map.set(key, {
113
- status: false,
114
- zIndex: 99,
115
- top: 0,
116
- left: 0,
117
- });
118
- }
119
- }
120
-
121
124
  public resetState() {
122
125
  this.set('showSrc', false);
123
126
  this.set('uiSelectMode', false);
@@ -134,6 +137,10 @@ class Ui extends BaseService {
134
137
  this.removeAllPlugins();
135
138
  }
136
139
 
140
+ public usePlugin(options: AsyncHookPlugin<AsyncMethodName, Ui>): void {
141
+ super.usePlugin(options);
142
+ }
143
+
137
144
  private async setStageRect(value: StageRect) {
138
145
  state.stageRect = {
139
146
  ...state.stageRect,
@@ -17,9 +17,4 @@
17
17
  .el-drawer__body {
18
18
  padding: 10px 20px;
19
19
  }
20
-
21
- &.m-form-box {
22
- width: 100%;
23
- min-width: 872px;
24
- }
25
20
  }
@@ -1,3 +1,9 @@
1
+ .m-container-vs-code {
2
+ .el-form-item {
3
+ margin-bottom: 0;
4
+ }
5
+ }
6
+
1
7
  .magic-code-editor {
2
8
  width: 100%;
3
9
  }
@@ -5,6 +5,8 @@
5
5
  border: 1px solid $--border-color;
6
6
  display: flex;
7
7
  flex-direction: column;
8
+ max-height: 100%;
9
+ max-width: 100%;
8
10
 
9
11
  .m-editor-float-box-title {
10
12
  text-align: center;
@@ -19,9 +21,9 @@
19
21
  }
20
22
 
21
23
  .m-editor-float-box-body {
22
- padding: 5px;
23
- flex: 1;
24
24
  overflow: auto;
25
+ flex: 1;
26
+ padding: 0 16px;
25
27
  }
26
28
  }
27
29
 
@@ -1,6 +1,20 @@
1
1
  .m-editor-props-panel {
2
2
  padding: 0 10px;
3
3
 
4
+ .m-editor-props-panel-src-icon {
5
+ position: absolute;
6
+ right: 15px;
7
+ bottom: 15px;
8
+ z-index: 30;
9
+ }
10
+
11
+ .magic-code-editor {
12
+ position: absolute;
13
+ left: 0;
14
+ top: 0;
15
+ z-index: 10;
16
+ }
17
+
4
18
  &.small {
5
19
  .el-form-item__label {
6
20
  font-size: 12px;
@@ -72,12 +72,15 @@
72
72
  }
73
73
 
74
74
  .m-editor-slide-list-box {
75
- min-width: 270px;
75
+ display: flex;
76
+ min-width: 240px;
76
77
  min-height: 500px;
77
- max-height: 1024px;
78
78
  > div {
79
79
  &:first-child {
80
- width: 100%;
80
+ min-width: 240px;
81
81
  }
82
82
  }
83
+ .m-form-box {
84
+ border-left: 1px solid #e0e0e0;
85
+ }
83
86
  }
package/src/type.ts CHANGED
@@ -17,9 +17,20 @@
17
17
  */
18
18
 
19
19
  import type { Component } from 'vue';
20
+ import type { PascalCasedProperties } from 'type-fest';
20
21
 
21
- import type { ColumnConfig, FilterFunction, FormConfig, FormItem } from '@tmagic/form';
22
- import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
22
+ import type { ChildConfig, ColumnConfig, FilterFunction, FormConfig, FormItem, Input } from '@tmagic/form';
23
+ import type {
24
+ CodeBlockContent,
25
+ CodeBlockDSL,
26
+ DataSourceFieldType,
27
+ Id,
28
+ MApp,
29
+ MContainer,
30
+ MNode,
31
+ MPage,
32
+ MPageFragment,
33
+ } from '@tmagic/schema';
23
34
  import type StageCore from '@tmagic/stage';
24
35
  import type {
25
36
  ContainerHighlightType,
@@ -225,20 +236,22 @@ export interface UiState {
225
236
  propsPanelSize: 'large' | 'default' | 'small';
226
237
  /** 是否显示新增页面按钮 */
227
238
  showAddPageButton: boolean;
228
-
229
- /** slide 拖拽悬浮窗 state */
230
- floatBox: Map<
231
- string,
232
- {
233
- status: boolean;
234
- zIndex: number;
235
- top: number;
236
- left: number;
237
- }
238
- >;
239
-
240
239
  /** 是否隐藏侧边栏 */
241
240
  hideSlideBar: boolean;
241
+
242
+ // navMenu 的宽高
243
+ navMenuRect: {
244
+ left: number;
245
+ top: number;
246
+ width: number;
247
+ height: number;
248
+ };
249
+ frameworkRect: {
250
+ left: number;
251
+ top: number;
252
+ width: number;
253
+ height: number;
254
+ };
242
255
  }
243
256
 
244
257
  export interface EditorNodeInfo {
@@ -595,42 +608,44 @@ export interface KeyBindingCacheItem {
595
608
  bound: boolean;
596
609
  }
597
610
 
598
- export interface CodeSelectColConfig {
611
+ export interface CodeSelectColConfig extends FormItem {
599
612
  type: 'code-select-col';
600
- name: string;
601
- text: string;
602
- labelWidth?: number | string;
603
- disabled?: boolean | FilterFunction;
613
+ /** 是否可以编辑代码块,disable表示的是是否可以选择代码块 */
604
614
  notEditable?: boolean | FilterFunction;
605
- display?: boolean | FilterFunction;
606
615
  }
607
616
 
608
- export interface PageFragmentSelectConfig {
617
+ export interface PageFragmentSelectConfig extends FormItem {
609
618
  type: 'page-fragment-select';
610
- name: string;
611
- text: string;
612
- labelWidth?: number | string;
613
- disabled?: boolean | FilterFunction;
614
- display?: boolean | FilterFunction;
615
619
  }
616
620
 
617
- export interface DataSourceMethodSelectConfig {
621
+ export interface DataSourceSelect extends FormItem, Input {
622
+ type: 'data-source-select';
623
+ /** 数据源类型: base、http... */
624
+ dataSourceType?: string;
625
+ /** 是否要编译成数据源的data。
626
+ * id: 不编译,就是要数据源id;
627
+ * value: 要编译(数据源data)
628
+ * */
629
+ value?: 'id' | 'value';
630
+ }
631
+
632
+ export interface DataSourceMethodSelectConfig extends FormItem {
618
633
  type: 'data-source-method-select';
619
- name: string;
620
- text: string;
621
- labelWidth?: number | string;
622
- disabled?: boolean | FilterFunction;
634
+ /** 是否可以编辑数据源,disable表示的是是否可以选择数据源 */
623
635
  notEditable?: boolean | FilterFunction;
624
- display?: boolean | FilterFunction;
625
636
  }
626
637
 
627
- export interface DataSourceFieldSelectConfig {
638
+ export interface DataSourceFieldSelectConfig extends FormItem {
628
639
  type: 'data-source-field-select';
629
- name: string;
640
+ /** 是否要编译成数据源的data。
641
+ * key: 不编译,就是要数据源id和field name;
642
+ * value: 要编译(数据源data[`${filed}`])
643
+ * */
630
644
  value?: 'key' | 'value';
631
- labelWidth?: number | string;
632
- disabled?: boolean | FilterFunction;
633
- display?: boolean | FilterFunction;
645
+ /** 是否严格的遵守父子节点不互相关联 */
646
+ checkStrictly?: boolean;
647
+ dataSourceFieldType?: DataSourceFieldType[];
648
+ fieldConfig?: ChildConfig;
634
649
  }
635
650
 
636
651
  /** 可新增的数据源类型选项 */
@@ -670,3 +685,38 @@ export interface TreeNodeData {
670
685
  items?: TreeNodeData[];
671
686
  [key: string]: any;
672
687
  }
688
+
689
+ export type AsyncBeforeHook<Value extends Array<string>, C extends Record<Value[number], (...args: any) => any>> = {
690
+ [K in Value[number]]?: (...args: Parameters<C[K]>) => Promise<Parameters<C[K]>> | Parameters<C[K]>;
691
+ };
692
+
693
+ export type AsyncAfterHook<Value extends Array<string>, C extends Record<Value[number], (...args: any) => any>> = {
694
+ [K in Value[number]]?: (
695
+ result: Awaited<ReturnType<C[K]>>,
696
+ ...args: Parameters<C[K]>
697
+ ) => ReturnType<C[K]> | Awaited<ReturnType<C[K]>>;
698
+ };
699
+
700
+ export type SyncBeforeHook<Value extends Array<string>, C extends Record<Value[number], (...args: any) => any>> = {
701
+ [K in Value[number]]?: (...args: Parameters<C[K]>) => Parameters<C[K]>;
702
+ };
703
+
704
+ export type SyncAfterHook<Value extends Array<string>, C extends Record<Value[number], (...args: any) => any>> = {
705
+ [K in Value[number]]?: (result: ReturnType<C[K]>, ...args: Parameters<C[K]>) => ReturnType<C[K]>;
706
+ };
707
+
708
+ export type AddPrefixToObject<T, P extends string> = {
709
+ [K in keyof T as K extends string ? `${P}${K}` : never]: T[K];
710
+ };
711
+
712
+ export type AsyncHookPlugin<
713
+ T extends Array<string>,
714
+ C extends Record<T[number], (...args: any) => any>,
715
+ > = AddPrefixToObject<PascalCasedProperties<AsyncBeforeHook<T, C>>, 'before'> &
716
+ AddPrefixToObject<PascalCasedProperties<AsyncAfterHook<T, C>>, 'after'>;
717
+
718
+ export type SyncHookPlugin<
719
+ T extends Array<string>,
720
+ C extends Record<T[number], (...args: any) => any>,
721
+ > = AddPrefixToObject<PascalCasedProperties<SyncBeforeHook<T, C>>, 'before'> &
722
+ AddPrefixToObject<PascalCasedProperties<SyncAfterHook<T, C>>, 'after'>;