@tmagic/editor 1.4.6 → 1.4.8

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 (158) hide show
  1. package/dist/style.css +1 -1
  2. package/dist/tmagic-editor.js +636 -589
  3. package/dist/tmagic-editor.umd.cjs +634 -586
  4. package/package.json +15 -11
  5. package/types/editorProps.d.ts +0 -7
  6. package/types/layouts/PropsPanel.vue.d.ts +9 -9
  7. package/types/layouts/sidebar/layer/use-click.d.ts +1 -1
  8. package/types/services/codeBlock.d.ts +2 -1
  9. package/types/services/dataSource.d.ts +2 -1
  10. package/types/services/dep.d.ts +12 -2
  11. package/types/services/editor.d.ts +22 -4
  12. package/types/services/props.d.ts +7 -6
  13. package/types/type.d.ts +6 -0
  14. package/types/utils/editor.d.ts +1 -0
  15. package/types/utils/idle-task.d.ts +14 -0
  16. package/types/utils/operator.d.ts +2 -2
  17. package/src/Editor.vue +0 -211
  18. package/src/components/CodeBlockEditor.vue +0 -268
  19. package/src/components/CodeParams.vue +0 -60
  20. package/src/components/ContentMenu.vue +0 -193
  21. package/src/components/FloatingBox.vue +0 -178
  22. package/src/components/Icon.vue +0 -27
  23. package/src/components/Resizer.vue +0 -23
  24. package/src/components/ScrollBar.vue +0 -151
  25. package/src/components/ScrollViewer.vue +0 -128
  26. package/src/components/SearchInput.vue +0 -37
  27. package/src/components/SplitView.vue +0 -186
  28. package/src/components/ToolButton.vue +0 -138
  29. package/src/components/Tree.vue +0 -71
  30. package/src/components/TreeNode.vue +0 -148
  31. package/src/editorProps.ts +0 -124
  32. package/src/fields/Code.vue +0 -50
  33. package/src/fields/CodeLink.vue +0 -80
  34. package/src/fields/CodeSelect.vue +0 -132
  35. package/src/fields/CodeSelectCol.vue +0 -139
  36. package/src/fields/DataSourceFieldSelect.vue +0 -149
  37. package/src/fields/DataSourceFields.vue +0 -323
  38. package/src/fields/DataSourceInput.vue +0 -325
  39. package/src/fields/DataSourceMethodSelect.vue +0 -153
  40. package/src/fields/DataSourceMethods.vue +0 -104
  41. package/src/fields/DataSourceMocks.vue +0 -255
  42. package/src/fields/DataSourceSelect.vue +0 -98
  43. package/src/fields/EventSelect.vue +0 -301
  44. package/src/fields/KeyValue.vue +0 -137
  45. package/src/fields/PageFragmentSelect.vue +0 -63
  46. package/src/fields/UISelect.vue +0 -135
  47. package/src/hooks/index.ts +0 -24
  48. package/src/hooks/use-code-block-edit.ts +0 -83
  49. package/src/hooks/use-data-source-edit.ts +0 -46
  50. package/src/hooks/use-data-source-method.ts +0 -100
  51. package/src/hooks/use-editor-content-height.ts +0 -26
  52. package/src/hooks/use-filter.ts +0 -55
  53. package/src/hooks/use-float-box.ts +0 -76
  54. package/src/hooks/use-getso.ts +0 -35
  55. package/src/hooks/use-next-float-box-position.ts +0 -29
  56. package/src/hooks/use-node-status.ts +0 -48
  57. package/src/hooks/use-stage.ts +0 -129
  58. package/src/hooks/use-window-rect.ts +0 -20
  59. package/src/icons/AppManageIcon.vue +0 -15
  60. package/src/icons/CenterIcon.vue +0 -13
  61. package/src/icons/CodeIcon.vue +0 -28
  62. package/src/icons/FolderMinusIcon.vue +0 -22
  63. package/src/icons/PinIcon.vue +0 -25
  64. package/src/icons/PinnedIcon.vue +0 -25
  65. package/src/index.ts +0 -118
  66. package/src/initService.ts +0 -447
  67. package/src/layouts/AddPageBox.vue +0 -55
  68. package/src/layouts/CodeEditor.vue +0 -226
  69. package/src/layouts/Framework.vue +0 -163
  70. package/src/layouts/NavMenu.vue +0 -200
  71. package/src/layouts/PropsPanel.vue +0 -130
  72. package/src/layouts/page-bar/AddButton.vue +0 -48
  73. package/src/layouts/page-bar/PageBar.vue +0 -159
  74. package/src/layouts/page-bar/PageBarScrollContainer.vue +0 -156
  75. package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
  76. package/src/layouts/sidebar/ComponentListPanel.vue +0 -134
  77. package/src/layouts/sidebar/Sidebar.vue +0 -278
  78. package/src/layouts/sidebar/code-block/CodeBlockList.vue +0 -142
  79. package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -70
  80. package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +0 -84
  81. package/src/layouts/sidebar/data-source/DataSourceList.vue +0 -160
  82. package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +0 -106
  83. package/src/layouts/sidebar/layer/LayerMenu.vue +0 -128
  84. package/src/layouts/sidebar/layer/LayerNodeTool.vue +0 -32
  85. package/src/layouts/sidebar/layer/LayerPanel.vue +0 -119
  86. package/src/layouts/sidebar/layer/use-click.ts +0 -110
  87. package/src/layouts/sidebar/layer/use-drag.ts +0 -161
  88. package/src/layouts/sidebar/layer/use-keybinding.ts +0 -54
  89. package/src/layouts/sidebar/layer/use-node-status.ts +0 -114
  90. package/src/layouts/workspace/Breadcrumb.vue +0 -35
  91. package/src/layouts/workspace/Workspace.vue +0 -46
  92. package/src/layouts/workspace/viewer/NodeListMenu.vue +0 -115
  93. package/src/layouts/workspace/viewer/Stage.vue +0 -246
  94. package/src/layouts/workspace/viewer/StageOverlay.vue +0 -68
  95. package/src/layouts/workspace/viewer/ViewerMenu.vue +0 -145
  96. package/src/services/BaseService.ts +0 -230
  97. package/src/services/codeBlock.ts +0 -324
  98. package/src/services/componentList.ts +0 -58
  99. package/src/services/dataSource.ts +0 -209
  100. package/src/services/dep.ts +0 -80
  101. package/src/services/editor.ts +0 -1087
  102. package/src/services/events.ts +0 -93
  103. package/src/services/history.ts +0 -126
  104. package/src/services/keybinding.ts +0 -220
  105. package/src/services/props.ts +0 -265
  106. package/src/services/stageOverlay.ts +0 -212
  107. package/src/services/storage.ts +0 -155
  108. package/src/services/ui.ts +0 -156
  109. package/src/shims-vue.d.ts +0 -6
  110. package/src/theme/breadcrumb.scss +0 -6
  111. package/src/theme/code-block.scss +0 -6
  112. package/src/theme/code-editor.scss +0 -38
  113. package/src/theme/common/var.scss +0 -14
  114. package/src/theme/component-list-panel.scss +0 -95
  115. package/src/theme/content-menu.scss +0 -76
  116. package/src/theme/data-source-field.scss +0 -12
  117. package/src/theme/data-source-fields.scss +0 -13
  118. package/src/theme/data-source-input.scss +0 -18
  119. package/src/theme/data-source-methods.scss +0 -13
  120. package/src/theme/data-source.scss +0 -28
  121. package/src/theme/event.scss +0 -37
  122. package/src/theme/floating-box.scss +0 -32
  123. package/src/theme/framework.scss +0 -69
  124. package/src/theme/icon.scss +0 -12
  125. package/src/theme/index.scss +0 -10
  126. package/src/theme/key-value.scss +0 -20
  127. package/src/theme/layer-panel.scss +0 -26
  128. package/src/theme/layout.scss +0 -9
  129. package/src/theme/nav-menu.scss +0 -78
  130. package/src/theme/page-bar.scss +0 -89
  131. package/src/theme/page-fragment-select.scss +0 -14
  132. package/src/theme/props-panel.scss +0 -55
  133. package/src/theme/resizer.scss +0 -66
  134. package/src/theme/ruler.scss +0 -38
  135. package/src/theme/search-input.scss +0 -14
  136. package/src/theme/sidebar.scss +0 -79
  137. package/src/theme/stage.scss +0 -76
  138. package/src/theme/theme.scss +0 -27
  139. package/src/theme/tree.scss +0 -89
  140. package/src/theme/workspace.scss +0 -9
  141. package/src/type.ts +0 -746
  142. package/src/utils/compose.ts +0 -52
  143. package/src/utils/config.ts +0 -29
  144. package/src/utils/content-menu.ts +0 -95
  145. package/src/utils/data-source/formConfigs/base.ts +0 -30
  146. package/src/utils/data-source/formConfigs/http.ts +0 -60
  147. package/src/utils/data-source/index.ts +0 -236
  148. package/src/utils/editor.ts +0 -294
  149. package/src/utils/index.ts +0 -24
  150. package/src/utils/keybinding-config.ts +0 -125
  151. package/src/utils/logger.ts +0 -47
  152. package/src/utils/monaco-editor.ts +0 -8
  153. package/src/utils/operator.ts +0 -106
  154. package/src/utils/props.ts +0 -504
  155. package/src/utils/scroll-viewer.ts +0 -165
  156. package/src/utils/tree.ts +0 -15
  157. package/src/utils/undo-redo.ts +0 -76
  158. package/tsconfig.build.json +0 -16
