@tmagic/editor 1.0.0-rc.1 → 1.0.0-rc.12

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 (96) hide show
  1. package/dist/style.css +7 -3
  2. package/dist/tmagic-editor.es.js +304 -1405
  3. package/dist/tmagic-editor.es.js.map +1 -1
  4. package/dist/tmagic-editor.umd.js +304 -1407
  5. package/dist/tmagic-editor.umd.js.map +1 -1
  6. package/dist/types/src/Editor.vue.d.ts +42 -1
  7. package/dist/types/src/fields/Code.vue.d.ts +4 -4
  8. package/dist/types/src/fields/CodeLink.vue.d.ts +1 -3
  9. package/dist/types/src/layouts/Framework.vue.d.ts +15 -3
  10. package/dist/types/src/layouts/PropsPanel.vue.d.ts +2 -4
  11. package/dist/types/src/layouts/workspace/Workspace.vue.d.ts +3 -27
  12. package/dist/types/src/services/BaseService.d.ts +1 -1
  13. package/dist/types/src/services/editor.d.ts +6 -3
  14. package/dist/types/src/services/history.d.ts +1 -18
  15. package/dist/types/src/services/props.d.ts +8 -2
  16. package/dist/types/src/type.d.ts +9 -0
  17. package/dist/types/src/utils/editor.d.ts +0 -6
  18. package/dist/types/src/utils/props.d.ts +10 -1
  19. package/package.json +17 -18
  20. package/src/Editor.vue +41 -9
  21. package/src/components/ContentMenu.vue +59 -26
  22. package/src/layouts/CodeEditor.vue +1 -4
  23. package/src/layouts/Framework.vue +14 -1
  24. package/src/layouts/PropsPanel.vue +1 -1
  25. package/src/layouts/sidebar/LayerMenu.vue +3 -0
  26. package/src/layouts/sidebar/TabPane.vue +1 -1
  27. package/src/layouts/workspace/Stage.vue +14 -31
  28. package/src/layouts/workspace/ViewerMenu.vue +17 -2
  29. package/src/layouts/workspace/Workspace.vue +21 -26
  30. package/src/services/BaseService.ts +1 -1
  31. package/src/services/editor.ts +49 -14
  32. package/src/services/props.ts +64 -9
  33. package/src/theme/page-bar.scss +1 -0
  34. package/src/theme/props-panel.scss +6 -4
  35. package/src/theme/workspace.scss +4 -0
  36. package/src/type.ts +10 -0
  37. package/src/utils/editor.ts +7 -52
  38. package/src/utils/polyfills.ts +5 -19
  39. package/src/utils/props.ts +31 -7
  40. package/LICENSE +0 -5432
  41. package/coverage/clover.xml +0 -1560
  42. package/coverage/coverage-final.json +0 -36
  43. package/coverage/lcov-report/base.css +0 -224
  44. package/coverage/lcov-report/block-navigation.js +0 -87
  45. package/coverage/lcov-report/favicon.png +0 -0
  46. package/coverage/lcov-report/index.html +0 -206
  47. package/coverage/lcov-report/prettify.css +0 -1
  48. package/coverage/lcov-report/prettify.js +0 -2
  49. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  50. package/coverage/lcov-report/sorter.js +0 -196
  51. package/coverage/lcov-report/src/Editor.vue.html +0 -787
  52. package/coverage/lcov-report/src/components/ContentMenu.vue.html +0 -406
  53. package/coverage/lcov-report/src/components/Icon.vue.html +0 -172
  54. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +0 -283
  55. package/coverage/lcov-report/src/components/ToolButton.vue.html +0 -772
  56. package/coverage/lcov-report/src/components/index.html +0 -161
  57. package/coverage/lcov-report/src/index.html +0 -131
  58. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +0 -214
  59. package/coverage/lcov-report/src/layouts/Framework.vue.html +0 -304
  60. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +0 -208
  61. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +0 -319
  62. package/coverage/lcov-report/src/layouts/Resizer.vue.html +0 -268
  63. package/coverage/lcov-report/src/layouts/index.html +0 -176
  64. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +0 -358
  65. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +0 -421
  66. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +0 -775
  67. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +0 -226
  68. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +0 -289
  69. package/coverage/lcov-report/src/layouts/sidebar/index.html +0 -176
  70. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +0 -718
  71. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +0 -757
  72. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +0 -532
  73. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +0 -586
  74. package/coverage/lcov-report/src/layouts/workspace/index.html +0 -161
  75. package/coverage/lcov-report/src/services/BaseService.ts.html +0 -643
  76. package/coverage/lcov-report/src/services/componentList.ts.html +0 -229
  77. package/coverage/lcov-report/src/services/editor.ts.html +0 -2077
  78. package/coverage/lcov-report/src/services/events.ts.html +0 -331
  79. package/coverage/lcov-report/src/services/history.ts.html +0 -478
  80. package/coverage/lcov-report/src/services/index.html +0 -206
  81. package/coverage/lcov-report/src/services/props.ts.html +0 -415
  82. package/coverage/lcov-report/src/services/ui.ts.html +0 -580
  83. package/coverage/lcov-report/src/type.ts.html +0 -850
  84. package/coverage/lcov-report/src/utils/compose.ts.html +0 -184
  85. package/coverage/lcov-report/src/utils/config.ts.html +0 -172
  86. package/coverage/lcov-report/src/utils/editor.ts.html +0 -838
  87. package/coverage/lcov-report/src/utils/index.html +0 -221
  88. package/coverage/lcov-report/src/utils/index.ts.html +0 -151
  89. package/coverage/lcov-report/src/utils/logger.ts.html +0 -226
  90. package/coverage/lcov-report/src/utils/props.ts.html +0 -796
  91. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +0 -733
  92. package/coverage/lcov-report/src/utils/undo-redo.ts.html +0 -313
  93. package/coverage/lcov.info +0 -3708
  94. package/dist/types/src/components/ToolButton.vue.d.ts +0 -46
  95. package/dist/types/src/fields/UISelect.vue.d.ts +0 -35
  96. package/dist/types/src/layouts/workspace/PageBar.vue.d.ts +0 -18
