@tmagic/editor 1.3.0-alpha.2 → 1.3.0-alpha.21

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 (167) hide show
  1. package/dist/style.css +91 -120
  2. package/dist/tmagic-editor.js +4609 -3257
  3. package/dist/tmagic-editor.js.map +1 -1
  4. package/dist/tmagic-editor.umd.cjs +5708 -4337
  5. package/dist/tmagic-editor.umd.cjs.map +1 -1
  6. package/package.json +21 -22
  7. package/src/Editor.vue +29 -7
  8. package/src/components/CodeBlockEditor.vue +170 -0
  9. package/src/components/CodeParams.vue +60 -0
  10. package/src/components/ContentMenu.vue +30 -11
  11. package/src/components/Icon.vue +5 -1
  12. package/src/components/Resizer.vue +45 -0
  13. package/src/components/ScrollBar.vue +5 -1
  14. package/src/components/ScrollViewer.vue +5 -1
  15. package/src/components/SearchInput.vue +4 -0
  16. package/src/components/{Layout.vue → SplitView.vue} +8 -4
  17. package/src/components/ToolButton.vue +5 -1
  18. package/src/editorProps.ts +35 -4
  19. package/src/fields/Code.vue +28 -20
  20. package/src/fields/CodeLink.vue +15 -10
  21. package/src/fields/CodeSelect.vue +19 -10
  22. package/src/fields/CodeSelectCol.vue +67 -83
  23. package/src/fields/DataSourceFieldSelect.vue +47 -0
  24. package/src/fields/DataSourceFields.vue +24 -21
  25. package/src/fields/DataSourceInput.vue +318 -0
  26. package/src/fields/DataSourceMethodSelect.vue +136 -0
  27. package/src/fields/DataSourceMethods.vue +103 -0
  28. package/src/fields/DataSourceSelect.vue +68 -0
  29. package/src/fields/EventSelect.vue +62 -22
  30. package/src/fields/KeyValue.vue +13 -11
  31. package/src/fields/UISelect.vue +59 -15
  32. package/src/hooks/index.ts +21 -0
  33. package/src/hooks/use-code-block-edit.ts +84 -0
  34. package/src/hooks/use-data-source-method.ts +100 -0
  35. package/src/{utils/stage.ts → hooks/use-stage.ts} +4 -7
  36. package/src/icons/AppManageIcon.vue +5 -1
  37. package/src/icons/CenterIcon.vue +13 -0
  38. package/src/icons/CodeIcon.vue +5 -3
  39. package/src/index.ts +24 -3
  40. package/src/initService.ts +75 -16
  41. package/src/layouts/AddPageBox.vue +5 -1
  42. package/src/layouts/CodeEditor.vue +66 -11
  43. package/src/layouts/Framework.vue +32 -28
  44. package/src/layouts/NavMenu.vue +5 -1
  45. package/src/layouts/PropsPanel.vue +14 -4
  46. package/src/layouts/sidebar/ComponentListPanel.vue +11 -10
  47. package/src/layouts/sidebar/LayerMenu.vue +13 -25
  48. package/src/layouts/sidebar/LayerNode.vue +40 -0
  49. package/src/layouts/sidebar/LayerPanel.vue +71 -28
  50. package/src/layouts/sidebar/Sidebar.vue +13 -17
  51. package/src/layouts/sidebar/code-block/CodeBlockList.vue +84 -118
  52. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +63 -0
  53. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +39 -34
  54. package/src/layouts/sidebar/data-source/DataSourceList.vue +145 -0
  55. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +17 -65
  56. package/src/layouts/workspace/Breadcrumb.vue +5 -1
  57. package/src/layouts/workspace/PageBar.vue +5 -1
  58. package/src/layouts/workspace/PageBarScrollContainer.vue +5 -1
  59. package/src/layouts/workspace/Stage.vue +30 -8
  60. package/src/layouts/workspace/ViewerMenu.vue +15 -36
  61. package/src/layouts/workspace/Workspace.vue +9 -134
  62. package/src/services/codeBlock.ts +20 -72
  63. package/src/services/dataSource.ts +17 -2
  64. package/src/services/dep.ts +23 -20
  65. package/src/services/editor.ts +3 -3
  66. package/src/services/keybinding.ts +185 -0
  67. package/src/services/props.ts +2 -2
  68. package/src/services/storage.ts +3 -2
  69. package/src/theme/code-block.scss +5 -117
  70. package/src/theme/code-editor.scss +27 -2
  71. package/src/theme/content-menu.scss +1 -1
  72. package/src/theme/data-source-input.scss +18 -0
  73. package/src/theme/data-source-methods.scss +13 -0
  74. package/src/theme/event.scss +15 -12
  75. package/src/theme/framework.scss +0 -3
  76. package/src/theme/layer-panel.scss +6 -0
  77. package/src/theme/layout.scss +4 -0
  78. package/src/theme/resizer.scss +25 -10
  79. package/src/theme/stage.scss +4 -0
  80. package/src/theme/theme.scss +2 -0
  81. package/src/type.ts +105 -7
  82. package/src/utils/config.ts +1 -1
  83. package/src/utils/content-menu.ts +92 -0
  84. package/src/utils/data-source/formConfigs/base.ts +35 -30
  85. package/src/utils/data-source/index.ts +75 -6
  86. package/src/utils/dep.ts +39 -7
  87. package/src/utils/index.ts +1 -1
  88. package/src/utils/keybinding-config.ts +120 -0
  89. package/src/utils/props.ts +298 -155
  90. package/src/utils/undo-redo.ts +1 -1
  91. package/types/Editor.vue.d.ts +37 -4
  92. package/types/components/CodeBlockEditor.vue.d.ts +23 -0
  93. package/types/components/CodeParams.vue.d.ts +26 -0
  94. package/types/components/ContentMenu.vue.d.ts +8 -3
  95. package/types/components/Icon.vue.d.ts +2 -2
  96. package/types/{layouts → components}/Resizer.vue.d.ts +2 -2
  97. package/types/components/ScrollBar.vue.d.ts +1 -1
  98. package/types/components/ScrollViewer.vue.d.ts +8 -5
  99. package/types/components/SearchInput.vue.d.ts +1 -1
  100. package/types/components/{Layout.vue.d.ts → SplitView.vue.d.ts} +9 -6
  101. package/types/components/ToolButton.vue.d.ts +10 -7
  102. package/types/editorProps.d.ts +23 -4
  103. package/types/fields/Code.vue.d.ts +23 -18
  104. package/types/fields/CodeLink.vue.d.ts +13 -22
  105. package/types/fields/CodeSelect.vue.d.ts +12 -20
  106. package/types/fields/CodeSelectCol.vue.d.ts +14 -15
  107. package/types/fields/DataSourceFieldSelect.vue.d.ts +29 -0
  108. package/types/fields/DataSourceFields.vue.d.ts +13 -21
  109. package/types/fields/DataSourceInput.vue.d.ts +34 -0
  110. package/types/fields/DataSourceMethodSelect.vue.d.ts +29 -0
  111. package/types/fields/DataSourceMethods.vue.d.ts +32 -0
  112. package/types/fields/DataSourceSelect.vue.d.ts +40 -0
  113. package/types/fields/EventSelect.vue.d.ts +3 -14
  114. package/types/fields/KeyValue.vue.d.ts +15 -27
  115. package/types/fields/UISelect.vue.d.ts +3 -12
  116. package/types/hooks/index.d.ts +3 -0
  117. package/types/hooks/use-code-block-edit.d.ts +125 -0
  118. package/types/hooks/use-data-source-method.d.ts +123 -0
  119. package/types/icons/AppManageIcon.vue.d.ts +1 -1
  120. package/types/icons/CenterIcon.vue.d.ts +2 -0
  121. package/types/icons/CodeIcon.vue.d.ts +1 -1
  122. package/types/index.d.ts +12 -2
  123. package/types/initService.d.ts +2 -2
  124. package/types/layouts/AddPageBox.vue.d.ts +1 -1
  125. package/types/layouts/CodeEditor.vue.d.ts +18 -10
  126. package/types/layouts/Framework.vue.d.ts +11 -32
  127. package/types/layouts/NavMenu.vue.d.ts +7 -4
  128. package/types/layouts/PropsPanel.vue.d.ts +276 -4
  129. package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +4 -4
  130. package/types/layouts/sidebar/LayerMenu.vue.d.ts +2 -2
  131. package/types/layouts/sidebar/LayerNode.vue.d.ts +16 -0
  132. package/types/layouts/sidebar/LayerPanel.vue.d.ts +5 -5
  133. package/types/layouts/sidebar/Sidebar.vue.d.ts +16 -16
  134. package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +7 -12
  135. package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +28 -0
  136. package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +4 -2
  137. package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +14 -0
  138. package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +1 -11
  139. package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
  140. package/types/layouts/workspace/PageBar.vue.d.ts +5 -5
  141. package/types/layouts/workspace/PageBarScrollContainer.vue.d.ts +2 -2
  142. package/types/layouts/workspace/Stage.vue.d.ts +2 -2
  143. package/types/layouts/workspace/ViewerMenu.vue.d.ts +7 -4
  144. package/types/layouts/workspace/Workspace.vue.d.ts +9 -9
  145. package/types/services/codeBlock.d.ts +6 -37
  146. package/types/services/dataSource.d.ts +7 -1
  147. package/types/services/dep.d.ts +12 -21
  148. package/types/services/editor.d.ts +1 -1
  149. package/types/services/keybinding.d.ts +20 -0
  150. package/types/services/props.d.ts +10 -115
  151. package/types/type.d.ts +97 -7
  152. package/types/utils/config.d.ts +1 -1
  153. package/types/utils/content-menu.d.ts +7 -0
  154. package/types/utils/data-source/formConfigs/base.d.ts +2 -2
  155. package/types/utils/data-source/index.d.ts +7 -1
  156. package/types/utils/dep.d.ts +4 -2
  157. package/types/utils/index.d.ts +1 -1
  158. package/types/utils/keybinding-config.d.ts +3 -0
  159. package/types/utils/props.d.ts +13 -102
  160. package/src/components/CodeDraftEditor.vue +0 -144
  161. package/src/components/FunctionEditor.vue +0 -190
  162. package/src/layouts/Resizer.vue +0 -32
  163. package/src/layouts/sidebar/code-block/CodeBlockEditor.vue +0 -96
  164. package/types/components/CodeDraftEditor.vue.d.ts +0 -58
  165. package/types/components/FunctionEditor.vue.d.ts +0 -192
  166. package/types/layouts/sidebar/code-block/CodeBlockEditor.vue.d.ts +0 -25
  167. /package/types/{utils/stage.d.ts → hooks/use-stage.d.ts} +0 -0