@@ -1,294 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 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
- import serialize from 'serialize-javascript';
20
-
21
- import type { Id, MApp, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
22
- import { NodeType } from '@tmagic/schema';
23
- import type StageCore from '@tmagic/stage';
24
- import { calcValueByFontsize, getNodePath, isNumber, isPage, isPageFragment, isPop } from '@tmagic/utils';
25
-
26
- import { Layout } from '@editor/type';
27
- export const COPY_STORAGE_KEY = '$MagicEditorCopyData';
28
- export const COPY_CODE_STORAGE_KEY = '$MagicEditorCopyCode';
29
- export const COPY_DS_STORAGE_KEY = '$MagicEditorCopyDataSource';
30
-
31
- /**
32
- * 获取所有页面配置
33
- * @param root DSL跟节点
34
- * @returns 所有页面配置
35
- */
36
- export const getPageList = (root?: MApp | null): MPage[] => {
37
- if (!root) return [];
38
- if (!Array.isArray(root.items)) return [];
39
- return root.items.filter((item) => isPage(item)) as MPage[];
40
- };
41
-
42
- export const getPageFragmentList = (root?: MApp | null): MPageFragment[] => {
43
- if (!root) return [];
44
- if (!Array.isArray(root.items)) return [];
45
- return root.items.filter((item) => isPageFragment(item)) as MPageFragment[];
46
- };
47
-
48
- /**
49
- * 获取所有页面名称
50
- * @param pages 所有页面配置
51
- * @returns 所有页面名称
52
- */
53
- export const getPageNameList = (pages: (MPage | MPageFragment)[]): string[] =>
54
- pages.map((page) => page.name || 'index');
55
-
56
- /**
57
- * 新增页面时,生成页面名称
58
- * @param {Object} pageNameList 所有页面名称
59
- * @returns {string}
60
- */
61
- export const generatePageName = (pageNameList: string[], type: NodeType.PAGE | NodeType.PAGE_FRAGMENT): string => {
62
- let pageLength = pageNameList.length;
63
-
64
- if (!pageLength) return `${type}_index`;
65
-
66
- let pageName = `${type}_${pageLength}`;
67
- while (pageNameList.includes(pageName)) {
68
- pageLength += 1;
69
- pageName = `${type}_${pageLength}`;
70
- }
71
-
72
- return pageName;
73
- };
74
-
75
- /**
76
- * 新增页面时,生成页面名称
77
- * @param {Object} app 所有页面配置
78
- * @returns {string}
79
- */
80
- export const generatePageNameByApp = (app: MApp, type: NodeType.PAGE | NodeType.PAGE_FRAGMENT): string =>
81
- generatePageName(getPageNameList(type === 'page' ? getPageList(app) : getPageFragmentList(app)), type);
82
-
83
- /**
84
- * @param {Object} node
85
- * @returns {boolean}
86
- */
87
- export const isFixed = (node: MNode): boolean => node.style?.position === 'fixed';
88
-
89
- export const getNodeIndex = (id: Id, parent: MContainer | MApp): number => {
90
- const items = parent?.items || [];
91
- return items.findIndex((item: MNode) => `${item.id}` === `${id}`);
92
- };
93
-
94
- export const getRelativeStyle = (style: Record<string, any> = {}): Record<string, any> => ({
95
- ...style,
96
- position: 'relative',
97
- top: 0,
98
- left: 0,
99
- });
100
-
101
- const getMiddleTop = (node: MNode, parentNode: MNode, stage: StageCore | null) => {
102
- let height = node.style?.height || 0;
103
-
104
- if (!stage || typeof node.style?.top !== 'undefined' || !parentNode.style) return node.style?.top;
105
-
106
- if (!isNumber(height)) {
107
- height = 0;
108
- }
109
-
110
- const { height: parentHeight } = parentNode.style;
111
- // wrapperHeight 是未 calcValue的高度, 所以要将其calcValueByFontsize一下, 否则在pad or pc端计算的结果有误
112
- const { scrollTop = 0, wrapperHeight } = stage.mask;
113
- const wrapperHeightDeal = calcValueByFontsize(stage.renderer.getDocument()!, wrapperHeight);
114
- const scrollTopDeal = calcValueByFontsize(stage.renderer.getDocument()!, scrollTop);
115
- if (isPage(parentNode)) {
116
- return (wrapperHeightDeal - height) / 2 + scrollTopDeal;
117
- }
118
-
119
- // 如果容器的元素高度大于当前视口高度的2倍, 添加的元素居中位置也会看不见, 所以要取最小值计算
120
- return (Math.min(parentHeight, wrapperHeightDeal) - height) / 2;
121
- };
122
-
123
- export const getInitPositionStyle = (style: Record<string, any> = {}, layout: Layout) => {
124
- if (layout === Layout.ABSOLUTE) {
125
- const newStyle: Record<string, any> = {
126
- ...style,
127
- position: 'absolute',
128
- };
129
-
130
- if (typeof newStyle.left === 'undefined' && typeof newStyle.right === 'undefined') {
131
- newStyle.left = 0;
132
- }
133
-
134
- return newStyle;
135
- }
136
-
137
- if (layout === Layout.RELATIVE) {
138
- return getRelativeStyle(style);
139
- }
140
-
141
- return style;
142
- };
143
-
144
- export const setChildrenLayout = (node: MContainer, layout: Layout) => {
145
- node.items?.forEach((child: MNode) => {
146
- setLayout(child, layout);
147
- });
148
- return node;
149
- };
150
-
151
- export const setLayout = (node: MNode, layout: Layout) => {
152
- if (isPop(node)) return;
153
-
154
- const style = node.style || {};
155
-
156
- // 是 fixed 不做处理
157
- if (style.position === 'fixed') return;
158
-
159
- if (layout !== Layout.RELATIVE) {
160
- style.position = 'absolute';
161
- } else {
162
- node.style = getRelativeStyle(style);
163
- node.style.right = 'auto';
164
- node.style.bottom = 'auto';
165
- }
166
- return node;
167
- };
168
-
169
- export const change2Fixed = (node: MNode, root: MApp) => {
170
- const path = getNodePath(node.id, root.items);
171
- const offset = {
172
- left: 0,
173
- top: 0,
174
- };
175
-
176
- path.forEach((value) => {
177
- offset.left = offset.left + globalThis.parseFloat(value.style?.left || 0);
178
- offset.top = offset.top + globalThis.parseFloat(value.style?.top || 0);
179
- });
180
-
181
- return {
182
- ...(node.style || {}),
183
- ...offset,
184
- };
185
- };
186
-
187
- export const Fixed2Other = async (
188
- node: MNode,
189
- root: MApp,
190
- getLayout: (parent: MNode, node?: MNode) => Promise<Layout>,
191
- ) => {
192
- const path = getNodePath(node.id, root.items);
193
- const cur = path.pop();
194
- const offset = {
195
- left: cur?.style?.left || 0,
196
- top: cur?.style?.top || 0,
197
- right: '',
198
- bottom: '',
199
- };
200
-
201
- path.forEach((value) => {
202
- offset.left = offset.left - globalThis.parseFloat(value.style?.left || 0);
203
- offset.top = offset.top - globalThis.parseFloat(value.style?.top || 0);
204
- });
205
- const style = node.style || {};
206
-
207
- const parent = path.pop();
208
- if (!parent) {
209
- return getRelativeStyle(style);
210
- }
211
-
212
- const layout = await getLayout(parent);
213
- if (layout !== Layout.RELATIVE) {
214
- return {
215
- ...style,
216
- ...offset,
217
- position: 'absolute',
218
- };
219
- }
220
-
221
- return getRelativeStyle(style);
222
- };
223
-
224
- export const getGuideLineFromCache = (key: string): number[] => {
225
- if (!key) return [];
226
-
227
- const guideLineCacheData = globalThis.localStorage.getItem(key);
228
- if (guideLineCacheData) {
229
- try {
230
- return JSON.parse(guideLineCacheData) || [];
231
- } catch (e) {
232
- console.error(e);
233
- }
234
- }
235
-
236
- return [];
237
- };
238
-
239
- export const fixNodeLeft = (config: MNode, parent: MContainer, doc?: Document) => {
240
- if (!doc || !config.style || !isNumber(config.style.left)) return config.style?.left;
241
-
242
- const el = doc.getElementById(`${config.id}`);
243
- const parentEl = doc.getElementById(`${parent.id}`);
244
-
245
- const left = Number(config.style?.left) || 0;
246
- if (el && parentEl) {
247
- const calcParentOffsetWidth = calcValueByFontsize(doc, parentEl.offsetWidth);
248
- const calcElOffsetWidth = calcValueByFontsize(doc, el.offsetWidth);
249
- if (calcElOffsetWidth + left > calcParentOffsetWidth) {
250
- return calcParentOffsetWidth - calcElOffsetWidth;
251
- }
252
- }
253
-
254
- return config.style.left;
255
- };
256
-
257
- export const fixNodePosition = (config: MNode, parent: MContainer, stage: StageCore | null) => {
258
- if (config.style?.position !== 'absolute') {
259
- return config.style;
260
- }
261
-
262
- return {
263
- ...(config.style || {}),
264
- top: getMiddleTop(config, parent, stage),
265
- left: fixNodeLeft(config, parent, stage?.renderer.contentWindow?.document),
266
- };
267
- };
268
-
269
- // 序列化配置
270
- export const serializeConfig = (config: any) =>
271
- serialize(config, {
272
- space: 2,
273
- unsafe: true,
274
- }).replace(/"(\w+)":\s/g, '$1: ');
275
-
276
- export interface NodeItem {
277
- items?: NodeItem[];
278
- [key: string]: any;
279
- }
280
-
281
- export const traverseNode = <T extends NodeItem = NodeItem>(
282
- node: T,
283
- cb: (node: T, parents: T[]) => void,
284
- parents: T[] = [],
285
- ) => {
286
- cb(node, parents);
287
-
288
- if (node.items?.length) {
289
- parents.push(node);
290
- node.items.forEach((item) => {
291
- traverseNode(item as T, cb, [...parents]);
292
- });
293
- }
294
- };
@@ -1,24 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 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
- export * from './config';
20
- export * from './props';
21
- export * from './logger';
22
- export * from './editor';
23
- export * from './operator';
24
- export * from './data-source';
@@ -1,125 +0,0 @@
1
- import { KeyBindingCommand, KeyBindingItem } from '@editor/type';
2
-
3
- export enum KeyBindingContainerKey {
4
- STAGE = 'stage',
5
- LAYER_PANEL = 'layer-panel',
6
- }
7
-
8
- export default [
9
- {
10
- command: KeyBindingCommand.DELETE_NODE,
11
- keybinding: ['delete', 'backspace'],
12
- when: [
13
- [KeyBindingContainerKey.STAGE, 'keyup'],
14
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
15
- ],
16
- },
17
- {
18
- command: KeyBindingCommand.COPY_NODE,
19
- keybinding: 'ctrl+c',
20
- when: [
21
- [KeyBindingContainerKey.STAGE, 'keydown'],
22
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
23
- ],
24
- },
25
- {
26
- command: KeyBindingCommand.PASTE_NODE,
27
- keybinding: 'ctrl+v',
28
- when: [
29
- [KeyBindingContainerKey.STAGE, 'keydown'],
30
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
31
- ],
32
- },
33
- {
34
- command: KeyBindingCommand.CUT_NODE,
35
- keybinding: 'ctrl+x',
36
- when: [
37
- [KeyBindingContainerKey.STAGE, 'keydown'],
38
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
39
- ],
40
- },
41
- {
42
- command: KeyBindingCommand.UNDO,
43
- keybinding: 'ctrl+z',
44
- when: [
45
- [KeyBindingContainerKey.STAGE, 'keydown'],
46
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
47
- ],
48
- },
49
- {
50
- command: KeyBindingCommand.REDO,
51
- keybinding: 'ctrl+shift+z',
52
- when: [
53
- [KeyBindingContainerKey.STAGE, 'keydown'],
54
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
55
- ],
56
- },
57
- {
58
- command: KeyBindingCommand.MOVE_UP_1,
59
- keybinding: 'up',
60
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
61
- },
62
- {
63
- command: KeyBindingCommand.MOVE_DOWN_1,
64
- keybinding: 'down',
65
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
66
- },
67
- {
68
- command: KeyBindingCommand.MOVE_LEFT_1,
69
- keybinding: 'left',
70
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
71
- },
72
- {
73
- command: KeyBindingCommand.MOVE_RIGHT_1,
74
- keybinding: 'right',
75
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
76
- },
77
- {
78
- command: KeyBindingCommand.MOVE_UP_10,
79
- keybinding: 'ctrl+up',
80
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
81
- },
82
- {
83
- command: KeyBindingCommand.MOVE_DOWN_10,
84
- keybinding: 'ctrl+down',
85
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
86
- },
87
- {
88
- command: KeyBindingCommand.MOVE_LEFT_10,
89
- keybinding: 'ctrl+left',
90
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
91
- },
92
- {
93
- command: KeyBindingCommand.MOVE_RIGHT_10,
94
- keybinding: 'ctrl+right',
95
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
96
- },
97
- {
98
- command: KeyBindingCommand.SWITCH_NODE,
99
- keybinding: 'tab',
100
- when: [
101
- [KeyBindingContainerKey.STAGE, 'keydown'],
102
- [KeyBindingContainerKey.LAYER_PANEL, 'keydown'],
103
- ],
104
- },
105
- {
106
- command: KeyBindingCommand.ZOOM_IN,
107
- keybinding: ['ctrl+=', 'ctrl+numpadplus'],
108
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
109
- },
110
- {
111
- command: KeyBindingCommand.ZOOM_OUT,
112
- keybinding: ['ctrl+-', 'ctrl+numpad-'],
113
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
114
- },
115
- {
116
- command: KeyBindingCommand.ZOOM_FIT,
117
- keybinding: 'ctrl+0',
118
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
119
- },
120
- {
121
- command: KeyBindingCommand.ZOOM_RESET,
122
- keybinding: 'ctrl+1',
123
- when: [[KeyBindingContainerKey.STAGE, 'keydown']],
124
- },
125
- ] as KeyBindingItem[];
@@ -1,47 +0,0 @@
1
- /*
2
- * Tencent is pleased to support the open source community by making TMagicEditor available.
3
- *
4
- * Copyright (C) 2023 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
- export const log = (...args: any[]) => {
20
- if (process.env.NODE_ENV === 'development') {
21
- console.log('magic editor: ', ...args);
22
- }
23
- };
24
-
25
- export const info = (...args: any[]) => {
26
- if (process.env.NODE_ENV === 'development') {
27
- console.info('magic editor: ', ...args);
28
- }
29
- };
30
-
31
- export const warn = (...args: any[]) => {
32
- if (process.env.NODE_ENV === 'development') {
33
- console.warn('magic editor: ', ...args);
34
- }
35
- };
36
-
37
- export const debug = (...args: any[]) => {
38
- if (process.env.NODE_ENV === 'development') {
39
- console.debug('magic editor: ', ...args);
40
- }
41
- };
42
-
43
- export const error = (...args: any[]) => {
44
- if (process.env.NODE_ENV === 'development') {
45
- console.error('magic editor: ', ...args);
46
- }
47
- };
@@ -1,8 +0,0 @@
1
- import { emmetCSS, emmetHTML } from 'emmet-monaco-es';
2
- import * as monaco from 'monaco-editor';
3
-
4
- // 注册emmet插件
5
- emmetHTML(monaco);
6
- emmetCSS(monaco, ['css', 'scss']);
7
-
8
- export default monaco;
@@ -1,106 +0,0 @@
1
- import { toRaw } from 'vue';
2
- import { isEmpty } from 'lodash-es';
3
-
4
- import { Id, MContainer, MNode, NodeType } from '@tmagic/schema';
5
- import { isPage, isPageFragment } from '@tmagic/utils';
6
-
7
- import editorService from '@editor/services/editor';
8
- import propsService from '@editor/services/props';
9
- import type { AddMNode, PastePosition } from '@editor/type';
10
- import { generatePageNameByApp, getInitPositionStyle } from '@editor/utils/editor';
11
-
12
- /**
13
- * 粘贴前置操作:返回分配了新id以及校准了坐标的配置
14
- * @param position 粘贴的坐标
15
- * @param config 待粘贴的元素配置(复制时保存的那份配置)
16
- * @returns
17
- */
18
- export const beforePaste = (position: PastePosition, config: MNode[]): MNode[] => {
19
- if (!config[0]?.style) return config;
20
- const curNode = editorService.get('node');
21
- // 将数组中第一个元素的坐标作为参照点
22
- const { left: referenceLeft, top: referenceTop } = config[0].style;
23
- // 坐标校准后的粘贴数据
24
- const pasteConfigs: MNode[] = config.map((configItem: MNode): MNode => {
25
- // 解构 position 对象,从 position 删除 offsetX、offsetY字段
26
- const { offsetX = 0, offsetY = 0, ...positionClone } = position;
27
- let pastePosition = positionClone;
28
-
29
- if (!isEmpty(pastePosition) && curNode?.items) {
30
- // 如果没有传入粘贴坐标则可能为键盘操作,不再转换
31
- // 如果粘贴时选中了容器,则将元素粘贴到容器内,坐标需要转换为相对于容器的坐标
32
- pastePosition = getPositionInContainer(pastePosition, curNode.id);
33
- }
34
-
35
- // 将所有待粘贴元素坐标相对于多选第一个元素坐标重新计算,以保证多选粘贴后元素间距不变
36
- if (pastePosition.left && configItem.style?.left) {
37
- pastePosition.left = configItem.style.left - referenceLeft + pastePosition.left;
38
- }
39
- if (pastePosition.top && configItem.style?.top) {
40
- pastePosition.top = configItem.style?.top - referenceTop + pastePosition.top;
41
- }
42
- const pasteConfig = propsService.setNewItemId(configItem, false);
43
-
44
- if (pasteConfig.style) {
45
- const { left, top } = pasteConfig.style;
46
- // 判断能转换为数字时,做粘贴偏移量计算
47
- if (typeof left === 'number' || (!!left && !isNaN(Number(left)))) {
48
- pasteConfig.style.left = Number(left) + offsetX;
49
- }
50
- if (typeof top === 'number' || (!!top && !isNaN(Number(top)))) {
51
- pasteConfig.style.top = Number(top) + offsetY;
52
- }
53
-
54
- pasteConfig.style = {
55
- ...pasteConfig.style,
56
- ...pastePosition,
57
- };
58
- }
59
- const root = editorService.get('root');
60
- if ((isPage(pasteConfig) || isPageFragment(pasteConfig)) && root) {
61
- pasteConfig.name = generatePageNameByApp(root, isPage(pasteConfig) ? NodeType.PAGE : NodeType.PAGE_FRAGMENT);
62
- }
63
- return pasteConfig as MNode;
64
- });
65
- return pasteConfigs;
66
- };
67
-
68
- /**
69
- * 将元素粘贴到容器内时,将相对于画布坐标转换为相对于容器的坐标
70
- * @param position PastePosition 粘贴时相对于画布的坐标
71
- * @param id 元素id
72
- * @returns PastePosition 转换后的坐标
73
- */
74
- export const getPositionInContainer = (position: PastePosition = {}, id: Id) => {
75
- let { left = 0, top = 0 } = position;
76
- const parentEl = editorService.get('stage')?.renderer?.contentWindow?.document.getElementById(`${id}`);
77
- const parentElRect = parentEl?.getBoundingClientRect();
78
- left = left - (parentElRect?.left || 0);
79
- top = top - (parentElRect?.top || 0);
80
- return {
81
- left,
82
- top,
83
- };
84
- };
85
-
86
- export const getAddParent = (node: MNode) => {
87
- const curNode = editorService.get('node');
88
-
89
- let parentNode;
90
- if (isPage(node)) {
91
- parentNode = editorService.get('root');
92
- } else if (curNode?.items) {
93
- parentNode = curNode as MContainer;
94
- } else if (curNode?.id) {
95
- parentNode = editorService.getParentById(curNode.id, false);
96
- }
97
- return parentNode;
98
- };
99
-
100
- export const getDefaultConfig = async (addNode: AddMNode, parentNode: MContainer) => {
101
- const { type, inputEvent, ...config } = addNode;
102
- const layout = await editorService.getLayout(toRaw(parentNode), addNode as MNode);
103
- const newNode = { ...toRaw(await propsService.getPropsValue(type, config)) };
104
- newNode.style = getInitPositionStyle(newNode.style, layout);
105
- return newNode;
106
- };