@tmagic/editor 1.0.0-beta.8 → 1.0.0-rc.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 (121) hide show
  1. package/README.md +1 -0
  2. package/coverage/clover.xml +1556 -0
  3. package/coverage/coverage-final.json +36 -0
  4. package/coverage/lcov-report/base.css +224 -0
  5. package/coverage/lcov-report/block-navigation.js +87 -0
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +206 -0
  8. package/coverage/lcov-report/prettify.css +1 -0
  9. package/coverage/lcov-report/prettify.js +2 -0
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +196 -0
  12. package/coverage/lcov-report/src/Editor.vue.html +802 -0
  13. package/coverage/lcov-report/src/components/ContentMenu.vue.html +406 -0
  14. package/coverage/lcov-report/src/components/Icon.vue.html +172 -0
  15. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +283 -0
  16. package/coverage/lcov-report/src/components/ToolButton.vue.html +772 -0
  17. package/coverage/lcov-report/src/components/index.html +161 -0
  18. package/coverage/lcov-report/src/index.html +131 -0
  19. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +214 -0
  20. package/coverage/lcov-report/src/layouts/Framework.vue.html +343 -0
  21. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +208 -0
  22. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +319 -0
  23. package/coverage/lcov-report/src/layouts/Resizer.vue.html +268 -0
  24. package/coverage/lcov-report/src/layouts/index.html +176 -0
  25. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +358 -0
  26. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +421 -0
  27. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +775 -0
  28. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +226 -0
  29. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +289 -0
  30. package/coverage/lcov-report/src/layouts/sidebar/index.html +176 -0
  31. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +718 -0
  32. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +760 -0
  33. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +532 -0
  34. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +598 -0
  35. package/coverage/lcov-report/src/layouts/workspace/index.html +161 -0
  36. package/coverage/lcov-report/src/services/BaseService.ts.html +643 -0
  37. package/coverage/lcov-report/src/services/componentList.ts.html +229 -0
  38. package/coverage/lcov-report/src/services/editor.ts.html +2077 -0
  39. package/coverage/lcov-report/src/services/events.ts.html +331 -0
  40. package/coverage/lcov-report/src/services/history.ts.html +478 -0
  41. package/coverage/lcov-report/src/services/index.html +206 -0
  42. package/coverage/lcov-report/src/services/props.ts.html +415 -0
  43. package/coverage/lcov-report/src/services/ui.ts.html +580 -0
  44. package/coverage/lcov-report/src/type.ts.html +850 -0
  45. package/coverage/lcov-report/src/utils/compose.ts.html +184 -0
  46. package/coverage/lcov-report/src/utils/config.ts.html +172 -0
  47. package/coverage/lcov-report/src/utils/editor.ts.html +838 -0
  48. package/coverage/lcov-report/src/utils/index.html +221 -0
  49. package/coverage/lcov-report/src/utils/index.ts.html +151 -0
  50. package/coverage/lcov-report/src/utils/logger.ts.html +226 -0
  51. package/coverage/lcov-report/src/utils/props.ts.html +796 -0
  52. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +733 -0
  53. package/coverage/lcov-report/src/utils/undo-redo.ts.html +313 -0
  54. package/coverage/lcov.info +3747 -0
  55. package/dist/style.css +91 -45
  56. package/dist/tmagic-editor.es.js +1462 -2003
  57. package/dist/tmagic-editor.es.js.map +1 -1
  58. package/dist/tmagic-editor.umd.js +1461 -2003
  59. package/dist/tmagic-editor.umd.js.map +1 -1
  60. package/dist/types/src/Editor.vue.d.ts +10 -1
  61. package/dist/types/src/components/ToolButton.vue.d.ts +12 -1
  62. package/dist/types/src/fields/UISelect.vue.d.ts +4 -1
  63. package/dist/types/src/index.d.ts +1 -0
  64. package/dist/types/src/layouts/CodeEditor.vue.d.ts +13 -4
  65. package/dist/types/src/layouts/Framework.vue.d.ts +15 -3
  66. package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -1
  67. package/dist/types/src/layouts/sidebar/ComponentListPanel.vue.d.ts +2 -1
  68. package/dist/types/src/layouts/sidebar/Sidebar.vue.d.ts +2 -3
  69. package/dist/types/src/layouts/sidebar/TabPane.vue.d.ts +14 -0
  70. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +10 -3
  71. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +4 -6
  72. package/dist/types/src/services/BaseService.d.ts +4 -1
  73. package/dist/types/src/services/editor.d.ts +16 -6
  74. package/dist/types/src/services/history.d.ts +1 -0
  75. package/dist/types/src/services/props.d.ts +2 -2
  76. package/dist/types/src/services/ui.d.ts +2 -0
  77. package/dist/types/src/type.d.ts +16 -9
  78. package/dist/types/src/utils/editor.d.ts +5 -4
  79. package/dist/types/src/utils/polyfills.d.ts +0 -0
  80. package/package.json +44 -12
  81. package/src/Editor.vue +6 -1
  82. package/src/components/ContentMenu.vue +107 -0
  83. package/src/components/ScrollViewer.vue +1 -1
  84. package/src/components/ToolButton.vue +72 -31
  85. package/src/fields/UISelect.vue +14 -6
  86. package/src/index.ts +2 -0
  87. package/src/layouts/AddPageBox.vue +3 -1
  88. package/src/layouts/CodeEditor.vue +20 -13
  89. package/src/layouts/Framework.vue +20 -7
  90. package/src/layouts/PropsPanel.vue +5 -4
  91. package/src/layouts/sidebar/ComponentListPanel.vue +25 -3
  92. package/src/layouts/sidebar/LayerMenu.vue +91 -96
  93. package/src/layouts/sidebar/LayerPanel.vue +80 -59
  94. package/src/layouts/sidebar/Sidebar.vue +13 -52
  95. package/src/layouts/sidebar/TabPane.vue +68 -0
  96. package/src/layouts/workspace/PageBar.vue +145 -17
  97. package/src/layouts/workspace/Stage.vue +56 -64
  98. package/src/layouts/workspace/ViewerMenu.vue +107 -68
  99. package/src/layouts/workspace/Workspace.vue +110 -18
  100. package/src/services/BaseService.ts +70 -22
  101. package/src/services/editor.ts +197 -64
  102. package/src/services/history.ts +7 -0
  103. package/src/services/props.ts +3 -3
  104. package/src/services/ui.ts +35 -5
  105. package/src/theme/common/var.scss +3 -2
  106. package/src/theme/component-list-panel.scss +2 -0
  107. package/src/theme/content-menu.scss +33 -26
  108. package/src/theme/layer-panel.scss +10 -0
  109. package/src/theme/nav-menu.scss +6 -2
  110. package/src/theme/page-bar.scss +42 -2
  111. package/src/theme/props-panel.scss +19 -17
  112. package/src/type.ts +17 -9
  113. package/src/utils/editor.ts +35 -9
  114. package/src/utils/polyfills.ts +8 -0
  115. package/src/utils/props.ts +20 -1
  116. package/dist/types/src/layouts/sidebar/LayerMenu.vue.d.ts +0 -31
  117. package/dist/types/src/layouts/sidebar/LayerPanel.vue.d.ts +0 -973
  118. package/dist/types/src/layouts/workspace/Stage.vue.d.ts +0 -192
  119. package/dist/types/src/layouts/workspace/ViewerMenu.vue.d.ts +0 -18
  120. package/tsconfig.json +0 -9
  121. package/vite.config.ts +0 -30