@@ -80,7 +80,7 @@ class Props extends BaseService {
80
80
  return cloneDeep(this.state.propsConfigMap[type] || (await this.fillConfig([])));
81
81
  }
82
82
 
83
- public setPropsValues(values: Record<string, MNode>) {
83
+ public setPropsValues(values: Record<string, Partial<MNode>>) {
84
84
  Object.keys(values).forEach((type: string) => {
85
85
  this.setPropsValue(toLine(type), values[type]);
86
86
  });
@@ -91,7 +91,7 @@ class Props extends BaseService {
91
91
  * @param type 组件类型
92
92
  * @param value 组件初始值
93
93
  */
94
- public async setPropsValue(type: string, value: MNode) {
94
+ public async setPropsValue(type: string, value: Partial<MNode>) {
95
95
  this.state.propsValueMap[type] = value;
96
96
  }
97
97
 
@@ -1,5 +1,7 @@
1
1
  import serialize from 'serialize-javascript';
2
2
 
3
+ import { getConfig } from '@editor/utils/config';
4
+
3
5
  import BaseService from './BaseService';
4
6
 
5
7
  interface Options {
@@ -64,8 +66,7 @@ export class WebStorage extends BaseService {
64
66
 
65
67
  switch (protocol) {
66
68
  case Protocol.OBJECT:
67
- // eslint-disable-next-line no-eval
68
- return eval(`(${item})`);
69
+ return getConfig('parseDSL')(`(${item})`);
69
70
  case Protocol.JSON:
70
71
  return JSON.parse(item);
71
72
  case Protocol.NUMBER:
@@ -25,124 +25,12 @@
25
25
  }
26
26
  }
27
27
 
28
- .el-dialog.is-fullscreen.code-editor-dialog {
29
- overflow: hidden;
30
- }
31
-
32
- .code-editor-dialog {
33
- .tmagic-design-card {
34
- .t-card__header {
35
- display: block;
36
- }
37
- }
38
-
39
- .el-dialog__body,
40
- .t-dialog__body {
41
- height: 90%;
42
- padding-top: 10px;
43
- }
44
- .tmagic-design-card {
45
- height: 100%;
46
- background: #fff;
47
- .el-card__body,
48
- .t-card__body {
49
- height: 100%;
50
- background: #fff;
51
- }
52
- }
53
-
54
- .code-editor-layout {
55
- height: 100%;
56
- border: 1px solid #e4e7ed;
57
-
58
- .side-tree {
59
- height: 100%;
60
- overflow: auto;
61
- .el-tree-node__label {
62
- width: 100%;
63
- }
64
-
65
- .list-container {
66
- width: 100%;
67
- overflow: hidden;
68
- margin-left: -10px;
69
- .list-item {
70
- width: 100%;
71
- margin: 10px 0;
72
- line-height: 30px;
73
- .code-name {
74
- width: 100%;
75
- font-size: 14px;
76
- overflow: hidden;
77
- white-space: nowrap;
78
- text-overflow: ellipsis;
79
- }
80
- }
81
- }
82
- }
28
+ .m-editor-code-block-editor {
29
+ .tmagic-design-table {
30
+ height: 180px;
83
31
  }
84
32
 
85
- .code-name-wrapper {
86
- display: flex;
87
- align-items: center;
88
- font-size: 16px;
89
- margin-bottom: 10px;
90
- .code-name-label {
91
- margin-right: 10px;
92
- }
93
- .code-name-input {
94
- width: 300px;
95
- }
96
- }
97
-
98
- .m-editor-code-block-editor-panel-list-mode {
99
- height: 100%;
100
- z-index: 10;
101
- background: #fff;
102
- .el-card {
103
- border: 0;
104
- }
105
- }
106
-
107
- .m-editor-code-block-editor-panel {
108
- position: absolute;
109
- top: 0;
110
- left: 4px;
111
- width: calc(100% - 9px);
112
- height: 100%;
113
- z-index: 10;
114
- background: #fff;
115
- .el-card {
116
- border: 0;
117
- }
118
- }
119
-
120
- .m-editor-wrapper {
121
- height: 100%;
122
- &.fullScreen {
123
- height: 100%;
124
- width: 100%;
125
- position: fixed;
126
- top: 0;
127
- left: 0;
128
- z-index: 100;
129
- }
130
- .m-editor-container {
131
- height: calc(100% - 45px);
132
- }
133
- .m-editor-content-bottom {
134
- height: 45px;
135
- width: 100%;
136
- display: flex;
137
- justify-content: end;
138
- background: #fff;
139
- position: absolute;
140
- right: 20px;
141
- bottom: 0;
142
- > button {
143
- height: 30px;
144
- margin-top: 5px;
145
- }
146
- }
33
+ .el-drawer__body {
34
+ padding: 10px 20px;
147
35
  }
148
36
  }
@@ -1,7 +1,32 @@
1
1
  .magic-code-editor {
2
2
  width: 100%;
3
+ }
4
+
5
+ .magic-code-editor-wrapper {
6
+ width: 100%;
7
+ height: 100%;
8
+ position: relative;
9
+
10
+ &.full-screen {
11
+ position: fixed;
12
+ z-index: 10000;
13
+ top: 0;
14
+ left: 0;
15
+ }
16
+
17
+ .magic-code-editor-content {
18
+ width: 100%;
19
+ height: 100%;
20
+
21
+ .margin {
22
+ margin: 0;
23
+ }
24
+ }
3
25
 
4
- .margin {
5
- margin: 0;
26
+ .magic-code-editor-full-screen-icon {
27
+ position: absolute;
28
+ top: 5px;
29
+ right: 0;
30
+ z-index: 11;
6
31
  }
7
32
  }
@@ -8,7 +8,7 @@
8
8
  font-weight: 600;
9
9
  padding: 4px 0px;
10
10
  overflow: auto;
11
- max-height: 100%;
11
+ max-height: 80%;
12
12
 
13
13
  .menu-item {
14
14
  color: #333;
@@ -0,0 +1,18 @@
1
+ .tmagic-data-source-input-text {
2
+ .el-input__wrapper.tmagic-data-source-input-text-wrapper {
3
+ overflow: hidden;
4
+ padding-right: 30px;
5
+ }
6
+
7
+ .el-input__inner {
8
+ display: flex;
9
+ align-items: center;
10
+ overflow: hidden;
11
+ white-space: nowrap;
12
+ }
13
+
14
+ .tmagic-data-source-input-icon {
15
+ position: absolute;
16
+ right: 7px;
17
+ }
18
+ }
@@ -0,0 +1,13 @@
1
+ .m-editor-data-source-methods {
2
+ width: 100%;
3
+
4
+ .tmagic-design-table {
5
+ width: 100%;
6
+ }
7
+
8
+ .m-editor-data-source-methods-footer {
9
+ display: flex;
10
+ justify-content: flex-end;
11
+ margin-top: 15px;
12
+ }
13
+ }
@@ -19,18 +19,21 @@
19
19
  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.12);
20
20
  }
21
21
  }
22
- .m-fields-code-select-col {
22
+ .m-fields-code-select-col,
23
+ .m-fields-data-source-method-select {
23
24
  width: 100%;
24
- .code-select-container {
25
- display: flex;
26
- align-items: center;
27
- .select {
28
- flex: 10 0 100px;
29
- }
30
- .icon {
31
- flex: 1 0 20px;
32
- cursor: pointer;
33
- margin-right: 5px;
34
- }
25
+ }
26
+
27
+ .code-select-container,
28
+ .data-source-method-select-container {
29
+ display: flex;
30
+ align-items: center;
31
+ .select {
32
+ flex: 10 0 100px;
33
+ }
34
+ .icon {
35
+ flex: 1 0 20px;
36
+ cursor: pointer;
37
+ margin-right: 5px;
35
38
  }
36
39
  }
@@ -4,10 +4,7 @@
4
4
  width: 100%;
5
5
 
6
6
  &-content {
7
- width: 100%;
8
7
  height: calc(100% - #{$--nav-height});
9
- display: flex;
10
- justify-self: space-between;
11
8
  }
12
9
 
13
10
  &-framework-center {
@@ -44,6 +44,12 @@
44
44
  .magic-editor-layer-panel .cus-tree-node {
45
45
  width: 100%;
46
46
  overflow: hidden;
47
+ display: flex;
48
+ justify-content: space-between;
49
+
50
+ .layer-node-tool {
51
+ margin-right: 15px;
52
+ }
47
53
  }
48
54
 
49
55
  .magic-editor-layer-panel .cus-tree-node-hover {
@@ -2,4 +2,8 @@
2
2
  width: 100%;
3
3
  display: flex;
4
4
  justify-self: space-between;
5
+
6
+ &:has(.m-editor-resizer-draging) {
7
+ overflow: hidden;
8
+ }
5
9
  }
@@ -4,14 +4,38 @@
4
4
  width: 8px;
5
5
  margin: 0 -5px;
6
6
  height: 100%;
7
- opacity: 0.9;
7
+ opacity: 0.8;
8
8
  background: padding-box #d8dee8;
9
9
  box-sizing: border-box;
10
10
  cursor: col-resize;
11
11
  z-index: 1;
12
+ position: relative;
12
13
 
13
14
  &:hover {
14
15
  border-color: #d8dee8;
16
+
17
+ .icon-container {
18
+ visibility: visible;
19
+ opacity: 1;
20
+ }
21
+ }
22
+
23
+ &.m-editor-resizer-draging {
24
+ &::after {
25
+ content: "";
26
+ position: absolute;
27
+ width: 600px;
28
+ height: 100%;
29
+ left: 0;
30
+ }
31
+
32
+ &::before {
33
+ content: "";
34
+ position: absolute;
35
+ width: 600px;
36
+ height: 100%;
37
+ right: 0;
38
+ }
15
39
  }
16
40
 
17
41
  .icon-container {
@@ -40,12 +64,3 @@
40
64
  font-size: 18px;
41
65
  }
42
66
  }
43
-
44
- .magic-editor-resizer:hover {
45
- .icon-container {
46
- visibility: visible;
47
- opacity: 1;
48
- }
49
- // border-left: 5px solid rgba(0,0,0,.5);
50
- // border-right: 5px solid rgba(0,0,0,.5);
51
- }
@@ -6,6 +6,10 @@
6
6
  display: flex;
7
7
  justify-content: center;
8
8
  align-items: center;
9
+
10
+ &:focus-visible {
11
+ outline: none;
12
+ }
9
13
  }
10
14
 
11
15
  .m-editor-stage-container {
@@ -19,4 +19,6 @@
19
19
  @import "./dep-list.scss";
20
20
  @import "./data-source.scss";
21
21
  @import "./data-source-fields.scss";
22
+ @import "./data-source-methods.scss";
23
+ @import "./data-source-input.scss";
22
24
  @import "./key-value.scss";
package/src/type.ts CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  import type { Component } from 'vue';
20
20
 
21
- import type { FormConfig, FormItem } from '@tmagic/form';
21
+ import type { ColumnConfig, FilterFunction, FormConfig, FormItem } from '@tmagic/form';
22
22
  import type { CodeBlockContent, CodeBlockDSL, Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
23
23
  import type StageCore from '@tmagic/stage';
24
24
  import type {
@@ -30,11 +30,12 @@ import type {
30
30
 
31
31
  import type { CodeBlockService } from './services/codeBlock';
32
32
  import type { ComponentListService } from './services/componentList';
33
- import { DataSourceService } from './services/dataSource';
33
+ import type { DataSourceService } from './services/dataSource';
34
34
  import type { DepService } from './services/dep';
35
35
  import type { EditorService } from './services/editor';
36
36
  import type { EventsService } from './services/events';
37
37
  import type { HistoryService } from './services/history';
38
+ import type { KeybindingService } from './services/keybinding';
38
39
  import type { PropsService } from './services/props';
39
40
  import type { StorageService } from './services/storage';
40
41
  import type { UiService } from './services/ui';
@@ -44,6 +45,7 @@ export type BeforeAdd = (config: MNode, parent: MContainer) => Promise<MNode> |
44
45
  export type GetConfig = (config: FormConfig) => Promise<FormConfig> | FormConfig;
45
46
 
46
47
  export interface InstallOptions {
48
+ parseDSL: <T = any>(dsl: string) => T;
47
49
  [key: string]: any;
48
50
  }
49
51
 
@@ -58,6 +60,7 @@ export interface Services {
58
60
  codeBlockService: CodeBlockService;
59
61
  depService: DepService;
60
62
  dataSourceService: DataSourceService;
63
+ keybindingService: KeybindingService;
61
64
  }
62
65
 
63
66
  export interface StageOptions {
@@ -90,7 +93,7 @@ export type StoreStateKey = keyof StoreState;
90
93
 
91
94
  export interface PropsState {
92
95
  propsConfigMap: Record<string, FormConfig>;
93
- propsValueMap: Record<string, MNode>;
96
+ propsValueMap: Record<string, Partial<MNode>>;
94
97
  }
95
98
 
96
99
  export interface ComponentGroupState {
@@ -331,18 +334,15 @@ export interface ScrollViewerEvent {
331
334
  }
332
335
 
333
336
  export type CodeState = {
334
- /** 是否展示代码块编辑区 */
335
- isShowCodeEditor: boolean;
336
337
  /** 代码块DSL数据源 */
337
338
  codeDsl: CodeBlockDSL | null;
338
- /** 当前选中的代码块id */
339
- id: Id;
340
339
  /** 代码块是否可编辑 */
341
340
  editable: boolean;
342
341
  /** list模式下左侧展示的代码列表 */
343
342
  combineIds: string[];
344
343
  /** 为业务逻辑预留的不可删除的代码块列表,由业务逻辑维护(如代码块上线后不可删除) */
345
344
  undeletableList: Id[];
345
+ paramsColConfig?: ColumnConfig;
346
346
  };
347
347
 
348
348
  export type HookData = {
@@ -426,4 +426,102 @@ export interface EventSelectConfig {
426
426
  compActionConfig?: FormItem;
427
427
  /** 联动代码配置 */
428
428
  codeActionConfig?: FormItem;
429
+ /** 联动数据源配置 */
430
+ dataSourceActionConfig?: FormItem;
431
+ }
432
+
433
+ export enum KeyBindingCommand {
434
+ /** 复制 */
435
+ COPY_NODE = 'tmagic-system-copy-node',
436
+ /** 粘贴 */
437
+ PASTE_NODE = 'tmagic-system-paste-node',
438
+ /** 删除 */
439
+ DELETE_NODE = 'tmagic-system-delete-node',
440
+ /** 剪切 */
441
+ CUT_NODE = 'tmagic-system-cut-node',
442
+ /** 撤销 */
443
+ UNDO = 'tmagic-system-undo',
444
+ /** 重做 */
445
+ REDO = 'tmagic-system-redo',
446
+ /** 放大 */
447
+ ZOOM_IN = 'tmagic-system-zoom-in',
448
+ /** 缩小 */
449
+ ZOOM_OUT = 'tmagic-system-zoom-out',
450
+ /** 缩放到实际大小 */
451
+ ZOOM_RESET = 'tmagic-system-zoom-reset',
452
+ /** 缩放以适应 */
453
+ ZOOM_FIT = 'tmagic-system-zoom-fit',
454
+ /** 向上移动1px */
455
+ MOVE_UP_1 = 'tmagic-system-move-up-1',
456
+ /** 向下移动1px */
457
+ MOVE_DOWN_1 = 'tmagic-system-move-down-1',
458
+ /** 向左移动1px */
459
+ MOVE_LEFT_1 = 'tmagic-system-move-left-1',
460
+ /** 向右移动1px */
461
+ MOVE_RIGHT_1 = 'tmagic-system-move-right-1',
462
+ /** 向上移动10px */
463
+ MOVE_UP_10 = 'tmagic-system-move-up-10',
464
+ /** 向下移动10px */
465
+ MOVE_DOWN_10 = 'tmagic-system-move-down-10',
466
+ /** 向左移动10px */
467
+ MOVE_LEFT_10 = 'tmagic-system-move-left-10',
468
+ /** 向右移动10px */
469
+ MOVE_RIGHT_10 = 'tmagic-system-move-right-10',
470
+ /** 切换组件 */
471
+ SWITCH_NODE = 'tmagic-system-switch-node',
472
+ }
473
+
474
+ export interface KeyBindingItem {
475
+ command: KeyBindingCommand | string;
476
+ keybinding?: string | string[];
477
+ when: [string, 'keyup' | 'keydown'][];
478
+ }
479
+
480
+ export interface KeyBindingCacheItem {
481
+ type: string;
482
+ command: KeyBindingCommand | string;
483
+ keybinding?: string | string[];
484
+ eventType: 'keyup' | 'keydown';
485
+ binded: boolean;
486
+ }
487
+
488
+ export interface CodeSelectColConfig {
489
+ type: 'code-select-col';
490
+ name: string;
491
+ labelWidth?: number | string;
492
+ disabled?: boolean | FilterFunction;
493
+ display?: boolean | FilterFunction;
494
+ }
495
+
496
+ export interface DataSourceMethodSelectConfig {
497
+ type: 'data-source-method-select';
498
+ name: string;
499
+ labelWidth?: number | string;
500
+ disabled?: boolean | FilterFunction;
501
+ display?: boolean | FilterFunction;
502
+ }
503
+
504
+ export interface DataSourceFieldSelectConfig {
505
+ type: 'data-source-field-select';
506
+ name: string;
507
+ labelWidth?: number | string;
508
+ disabled?: boolean | FilterFunction;
509
+ display?: boolean | FilterFunction;
510
+ }
511
+
512
+ export enum DepTargetType {
513
+ DEFAULT = 'default',
514
+ /** 代码块 */
515
+ CODE_BLOCK = 'code-block',
516
+ /** 数据源 */
517
+ DATA_SOURCE = 'data-source',
518
+ /** 数据源方法 */
519
+ DATA_SOURCE_METHOD = 'data-source-method',
520
+ /** 数据源条件 */
521
+ DATA_SOURCE_COND = 'data-source-cond',
522
+ }
523
+
524
+ export interface DatasourceTypeOption {
525
+ type: string;
526
+ text: string;
429
527
  }
@@ -24,6 +24,6 @@ const setConfig = (option: InstallOptions): void => {
24
24
  $TMAGIC_EDITOR = option;
25
25
  };
26
26
 
27
- const getConfig = (key: keyof InstallOptions): unknown => $TMAGIC_EDITOR[key];
27
+ const getConfig = <K extends keyof InstallOptions>(key: K): InstallOptions[K] => $TMAGIC_EDITOR[key];
28
28
 
29
29
  export { getConfig, setConfig };
@@ -0,0 +1,92 @@
1
+ import { computed, markRaw, Ref, ref } from 'vue';
2
+ import { CopyDocument, Delete, DocumentCopy } from '@element-plus/icons-vue';
3
+
4
+ import { Id, MContainer, NodeType } from '@tmagic/schema';
5
+ import { isPage } from '@tmagic/utils';
6
+
7
+ import ContentMenu from '@editor/components/ContentMenu.vue';
8
+ import type { MenuButton, Services } from '@editor/type';
9
+
10
+ export const useDeleteMenu = (): MenuButton => ({
11
+ type: 'button',
12
+ text: '删除',
13
+ icon: Delete,
14
+ display: (services) => {
15
+ const node = services?.editorService?.get('node');
16
+ return node?.type !== NodeType.ROOT && !isPage(node);
17
+ },
18
+ handler: (services) => {
19
+ const nodes = services?.editorService?.get('nodes');
20
+ nodes && services?.editorService?.remove(nodes);
21
+ },
22
+ });
23
+
24
+ const canPaste = ref(false);
25
+
26
+ export const useCopyMenu = (): MenuButton => ({
27
+ type: 'button',
28
+ text: '复制',
29
+ icon: markRaw(CopyDocument),
30
+ handler: (services) => {
31
+ const nodes = services?.editorService?.get('nodes');
32
+ nodes && services?.editorService?.copy(nodes);
33
+ canPaste.value = true;
34
+ },
35
+ });
36
+
37
+ export const usePasteMenu = (menu?: Ref<InstanceType<typeof ContentMenu> | undefined>): MenuButton => ({
38
+ type: 'button',
39
+ text: '粘贴',
40
+ icon: markRaw(DocumentCopy),
41
+ display: () => canPaste.value,
42
+ handler: (services) => {
43
+ const nodes = services?.editorService?.get('nodes');
44
+ if (!nodes || nodes.length === 0) return;
45
+
46
+ if (menu?.value?.$el) {
47
+ const stage = services?.editorService?.get('stage');
48
+ const rect = menu.value.$el.getBoundingClientRect();
49
+ const parentRect = stage?.container?.getBoundingClientRect();
50
+ const initialLeft = (rect.left || 0) - (parentRect?.left || 0);
51
+ const initialTop = (rect.top || 0) - (parentRect?.top || 0);
52
+ services?.editorService?.paste({ left: initialLeft, top: initialTop });
53
+ } else {
54
+ services?.editorService?.paste();
55
+ }
56
+ },
57
+ });
58
+
59
+ const moveTo = (id: Id, services?: Services) => {
60
+ if (!services?.editorService) return;
61
+
62
+ const nodes = services.editorService.get('nodes') || [];
63
+ const parent = services.editorService.getNodeById(id) as MContainer;
64
+
65
+ if (!parent) return;
66
+
67
+ services?.editorService.add(nodes, parent);
68
+ services?.editorService.remove(nodes);
69
+ };
70
+
71
+ export const useMoveToMenu = (services?: Services): MenuButton => {
72
+ const root = computed(() => services?.editorService?.get('root'));
73
+
74
+ return {
75
+ type: 'button',
76
+ text: '移动至',
77
+ display: (services) => {
78
+ const node = services?.editorService?.get('node');
79
+ const pageLength = services?.editorService?.get('pageLength') || 0;
80
+ return !isPage(node) && pageLength > 1;
81
+ },
82
+ items: (root.value?.items || [])
83
+ .filter((page) => page.id !== services?.editorService?.get('page')?.id)
84
+ .map((page) => ({
85
+ text: `${page.name}(${page.id})`,
86
+ type: 'button',
87
+ handler: (services?: Services) => {
88
+ moveTo(page.id, services);
89
+ },
90
+ })),
91
+ };
92
+ };