@@ -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
 
101
- return cloneDeep({
102
- ...getDefaultPropsValue(type),
103
- ...mergeWith(this.state.propsValueMap[type] || {}, defaultValue),
104
- });
102
+ const data = cloneDeep(defaultValue as any);
103
+
104
+ await this.setNewItemId(data);
105
+
106
+ return {
107
+ ...getDefaultPropsValue(type, await this.createId(type)),
108
+ ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data),
109
+ };
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
+ }
105
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();
@@ -25,6 +25,7 @@
25
25
  justify-items: center;
26
26
  align-items: center;
27
27
  background-color: #f3f3f3;
28
+ white-space: nowrap;
28
29
 
29
30
  &.active {
30
31
  background-color: #fff;
@@ -23,9 +23,11 @@
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
  }
@@ -2,4 +2,8 @@
2
2
  height: 100%;
3
3
  width: 100%;
4
4
  user-select: none;
5
+
6
+ &:focus-visible {
7
+ outline: 0;
8
+ }
5
9
  }
package/src/type.ts CHANGED
@@ -21,6 +21,7 @@ import type { Component } from 'vue';
21
21
  import type { FormConfig } from '@tmagic/form';
22
22
  import type { Id, MApp, MContainer, MNode, MPage } from '@tmagic/schema';
23
23
  import type StageCore from '@tmagic/stage';
24
+ import type { MoveableOptions } from '@tmagic/stage';
24
25
 
25
26
  import type { ComponentListService } from '@editor/services/componentList';
26
27
  import type { EditorService } from '@editor/services/editor';
@@ -45,6 +46,15 @@ export interface Services {
45
46
  uiService: UiService;
46
47
  }
47
48
 
49
+ export interface StageOptions {
50
+ runtimeUrl: string;
51
+ autoScrollIntoView: boolean;
52
+ render: () => HTMLDivElement;
53
+ moveableOptions: MoveableOptions | ((core?: StageCore) => MoveableOptions);
54
+ canSelect: (el: HTMLElement) => boolean | Promise<boolean>;
55
+ updateDragEl: (el: HTMLDivElement) => void;
56
+ }
57
+
48
58
  export interface StoreState {
49
59
  root: MApp | null;
50
60
  page: MPage | null;
@@ -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}
@@ -142,9 +93,13 @@ export const toRelative = (node: MNode) => {
142
93
 
143
94
  const setTop2Middle = (node: MNode, parentNode: MNode, stage: StageCore) => {
144
95
  const style = node.style || {};
145
- const height = style.height || 0;
96
+ let height = style.height || 0;
146
97
 
147
- if (!stage || typeof style.top !== 'undefined' || !parentNode.style || !isNumber(height)) return style;
98
+ if (!stage || typeof style.top !== 'undefined' || !parentNode.style) return style;
99
+
100
+ if (!isNumber(height)) {
101
+ height = 0;
102
+ }
148
103
 
149
104
  const { height: parentHeight } = parentNode.style;
150
105
 
@@ -1,22 +1,8 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
- *
6
- * Licensed under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License.
8
- * You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing, software
13
- * distributed under the License is distributed on an "AS IS" BASIS,
14
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
16
- * limitations under the License.
17
- */
18
-
19
1
  // serialize-javascript 依赖的 randombytes 依赖全局的 global 对象,因此此处需添加 global polyfill
20
- if (typeof (window as any).global === 'undefined') {
2
+ if (typeof global === 'undefined') {
21
3
  (window as any).global = window;
22
4
  }
5
+
6
+ if (typeof globalThis === 'undefined') {
7
+ (window as any).globalThis = window;
8
+ }
@@ -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,19 @@ export const DEFAULT_CONFIG: FormConfig = fillConfig([]);
229
243
  * @param type 组件类型
230
244
  * @returns Object
231
245
  */
232
- export const getDefaultPropsValue = (type: string) => ({
233
- type,
234
- id: generateId(type),
235
- style: {},
236
- name: type,
237
- });
246
+ export const getDefaultPropsValue = (type: string, id: string) =>
247
+ ['page', 'container'].includes(type)
248
+ ? {
249
+ type,
250
+ id,
251
+ layout: 'absolute',
252
+ style: {},
253
+ name: type,
254
+ items: [],
255
+ }
256
+ : {
257
+ type,
258
+ id,
259
+ style: {},
260
+ name: type,
261
+ };