@@ -43,13 +43,17 @@
43
43
  display: flex !important;
44
44
  transition: all 0.3s ease 0s;
45
45
  border-bottom: 2px solid transparent;
46
- margin: 0 5px;
46
+ margin: 0;
47
47
 
48
48
  .is-disabled {
49
49
  opacity: 0.5;
50
50
  }
51
51
 
52
- .el-button--text,
52
+ .is-text {
53
+ padding: 5px;
54
+ }
55
+
56
+ .is-text,
53
57
  i {
54
58
  color: $--font-color;
55
59
  }
@@ -6,18 +6,25 @@
6
6
  width: 100%;
7
7
  height: $--page-bar-height;
8
8
  line-height: $--page-bar-height;
9
- background-color: #f3f3f3;
10
9
  color: $--font-color;
10
+ background-color: #f3f3f3;
11
11
  border-top: 1px solid $--border-color;
12
12
  z-index: 2;
13
+ overflow: hidden;
14
+
15
+ &-items {
16
+ display: flex;
17
+ transition: transform 0.3s;
18
+ }
13
19
 
14
- .m-editor-page-bar-item {
20
+ &-item {
15
21
  padding: 0 10px;
16
22
  cursor: pointer;
17
23
  border-right: 1px solid $--border-color;
18
24
  display: flex;
19
25
  justify-items: center;
20
26
  align-items: center;
27
+ background-color: #f3f3f3;
21
28
 
22
29
  &.active {
23
30
  background-color: #fff;
@@ -27,5 +34,38 @@
27
34
  cursor: pointer;
28
35
  }
29
36
  }
37
+
38
+ &-icon {
39
+ position: relative;
40
+ z-index: 1;
41
+ }
42
+
43
+ &-title {
44
+ max-width: 150px;
45
+ text-overflow: ellipsis;
46
+ white-space: nowrap;
47
+ overflow: hidden;
48
+ }
49
+ }
50
+ }
51
+
52
+ .page-bar-popover {
53
+ &.el-popper.el-popover {
54
+ padding: 10px 0;
55
+ }
56
+
57
+ .menu-item {
58
+ cursor: pointer;
59
+ transition: all 0.2s ease 0s;
60
+ padding: 5px 14px;
61
+
62
+ .el-button--text,
63
+ i {
64
+ color: $--font-color;
65
+ }
66
+
67
+ &:hover {
68
+ background-color: $--hover-color;
69
+ }
30
70
  }
31
71
  }
