@tmagic/editor 1.0.0-rc.6 → 1.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/tmagic-editor.es.js +17 -2
  2. package/dist/tmagic-editor.es.js.map +1 -1
  3. package/dist/tmagic-editor.umd.js +17 -2
  4. package/dist/tmagic-editor.umd.js.map +1 -1
  5. package/dist/types/src/fields/Code.vue.d.ts +4 -4
  6. package/dist/types/src/fields/CodeLink.vue.d.ts +1 -3
  7. package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -4
  8. package/dist/types/src/services/history.d.ts +1 -18
  9. package/package.json +11 -20
  10. package/src/services/editor.ts +1 -2
  11. package/src/services/props.ts +62 -7
  12. package/src/utils/editor.ts +1 -50
  13. package/src/utils/props.ts +17 -3
  14. package/LICENSE +0 -5432
  15. package/coverage/clover.xml +0 -1615
  16. package/coverage/coverage-final.json +0 -36
  17. package/coverage/lcov-report/base.css +0 -224
  18. package/coverage/lcov-report/block-navigation.js +0 -87
  19. package/coverage/lcov-report/favicon.png +0 -0
  20. package/coverage/lcov-report/index.html +0 -206
  21. package/coverage/lcov-report/prettify.css +0 -1
  22. package/coverage/lcov-report/prettify.js +0 -2
  23. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  24. package/coverage/lcov-report/sorter.js +0 -196
  25. package/coverage/lcov-report/src/Editor.vue.html +0 -853
  26. package/coverage/lcov-report/src/components/ContentMenu.vue.html +0 -505
  27. package/coverage/lcov-report/src/components/Icon.vue.html +0 -172
  28. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +0 -283
  29. package/coverage/lcov-report/src/components/ToolButton.vue.html +0 -772
  30. package/coverage/lcov-report/src/components/index.html +0 -161
  31. package/coverage/lcov-report/src/index.html +0 -131
  32. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +0 -214
  33. package/coverage/lcov-report/src/layouts/Framework.vue.html +0 -343
  34. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +0 -208
  35. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +0 -319
  36. package/coverage/lcov-report/src/layouts/Resizer.vue.html +0 -268
  37. package/coverage/lcov-report/src/layouts/index.html +0 -176
  38. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +0 -358
  39. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +0 -430
  40. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +0 -775
  41. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +0 -226
  42. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +0 -289
  43. package/coverage/lcov-report/src/layouts/sidebar/index.html +0 -176
  44. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +0 -718
  45. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +0 -766
  46. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +0 -577
  47. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +0 -649
  48. package/coverage/lcov-report/src/layouts/workspace/index.html +0 -161
  49. package/coverage/lcov-report/src/services/BaseService.ts.html +0 -643
  50. package/coverage/lcov-report/src/services/componentList.ts.html +0 -229
  51. package/coverage/lcov-report/src/services/editor.ts.html +0 -2167
  52. package/coverage/lcov-report/src/services/events.ts.html +0 -331
  53. package/coverage/lcov-report/src/services/history.ts.html +0 -478
  54. package/coverage/lcov-report/src/services/index.html +0 -206
  55. package/coverage/lcov-report/src/services/props.ts.html +0 -415
  56. package/coverage/lcov-report/src/services/ui.ts.html +0 -580
  57. package/coverage/lcov-report/src/type.ts.html +0 -850
  58. package/coverage/lcov-report/src/utils/compose.ts.html +0 -184
  59. package/coverage/lcov-report/src/utils/config.ts.html +0 -172
  60. package/coverage/lcov-report/src/utils/editor.ts.html +0 -850
  61. package/coverage/lcov-report/src/utils/index.html +0 -221
  62. package/coverage/lcov-report/src/utils/index.ts.html +0 -151
  63. package/coverage/lcov-report/src/utils/logger.ts.html +0 -226
  64. package/coverage/lcov-report/src/utils/props.ts.html +0 -796
  65. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +0 -733
  66. package/coverage/lcov-report/src/utils/undo-redo.ts.html +0 -313
  67. package/coverage/lcov.info +0 -3893
  68. package/dist/types/src/components/ToolButton.vue.d.ts +0 -46
  69. package/dist/types/src/fields/UISelect.vue.d.ts +0 -35
  70. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +0 -18
@@ -16,9 +16,9 @@ declare const _default: DefineComponent<Readonly<{
16
16
  }>>> & {
17
17
  onChange?: ((...args: any[]) => any) | undefined;
18
18
  }, {
19
- name: any;
20
- config: any;
21
- model: any;
22
- prop: any;
19
+ readonly name?: any;
20
+ readonly config?: any;
21
+ readonly model?: any;
22
+ readonly prop?: any;
23
23
  }>;
24
24
  export default _default;