@@ -1,31 +1,33 @@
1
1
  .m-editor-props-panel {
2
2
  padding: 0 10px;
3
3
 
4
- .el-form-item__label {
5
- font-size: 12px;
6
- }
7
-
8
- .m-fieldset {
9
- legend {
4
+ &.small {
5
+ .el-form-item__label {
10
6
  font-size: 12px;
11
7
  }
12
- }
13
8
 
14
- .el-tabs__item {
15
- font-size: 12px;
9
+ .m-fieldset {
10
+ legend {
11
+ font-size: 12px;
12
+ }
13
+ }
14
+
15
+ .el-tabs__item {
16
+ font-size: 12px;
17
+ }
16
18
  }
17
19
 
18
- span,
19
- a,
20
- p {
21
- font-size: 12px;
20
+ .el-input__wrapper {
21
+ border-radius: 0;
22
22
  }
23
23
  }
24
24
 
25
25
  .m-editor-props-panel-popper {
26
- span,
27
- a,
28
- p {
29
- font-size: 12px;
26
+ &.small {
27
+ span,
28
+ a,
29
+ p {
30
+ font-size: 12px;
31
+ }
30
32
  }
31
33
  }
package/src/type.ts CHANGED
@@ -50,8 +50,10 @@ export interface StoreState {
50
50
  page: MPage | null;
51
51
  parent: MContainer | null;
52
52
  node: MNode | null;
53
+ highlightNode: MNode | null;
53
54
  stage: StageCore | null;
54
55
  modifiedNodeIds: Map<Id, Id>;
56
+ pageLength: number;
55
57
  }
56
58
 
57
59
  export interface PropsState {
@@ -97,6 +99,8 @@ export interface UiState {
97
99
  showGuides: boolean;
98
100
  /** 是否显示标尺,true: 显示,false: 不显示,默认为true */
99
101
  showRule: boolean;
102
+ /** 用于控制该属性配置表单内组件的尺寸 */
103
+ propsPanelSize: 'large' | 'default' | 'small';
100
104
  }
101
105
 
102
106
  export interface EditorNodeInfo {
@@ -124,6 +128,8 @@ export interface MenuButton {
124
128
  * zoom: 放大缩小
125
129
  */
126
130
  type: 'button' | 'dropdown' | 'text' | 'divider' | 'zoom';
131
+ /** 当type为divider时有效,分割线方向, 默认vertical */
132
+ direction?: 'horizontal' | 'vertical';
127
133
  /** 展示的文案 */
128
134
  text?: string;
129
135
  /** 鼠标悬浮是显示的气泡中的文案 */
@@ -135,14 +141,9 @@ export interface MenuButton {
135
141
  /** 是否显示,默认为true */
136
142
  display?: boolean | ((data?: Services) => boolean);
137
143
  /** type为button/dropdown时点击运行的方法 */
138
- handler?: (data?: Services) => Promise<any> | any;
139
- /** type为dropdown时,下拉的菜单列表 */
140
- items?: {
141
- /** 展示的文案 */
142
- text: string;
143
- /** 点击运行的方法 */
144
- handler(data: Services): any;
145
- }[];
144
+ handler?: (data: Services, event: MouseEvent) => Promise<any> | any;
145
+ /** type为dropdown时,下拉的菜单列表, 或者有子菜单时 */
146
+ items?: MenuButton[];
146
147
  }
147
148
 
148
149
  export interface MenuComponent {
@@ -219,7 +220,9 @@ export interface ComponentItem {
219
220
  type: string;
220
221
  /** element-plus icon class */
221
222
  icon?: string | Component;
222
- [key: string]: any;
223
+ data?: {
224
+ [key: string]: any;
225
+ };
223
226
  }
224
227
 
225
228
  export interface ComponentGroup {
@@ -229,6 +232,11 @@ export interface ComponentGroup {
229
232
  items: ComponentItem[];
230
233
  }
231
234
 
235
+ export interface UpdateData {
236
+ id: Id;
237
+ [key: string]: any;
238
+ }
239
+
232
240
  export enum LayerOffset {
233
241
  TOP = 'top',
234
242
  BOTTOM = 'bottom',
@@ -18,8 +18,10 @@
18
18
 
19
19
  import { random } from 'lodash-es';
20
20
 
21
- import { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
22
- import { getNodePath, isPop } from '@tmagic/utils';
21
+ import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
22
+ import { NodeType } from '@tmagic/schema';
23
+ import type StageCore from '@tmagic/stage';
24
+ import { getNodePath, isNumber, isPage, isPop } from '@tmagic/utils';
23
25
 
24
26
  import { Layout } from '@editor/type';
25
27
 
@@ -34,7 +36,7 @@ export const generateId = (type: string | number): string => `${type}_${random(1
34
36
  */
35
37
  export const getPageList = (app: MApp): MPage[] => {
36
38
  if (app.items && Array.isArray(app.items)) {
37
- return app.items.filter((item: MPage) => item.type === 'page');
39
+ return app.items.filter((item: MPage) => item.type === NodeType.PAGE);
38
40
  }
39
41
  return [];
40
42
  };
@@ -104,11 +106,11 @@ const updatePopId = (oldId: Id, popId: Id, pageConfig: MPage) => {
104
106
  export const setNewItemId = (config: MNode, parent?: MPage) => {
105
107
  const oldId = config.id;
106
108
 
107
- config.id = generateId(config.type);
109
+ config.id = generateId(config.type || 'component');
108
110
  config.name = `${config.name?.replace(/_(\d+)$/, '')}_${config.id}`;
109
111
 
110
112
  // 只有弹窗在页面下的一级子元素才有效
111
- if (isPop(config) && parent?.type === 'page') {
113
+ if (isPop(config) && parent?.type === NodeType.PAGE) {
112
114
  updatePopId(oldId, config.id, parent);
113
115
  }
114
116
 
@@ -123,7 +125,7 @@ export const setNewItemId = (config: MNode, parent?: MPage) => {
123
125
  */
124
126
  export const isFixed = (node: MNode): boolean => node.style?.position === 'fixed';
125
127
 
126
- export const getNodeIndex = (node: MNode, parent: MContainer): number => {
128
+ export const getNodeIndex = (node: MNode, parent: MContainer | MApp): number => {
127
129
  const items = parent?.items || [];
128
130
  return items.findIndex((item: MNode) => `${item.id}` === `${node.id}`);
129
131
  };
@@ -138,11 +140,29 @@ export const toRelative = (node: MNode) => {
138
140
  return node;
139
141
  };
140
142
 
141
- export const initPosition = (node: MNode, layout: Layout) => {
143
+ const setTop2Middle = (node: MNode, parentNode: MNode, stage: StageCore) => {
144
+ const style = node.style || {};
145
+ const height = style.height || 0;
146
+
147
+ if (!stage || typeof style.top !== 'undefined' || !parentNode.style || !isNumber(height)) return style;
148
+
149
+ const { height: parentHeight } = parentNode.style;
150
+
151
+ if (isPage(parentNode)) {
152
+ const { scrollTop = 0, wrapperHeight } = stage.mask;
153
+ style.top = (wrapperHeight - height) / 2 + scrollTop;
154
+ } else {
155
+ style.top = (parentHeight - height) / 2;
156
+ }
157
+
158
+ return style;
159
+ };
160
+
161
+ export const initPosition = (node: MNode, layout: Layout, parentNode: MNode, stage: StageCore) => {
142
162
  if (layout === Layout.ABSOLUTE) {
143
163
  node.style = {
144
164
  position: 'absolute',
145
- ...(node.style || {}),
165
+ ...setTop2Middle(node, parentNode, stage),
146
166
  };
147
167
  return node;
148
168
  }
@@ -193,12 +213,18 @@ export const change2Fixed = (node: MNode, root: MApp) => {
193
213
  return node;
194
214
  };
195
215
 
196
- export const Fixed2Other = async (node: MNode, root: MApp, getLayout: (node: MNode) => Promise<Layout>) => {
216
+ export const Fixed2Other = async (
217
+ node: MNode,
218
+ root: MApp,
219
+ getLayout: (parent: MNode, node?: MNode) => Promise<Layout>,
220
+ ) => {
197
221
  const path = getNodePath(node.id, root.items);
198
222
  const cur = path.pop();
199
223
  const offset = {
200
224
  left: cur?.style?.left || 0,
201
225
  top: cur?.style?.top || 0,
226
+ right: '',
227
+ bottom: '',
202
228
  };
203
229
 
204
230
  path.forEach((value) => {
@@ -0,0 +1,8 @@
1
+ // serialize-javascript 依赖的 randombytes 依赖全局的 global 对象,因此此处需添加 global polyfill
2
+ if (typeof global === 'undefined') {
3
+ (window as any).global = window;
4
+ }
5
+
6
+ if (typeof globalThis === 'undefined') {
7
+ (window as any).globalThis = window;
8
+ }
@@ -142,6 +142,25 @@ export const fillConfig = (config: FormConfig = []) => [
142
142
  },
143
143
  ],
144
144
  },
145
+ {
146
+ type: 'fieldset',
147
+ legend: '字体',
148
+ items: [
149
+ {
150
+ name: 'color',
151
+ text: '颜色',
152
+ type: 'colorPicker',
153
+ },
154
+ {
155
+ name: 'fontSize',
156
+ text: '大小',
157
+ },
158
+ {
159
+ name: 'fontWeight',
160
+ text: '粗细',
161
+ },
162
+ ],
163
+ },
145
164
  ],
146
165
  },
147
166
  ],
@@ -174,7 +193,7 @@ export const fillConfig = (config: FormConfig = []) => [
174
193
  type: 'select',
175
194
  options: (mForm: FormState, { model }: any) => {
176
195
  const node = editorService.getNodeById(model.to);
177
- if (!node) return [];
196
+ if (!node?.type) return [];
178
197
 
179
198
  return eventsService.getMethod(node.type).map((option) => ({
180
199
  text: option.label,
@@ -1,31 +0,0 @@
1
- import type { MNode } from '@tmagic/schema';
2
- import type { DefineComponent, Ref, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes, PropType } from 'vue';
3
- import type { ComponentGroup } from '../../type';
4
- declare const _default: DefineComponent<{
5
- componentGroupList: {
6
- type: PropType<ComponentGroup[]>;
7
- default: () => never[];
8
- };
9
- }, {
10
- subVisible: Ref<boolean>;
11
- node: ComputedRef<MNode | undefined>;
12
- menu: ComputedRef<{
13
- app: {
14
- type: string;
15
- text: string;
16
- }[];
17
- component: ComponentGroup[];
18
- }>;
19
- append(config: any): void;
20
- remove(): void;
21
- copy(node: any): void;
22
- setSubVisiable(v: any): void;
23
- }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, Record<string, any>, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
24
- componentGroupList: {
25
- type: PropType<ComponentGroup[]>;
26
- default: () => never[];
27
- };
28
- }>>, {
29
- componentGroupList: ComponentGroup[];
30
- }>;
31
- export default _default;