@@ -20,9 +20,7 @@ declare const _default: DefineComponent<{
20
20
  };
21
21
  }, {
22
22
  modelValue: Ref<{
23
- form: {
24
- [x: string]: any;
25
- };
23
+ form: Record<string, any>;
26
24
  }>;
27
25
  formConfig: ComputedRef<{
28
26
  text: string;
@@ -1,9 +1,7 @@
1
1
  import type { DefineComponent, Ref, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
2
+ import type { FormValue } from '@tmagic/form';
2
3
  declare const _default: DefineComponent<{}, {
3
- values: Ref<{
4
- [x: string]: any;
5
- [x: number]: any;
6
- }>;
4
+ values: Ref<FormValue>;
7
5
  configForm: Ref<any>;
8
6
  curFormConfig: any;
9
7
  propsPanelSize: ComputedRef<unknown>;
@@ -15,24 +15,7 @@ export interface HistoryState {
15
15
  declare class History extends BaseService {
16
16
  state: {
17
17
  pageId?: Id | undefined;
18
- pageSteps: {
19
- [x: string]: {
20
- pushElement: (element: StepValue) => void;
21
- canUndo: () => boolean;
22
- undo: () => StepValue | null;
23
- canRedo: () => boolean;
24
- redo: () => StepValue | null;
25
- getCurrentElement: () => StepValue | null;
26
- };
27
- [x: number]: {
28
- pushElement: (element: StepValue) => void;
29
- canUndo: () => boolean;
30
- undo: () => StepValue | null;
31
- canRedo: () => boolean;
32
- redo: () => StepValue | null;
33
- getCurrentElement: () => StepValue | null;
34
- };
35
- };
18
+ pageSteps: Record<Id, UndoRedo<StepValue>>;
36
19
  canRedo: boolean;
37
20
  canUndo: boolean;
38
21
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-rc.6",
2
+ "version": "1.0.0-rc.7",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -22,9 +22,7 @@
22
22
  },
23
23
  "license": "Apache-2.0",
24
24
  "scripts": {
25
- "build": "vite build",
26
- "test": "jest --maxWorkers=8",
27
- "test:coverage": "jest --maxWorkers=16 --coverage"
25
+ "build": "vite build"
28
26
  },
29
27
  "engines": {
30
28
  "node": ">=14"
@@ -45,11 +43,11 @@
45
43
  "dependencies": {
46
44
  "@babel/core": "^7.18.0",
47
45
  "@element-plus/icons": "0.0.11",
48
- "@tmagic/core": "^1.0.0-rc.6",
49
- "@tmagic/form": "^1.0.0-rc.6",
50
- "@tmagic/schema": "^1.0.0-rc.6",
51
- "@tmagic/stage": "^1.0.0-rc.6",
52
- "@tmagic/utils": "^1.0.0-rc.6",
46
+ "@tmagic/core": "1.0.0-rc.7",
47
+ "@tmagic/form": "1.0.0-rc.7",
48
+ "@tmagic/schema": "1.0.0-rc.7",
49
+ "@tmagic/stage": "1.0.0-rc.7",
50
+ "@tmagic/utils": "1.0.0-rc.7",
53
51
  "buffer": "^6.0.3",
54
52
  "color": "^3.1.3",
55
53
  "element-plus": "^2.2.0",
@@ -62,31 +60,24 @@
62
60
  "vue": "^3.2.0"
63
61
  },
64
62
  "peerDependencies": {
65
- "@tmagic/form": "^1.0.0-rc.1",
63
+ "@tmagic/form": "1.0.0-rc.7",
66
64
  "element-plus": "^2.2.0",
65
+ "monaco-editor": "^0.32.1",
67
66
  "vue": "^3.2.0"
68
67
  },
69
68
  "devDependencies": {
70
69
  "@types/events": "^3.0.0",
71
- "@types/jest": "^27.5.1",
72
70
  "@types/lodash-es": "^4.17.4",
73
71
  "@types/node": "^15.12.4",
74
72
  "@types/serialize-javascript": "^5.0.1",
75
73
  "@vitejs/plugin-vue": "^1.2.3",
76
74
  "@vitejs/plugin-vue-jsx": "^1.1.6",
77
75
  "@vue/compiler-sfc": "^3.2.0",
78
- "@vue/test-utils": "^2.0.0-rc.20",
79
- "@vue/vue3-jest": "^27.0.0-alpha.4",
80
- "babel-jest": "^27.0.6",
81
- "jest": "^27.5.1",
82
- "jest-serializer-vue": "^2.0.2",
83
- "jest-transform-stub": "^2.0.0",
76
+ "@vue/test-utils": "^2.0.0",
84
77
  "sass": "^1.35.1",
85
- "ts-jest": "^27.1.4",
86
78
  "typescript": "^4.3.4",
87
79
  "vite": "^2.3.7",
88
80
  "vite-plugin-dts": "^0.9.6",
89
81
  "vue-tsc": "^0.0.24"
90
- },
91
- "gitHead": "a93928e56d73b7924991e899a4dfaf9614cd357c"
82
+ }
92
83
  }
@@ -38,7 +38,6 @@ import {
38
38
  initPosition,
39
39
  isFixed,
40
40
  setLayout,
41
- setNewItemId,
42
41
  } from '@editor/utils/editor';
43
42
  import { log } from '@editor/utils/logger';
44
43
 
@@ -495,7 +494,7 @@ class Editor extends BaseService {
495
494
  return;
496
495
  }
497
496
 
498
- setNewItemId(config, this.get('root'));
497
+ await propsService.setNewItemId(config, this.get('root'));
499
498
  if (config.style) {
500
499
  config.style = {
501
500
  ...config.style,
@@ -17,11 +17,12 @@
17
17
  */
18
18
 
19
19
  import { reactive } from 'vue';
20
- import { cloneDeep, mergeWith } from 'lodash-es';
20
+ import { cloneDeep, mergeWith, random } from 'lodash-es';
21
21
 
22
22
  import type { FormConfig } from '@tmagic/form';
23
- import type { MComponent, MNode } from '@tmagic/schema';
24
- import { toLine } from '@tmagic/utils';
23
+ import type { Id, MComponent, MNode, MPage } from '@tmagic/schema';
24
+ import { NodeType } from '@tmagic/schema';
25
+ import { isPop, toLine } from '@tmagic/utils';
25
26
 
26
27
  import type { PropsState } from '@editor/type';
27
28
  import { DEFAULT_CONFIG, fillConfig, getDefaultPropsValue } from '@editor/utils/props';
@@ -35,7 +36,7 @@ class Props extends BaseService {
35
36
  });
36
37
 
37
38
  constructor() {
38
- super(['setPropsConfig', 'getPropsConfig', 'setPropsValue', 'getPropsValue']);
39
+ super(['setPropsConfig', 'getPropsConfig', 'setPropsValue', 'getPropsValue', 'createId', 'setNewItemId']);
39
40
  }
40
41
 
41
42
  public setPropsConfigs(configs: Record<string, FormConfig>) {
@@ -87,7 +88,7 @@ class Props extends BaseService {
87
88
  * @param type 组件类型
88
89
  * @returns 组件初始值
89
90
  */
90
- public async getPropsValue(type: string, defaultValue = {}) {
91
+ public async getPropsValue(type: string, defaultValue: Record<string, any> = {}) {
91
92
  if (type === 'area') {
92
93
  const value = (await this.getPropsValue('button')) as MComponent;
93
94
  value.className = 'action-area';
@@ -98,13 +99,67 @@ class Props extends BaseService {
98
99
  return value;
99
100
  }
100
101
 
102
+ const data = cloneDeep(defaultValue as any);
103
+
104
+ await this.setNewItemId(data);
105
+
101
106
  return {
102
- ...getDefaultPropsValue(type),
103
- ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), cloneDeep(defaultValue)),
107
+ ...getDefaultPropsValue(type, await this.createId(type)),
108
+ ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
104
109
  };
105
110
  }
111
+
112
+ public async createId(type: string | number): Promise<string> {
113
+ return `${type}_${random(10000, false)}`;
114
+ }
115
+
116
+ /**
117
+ * 将组件与组件的子元素配置中的id都设置成一个新的ID
118
+ * @param {Object} config 组件配置
119
+ */
120
+ /* eslint no-param-reassign: ["error", { "props": false }] */
121
+ public async setNewItemId(config: MNode, parent?: MPage) {
122
+ const oldId = config.id;
123
+
124
+ config.id = await this.createId(config.type || 'component');
125
+
126
+ // 只有弹窗在页面下的一级子元素才有效
127
+ if (isPop(config) && parent?.type === NodeType.PAGE) {
128
+ updatePopId(oldId, config.id, parent);
129
+ }
130
+
131
+ if (config.items && Array.isArray(config.items)) {
132
+ for (const item of config.items) {
133
+ await this.setNewItemId(item, config as MPage);
134
+ }
135
+ }
136
+ }
106
137
  }
107
138
 
139
+ /**
140
+ * 复制页面时,需要把组件下关联的弹窗id换测复制出来的弹窗的id
141
+ * @param {number} oldId 复制的源弹窗id
142
+ * @param {number} popId 新的弹窗id
143
+ * @param {Object} pageConfig 页面配置
144
+ */
145
+ const updatePopId = (oldId: Id, popId: Id, pageConfig: MPage) => {
146
+ pageConfig.items?.forEach((config) => {
147
+ if (config.pop === oldId) {
148
+ config.pop = popId;
149
+ return;
150
+ }
151
+
152
+ if (config.popId === oldId) {
153
+ config.popId = popId;
154
+ return;
155
+ }
156
+
157
+ if (Array.isArray(config.items)) {
158
+ updatePopId(oldId, popId, config as MPage);
159
+ }
160
+ });
161
+ };
162
+
108
163
  export type PropsService = Props;
109
164
 
110
165
  export default new Props();
@@ -16,9 +16,7 @@
16
16
  * limitations under the License.
17
17
  */
18
18
 
19
- import { random } from 'lodash-es';
20
-
21
- import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
19
+ import type { MApp, MContainer, MNode, MPage } from '@tmagic/schema';
22
20
  import { NodeType } from '@tmagic/schema';
23
21
  import type StageCore from '@tmagic/stage';
24
22
  import { getNodePath, isNumber, isPage, isPop } from '@tmagic/utils';
@@ -27,8 +25,6 @@ import { Layout } from '@editor/type';
27
25
 
28
26
  export const COPY_STORAGE_KEY = '$MagicEditorCopyData';
29
27
 
30
- export const generateId = (type: string | number): string => `${type}_${random(10000, false)}`;
31
-
32
28
  /**
33
29
  * 获取所有页面配置
34
30
  * @param app DSL跟节点
@@ -74,51 +70,6 @@ export const generatePageName = (pageNameList: string[]): string => {
74
70
  */
75
71
  export const generatePageNameByApp = (app: MApp): string => generatePageName(getPageNameList(getPageList(app)));
76
72
 
77
- /**
78
- * 复制页面时,需要把组件下关联的弹窗id换测复制出来的弹窗的id
79
- * @param {number} oldId 复制的源弹窗id
80
- * @param {number} popId 新的弹窗id
81
- * @param {Object} pageConfig 页面配置
82
- */
83
- const updatePopId = (oldId: Id, popId: Id, pageConfig: MPage) => {
84
- pageConfig.items?.forEach((config) => {
85
- if (config.pop === oldId) {
86
- config.pop = popId;
87
- return;
88
- }
89
-
90
- if (config.popId === oldId) {
91
- config.popId = popId;
92
- return;
93
- }
94
-
95
- if (Array.isArray(config.items)) {
96
- updatePopId(oldId, popId, config as MPage);
97
- }
98
- });
99
- };
100
-
101
- /**
102
- * 将组件与组件的子元素配置中的id都设置成一个新的ID
103
- * @param {Object} config 组件配置
104
- */
105
- /* eslint no-param-reassign: ["error", { "props": false }] */
106
- export const setNewItemId = (config: MNode, parent?: MPage) => {
107
- const oldId = config.id;
108
-
109
- config.id = generateId(config.type || 'component');
110
- config.name = `${config.name?.replace(/_(\d+)$/, '')}_${config.id}`;
111
-
112
- // 只有弹窗在页面下的一级子元素才有效
113
- if (isPop(config) && parent?.type === NodeType.PAGE) {
114
- updatePopId(oldId, config.id, parent);
115
- }
116
-
117
- if (config.items && Array.isArray(config.items)) {
118
- config.items.forEach((item) => setNewItemId(item, config as MPage));
119
- }
120
- };
121
-
122
73
  /**
123
74
  * @param {Object} node
124
75
  * @returns {boolean}
@@ -20,7 +20,6 @@ import { FormConfig, FormState } from '@tmagic/form';
20
20
 
21
21
  import editorService from '@editor/services/editor';
22
22
  import eventsService from '@editor/services/events';
23
- import { generateId } from '@editor/utils/editor';
24
23
 
25
24
  /**
26
25
  * 统一为组件属性表单加上事件、高级、样式配置
@@ -161,6 +160,21 @@ export const fillConfig = (config: FormConfig = []) => [
161
160
  },
162
161
  ],
163
162
  },
163
+ {
164
+ type: 'fieldset',
165
+ legend: '变形',
166
+ name: 'transform',
167
+ items: [
168
+ {
169
+ name: 'rotate',
170
+ text: '旋转角度',
171
+ },
172
+ {
173
+ name: 'scale',
174
+ text: '缩放',
175
+ },
176
+ ],
177
+ },
164
178
  ],
165
179
  },
166
180
  ],
@@ -229,9 +243,9 @@ export const DEFAULT_CONFIG: FormConfig = fillConfig([]);
229
243
  * @param type 组件类型
230
244
  * @returns Object
231
245
  */
232
- export const getDefaultPropsValue = (type: string) => ({
246
+ export const getDefaultPropsValue = (type: string, id: string) => ({
233
247
  type,
234
- id: generateId(type),
248
+ id,
235
249
  style: {},
236
250
  name: type,
237
251
  });