@tmagic/editor 1.0.0-rc.1 → 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 (62) hide show
  1. package/coverage/clover.xml +94 -98
  2. package/coverage/coverage-final.json +4 -4
  3. package/coverage/lcov-report/index.html +35 -35
  4. package/coverage/lcov-report/src/Editor.vue.html +24 -9
  5. package/coverage/lcov-report/src/components/ContentMenu.vue.html +1 -1
  6. package/coverage/lcov-report/src/components/Icon.vue.html +1 -1
  7. package/coverage/lcov-report/src/components/ScrollViewer.vue.html +1 -1
  8. package/coverage/lcov-report/src/components/ToolButton.vue.html +1 -1
  9. package/coverage/lcov-report/src/components/index.html +1 -1
  10. package/coverage/lcov-report/src/index.html +14 -14
  11. package/coverage/lcov-report/src/layouts/AddPageBox.vue.html +1 -1
  12. package/coverage/lcov-report/src/layouts/Framework.vue.html +48 -9
  13. package/coverage/lcov-report/src/layouts/NavMenu.vue.html +1 -1
  14. package/coverage/lcov-report/src/layouts/PropsPanel.vue.html +2 -2
  15. package/coverage/lcov-report/src/layouts/Resizer.vue.html +1 -1
  16. package/coverage/lcov-report/src/layouts/index.html +15 -15
  17. package/coverage/lcov-report/src/layouts/sidebar/ComponentListPanel.vue.html +1 -1
  18. package/coverage/lcov-report/src/layouts/sidebar/LayerMenu.vue.html +1 -1
  19. package/coverage/lcov-report/src/layouts/sidebar/LayerPanel.vue.html +1 -1
  20. package/coverage/lcov-report/src/layouts/sidebar/Sidebar.vue.html +1 -1
  21. package/coverage/lcov-report/src/layouts/sidebar/TabPane.vue.html +1 -1
  22. package/coverage/lcov-report/src/layouts/sidebar/index.html +1 -1
  23. package/coverage/lcov-report/src/layouts/workspace/PageBar.vue.html +1 -1
  24. package/coverage/lcov-report/src/layouts/workspace/Stage.vue.html +7 -4
  25. package/coverage/lcov-report/src/layouts/workspace/ViewerMenu.vue.html +1 -1
  26. package/coverage/lcov-report/src/layouts/workspace/Workspace.vue.html +68 -56
  27. package/coverage/lcov-report/src/layouts/workspace/index.html +21 -21
  28. package/coverage/lcov-report/src/services/BaseService.ts.html +1 -1
  29. package/coverage/lcov-report/src/services/componentList.ts.html +1 -1
  30. package/coverage/lcov-report/src/services/editor.ts.html +1 -1
  31. package/coverage/lcov-report/src/services/events.ts.html +1 -1
  32. package/coverage/lcov-report/src/services/history.ts.html +1 -1
  33. package/coverage/lcov-report/src/services/index.html +1 -1
  34. package/coverage/lcov-report/src/services/props.ts.html +1 -1
  35. package/coverage/lcov-report/src/services/ui.ts.html +1 -1
  36. package/coverage/lcov-report/src/type.ts.html +1 -1
  37. package/coverage/lcov-report/src/utils/compose.ts.html +1 -1
  38. package/coverage/lcov-report/src/utils/config.ts.html +1 -1
  39. package/coverage/lcov-report/src/utils/editor.ts.html +1 -1
  40. package/coverage/lcov-report/src/utils/index.html +1 -1
  41. package/coverage/lcov-report/src/utils/index.ts.html +1 -1
  42. package/coverage/lcov-report/src/utils/logger.ts.html +1 -1
  43. package/coverage/lcov-report/src/utils/props.ts.html +1 -1
  44. package/coverage/lcov-report/src/utils/scroll-viewer.ts.html +1 -1
  45. package/coverage/lcov-report/src/utils/undo-redo.ts.html +1 -1
  46. package/coverage/lcov.info +314 -275
  47. package/dist/style.css +3 -3
  48. package/dist/tmagic-editor.es.js +60 -1256
  49. package/dist/tmagic-editor.es.js.map +1 -1
  50. package/dist/tmagic-editor.umd.js +62 -1258
  51. package/dist/tmagic-editor.umd.js.map +1 -1
  52. package/dist/types/src/Editor.vue.d.ts +9 -0
  53. package/dist/types/src/layouts/Framework.vue.d.ts +15 -3
  54. package/package.json +16 -8
  55. package/src/Editor.vue +6 -1
  56. package/src/layouts/CodeEditor.vue +1 -4
  57. package/src/layouts/Framework.vue +14 -1
  58. package/src/layouts/PropsPanel.vue +1 -1
  59. package/src/layouts/workspace/Stage.vue +1 -0
  60. package/src/layouts/workspace/Workspace.vue +37 -33
  61. package/src/theme/props-panel.scss +6 -4
  62. package/src/utils/polyfills.ts +5 -19
@@ -63,6 +63,10 @@ declare const _default: DefineComponent<{
63
63
  stageRect: {
64
64
  type: PropType<StageRect>;
65
65
  };
66
+ codeOptions: {
67
+ type: ObjectConstructor;
68
+ default: () => {};
69
+ };
66
70
  }, Services, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ("props-panel-mounted" | "update:modelValue")[], "props-panel-mounted" | "update:modelValue", VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
67
71
  /** 页面初始值 */
68
72
  modelValue: {
@@ -122,11 +126,16 @@ declare const _default: DefineComponent<{
122
126
  stageRect: {
123
127
  type: PropType<StageRect>;
124
128
  };
129
+ codeOptions: {
130
+ type: ObjectConstructor;
131
+ default: () => {};
132
+ };
125
133
  }>> & {
126
134
  "onProps-panel-mounted"?: ((...args: any[]) => any) | undefined;
127
135
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
128
136
  }, {
129
137
  menu: MenuBarData;
138
+ codeOptions: Record<string, any>;
130
139
  modelValue: MApp;
131
140
  componentGroupList: ComponentGroup[];
132
141
  propsConfigs: Record<string, FormConfig>;
@@ -1,11 +1,23 @@
1
- import type { DefineComponent, ComputedRef, ComponentOptionsMixin, EmitsOptions, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
1
+ import type { DefineComponent, ComputedRef, ComponentOptionsMixin, VNodeProps, AllowedComponentProps, ComponentCustomProps, ExtractPropTypes } from 'vue';
2
2
  import type { MApp } from '@tmagic/schema';
3
3
  import { GetColumnWidth } from '../type';
4
- declare const _default: DefineComponent<{}, {
4
+ declare const _default: DefineComponent<{
5
+ codeOptions: {
6
+ type: ObjectConstructor;
7
+ default: () => {};
8
+ };
9
+ }, {
5
10
  root: ComputedRef<MApp | undefined>;
6
11
  pageLength: ComputedRef<number>;
7
12
  showSrc: ComputedRef<boolean | undefined>;
8
13
  columnWidth: ComputedRef<GetColumnWidth | undefined>;
9
14
  saveCode(value: string): void;
10
- }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{}>>, {}>;
15
+ }, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, Record<string, any>, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes<{
16
+ codeOptions: {
17
+ type: ObjectConstructor;
18
+ default: () => {};
19
+ };
20
+ }>>, {
21
+ codeOptions: Record<string, any>;
22
+ }>;
11
23
  export default _default;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-rc.1",
2
+ "version": "1.0.0-rc.2",
3
3
  "name": "@tmagic/editor",
4
4
  "sideEffects": [
5
5
  "dist/*",
@@ -43,25 +43,32 @@
43
43
  "typescript"
44
44
  ],
45
45
  "dependencies": {
46
+ "@babel/core": "^7.18.0",
46
47
  "@element-plus/icons": "0.0.11",
47
- "@tmagic/core": "^1.0.0-rc.1",
48
- "@tmagic/form": "^1.0.0-rc.1",
49
- "@tmagic/schema": "^1.0.0-rc.1",
50
- "@tmagic/stage": "^1.0.0-rc.1",
51
- "@tmagic/utils": "^1.0.0-rc.1",
48
+ "@tmagic/core": "^1.0.0-rc.2",
49
+ "@tmagic/form": "^1.0.0-rc.2",
50
+ "@tmagic/schema": "^1.0.0-rc.2",
51
+ "@tmagic/stage": "^1.0.0-rc.2",
52
+ "@tmagic/utils": "^1.0.0-rc.2",
52
53
  "buffer": "^6.0.3",
53
54
  "color": "^3.1.3",
54
55
  "element-plus": "^2.2.0",
55
56
  "events": "^3.3.0",
57
+ "gesto": "^1.7.0",
56
58
  "keycon": "^1.1.2",
57
59
  "lodash-es": "^4.17.21",
58
60
  "monaco-editor": "^0.32.1",
59
61
  "serialize-javascript": "^6.0.0",
60
62
  "vue": "^3.2.0"
61
63
  },
64
+ "peerDependencies": {
65
+ "@tmagic/form": "^1.0.0-rc.1",
66
+ "element-plus": "^2.2.0",
67
+ "vue": "^3.2.0"
68
+ },
62
69
  "devDependencies": {
63
70
  "@types/events": "^3.0.0",
64
- "@types/jest": "^26.0.23",
71
+ "@types/jest": "^27.5.1",
65
72
  "@types/lodash-es": "^4.17.4",
66
73
  "@types/node": "^15.12.4",
67
74
  "@types/serialize-javascript": "^5.0.1",
@@ -70,6 +77,7 @@
70
77
  "@vue/compiler-sfc": "^3.2.0",
71
78
  "@vue/test-utils": "^2.0.0-rc.20",
72
79
  "@vue/vue3-jest": "^27.0.0-alpha.4",
80
+ "babel-jest": "^27.0.6",
73
81
  "jest": "^27.5.1",
74
82
  "jest-serializer-vue": "^2.0.2",
75
83
  "jest-transform-stub": "^2.0.0",
@@ -80,5 +88,5 @@
80
88
  "vite-plugin-dts": "^0.9.6",
81
89
  "vue-tsc": "^0.0.24"
82
90
  },
83
- "gitHead": "3b647794d087888bfec9772f54356fa48c0b6d90"
91
+ "gitHead": "3e309780ed33640ab3fc986a93dd0e7b15c167e5"
84
92
  }
package/src/Editor.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <framework>
2
+ <framework :code-options="codeOptions">
3
3
  <template #nav>
4
4
  <slot name="nav" :editorService="editorService"><nav-menu :data="menu"></nav-menu></slot>
5
5
  </template>
@@ -136,6 +136,11 @@ export default defineComponent({
136
136
  stageRect: {
137
137
  type: [String, Object] as PropType<StageRect>,
138
138
  },
139
+
140
+ codeOptions: {
141
+ type: Object,
142
+ default: () => ({}),
143
+ },
139
144
  },
140
145
 
141
146
  emits: ['props-panel-mounted', 'update:modelValue'],
@@ -94,11 +94,7 @@ export default defineComponent({
94
94
  const options = {
95
95
  value: values.value,
96
96
  language: props.language,
97
- tabSize: 2,
98
97
  theme: 'vs-dark',
99
- fontFamily: 'dm, Menlo, Monaco, "Courier New", monospace',
100
- fontSize: 14,
101
- formatOnPaste: true,
102
98
  ...props.options,
103
99
  };
104
100
 
@@ -117,6 +113,7 @@ export default defineComponent({
117
113
  codeEditor.value.addEventListener('keydown', (e) => {
118
114
  if (e.keyCode === 83 && (navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey)) {
119
115
  e.preventDefault();
116
+ e.stopPropagation();
120
117
  emit('save', getEditorValue());
121
118
  }
122
119
  });
@@ -2,7 +2,13 @@
2
2
  <div class="m-editor">
3
3
  <slot name="nav" class="m-editor-nav-menu"></slot>
4
4
 
5
- <magic-code-editor v-if="showSrc" class="m-editor-content" :init-values="root" @save="saveCode"></magic-code-editor>
5
+ <magic-code-editor
6
+ v-if="showSrc"
7
+ class="m-editor-content"
8
+ :init-values="root"
9
+ :options="codeOptions"
10
+ @save="saveCode"
11
+ ></magic-code-editor>
6
12
 
7
13
  <div class="m-editor-content" v-else>
8
14
  <div class="m-editor-framework-left" :style="`width: ${columnWidth?.left}px`">
@@ -48,6 +54,13 @@ export default defineComponent({
48
54
  Resizer,
49
55
  },
50
56
 
57
+ props: {
58
+ codeOptions: {
59
+ type: Object,
60
+ default: () => ({}),
61
+ },
62
+ },
63
+
51
64
  setup() {
52
65
  const { editorService, uiService } = inject<Services>('services') || {};
53
66
 
@@ -1,7 +1,7 @@
1
1
  <template>
2
2
  <m-form
3
3
  :class="`m-editor-props-panel ${propsPanelSize}`"
4
- popper-class="m-editor-props-panel-popper"
4
+ :popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
5
5
  ref="configForm"
6
6
  :size="propsPanelSize"
7
7
  :init-values="values"
@@ -209,6 +209,7 @@ export default defineComponent({
209
209
  const { scrollTop, scrollLeft } = stage.mask;
210
210
  if (layout === Layout.ABSOLUTE) {
211
211
  config.style = {
212
+ ...(config.style || {}),
212
213
  position: 'absolute',
213
214
  top: e.clientY - containerRect.top + scrollTop,
214
215
  left: e.clientX - containerRect.left + scrollLeft,
@@ -65,8 +65,13 @@ export default defineComponent({
65
65
  workspace.value?.focus();
66
66
  };
67
67
 
68
+ const mouseleaveHandler = () => {
69
+ workspace.value?.blur();
70
+ };
71
+
68
72
  onMounted(() => {
69
73
  workspace.value?.addEventListener('mouseenter', mouseenterHandler);
74
+ workspace.value?.addEventListener('mouseleave', mouseleaveHandler);
70
75
 
71
76
  keycon = new KeyController(workspace.value);
72
77
 
@@ -75,85 +80,84 @@ export default defineComponent({
75
80
  const ctrl = isMac ? 'meta' : 'ctrl';
76
81
 
77
82
  keycon
83
+ .keydown((e) => {
84
+ console.log(e);
85
+ e.inputEvent.preventDefault();
86
+ })
78
87
  .keyup('delete', (e) => {
79
88
  e.inputEvent.preventDefault();
80
89
  if (!node.value || isPage(node.value)) return;
81
90
  services?.editorService.remove(node.value);
82
91
  })
83
- .keydown([ctrl, 'c'], (e) => {
92
+ .keyup('backspace', (e) => {
84
93
  e.inputEvent.preventDefault();
94
+ if (!node.value || isPage(node.value)) return;
95
+ services?.editorService.remove(node.value);
96
+ })
97
+ .keydown([ctrl, 'c'], () => {
85
98
  node.value && services?.editorService.copy(node.value);
86
99
  })
87
- .keydown([ctrl, 'v'], (e) => {
88
- e.inputEvent.preventDefault();
100
+ .keydown([ctrl, 'v'], () => {
89
101
  node.value && services?.editorService.paste();
90
102
  })
91
- .keydown([ctrl, 'x'], (e) => {
92
- e.inputEvent.preventDefault();
103
+ .keydown([ctrl, 'x'], () => {
93
104
  if (!node.value || isPage(node.value)) return;
94
105
  services?.editorService.copy(node.value);
95
106
  services?.editorService.remove(node.value);
96
107
  })
97
- .keydown([ctrl, 'z'], (e) => {
98
- e.inputEvent.preventDefault();
108
+ .keydown([ctrl, 'z'], () => {
99
109
  services?.editorService.undo();
100
110
  })
101
- .keydown([ctrl, 'shift', 'z'], (e) => {
102
- e.inputEvent.preventDefault();
111
+ .keydown([ctrl, 'shift', 'z'], () => {
103
112
  services?.editorService.redo();
104
113
  })
105
- .keydown('up', (e) => {
106
- e.inputEvent.preventDefault();
114
+ .keydown('up', () => {
107
115
  services?.editorService.move(0, -1);
108
116
  })
109
- .keydown('down', (e) => {
110
- e.inputEvent.preventDefault();
117
+ .keydown('down', () => {
111
118
  services?.editorService.move(0, 1);
112
119
  })
113
- .keydown('left', (e) => {
114
- e.inputEvent.preventDefault();
120
+ .keydown('left', () => {
115
121
  services?.editorService.move(-1, 0);
116
122
  })
117
- .keydown('right', (e) => {
118
- e.inputEvent.preventDefault();
123
+ .keydown('right', () => {
119
124
  services?.editorService.move(1, 0);
120
125
  })
121
- .keydown([ctrl, 'up'], (e) => {
122
- e.inputEvent.preventDefault();
126
+ .keydown([ctrl, 'up'], () => {
123
127
  services?.editorService.move(0, -10);
124
128
  })
125
- .keydown([ctrl, 'down'], (e) => {
126
- e.inputEvent.preventDefault();
129
+ .keydown([ctrl, 'down'], () => {
127
130
  services?.editorService.move(0, 10);
128
131
  })
129
- .keydown([ctrl, 'left'], (e) => {
130
- e.inputEvent.preventDefault();
132
+ .keydown([ctrl, 'left'], () => {
131
133
  services?.editorService.move(-10, 0);
132
134
  })
133
- .keydown([ctrl, 'right'], (e) => {
134
- e.inputEvent.preventDefault();
135
+ .keydown([ctrl, 'right'], () => {
135
136
  services?.editorService.move(10, 0);
136
137
  })
137
- .keydown('tab', (e) => {
138
- e.inputEvent.preventDefault();
138
+ .keydown('tab', () => {
139
139
  services?.editorService.selectNextNode();
140
140
  })
141
- .keydown([ctrl, 'tab'], (e) => {
142
- e.inputEvent.preventDefault();
141
+ .keydown([ctrl, 'tab'], () => {
143
142
  services?.editorService.selectNextPage();
144
143
  })
145
- .keydown([ctrl, '='], (e) => {
146
- e.inputEvent.preventDefault();
144
+ .keydown([ctrl, '='], () => {
147
145
  services?.uiService.zoom(0.1);
148
146
  })
149
- .keydown([ctrl, '-'], (e) => {
150
- e.inputEvent.preventDefault();
147
+ .keydown([ctrl, 'numpadplus'], () => {
148
+ services?.uiService.zoom(0.1);
149
+ })
150
+ .keydown([ctrl, '-'], () => {
151
+ services?.uiService.zoom(-0.1);
152
+ })
153
+ .keydown([ctrl, 'numpad-'], () => {
151
154
  services?.uiService.zoom(-0.1);
152
155
  });
153
156
  });
154
157
 
155
158
  onUnmounted(() => {
156
159
  workspace.value?.removeEventListener('mouseenter', mouseenterHandler);
160
+ workspace.value?.removeEventListener('mouseleave', mouseleaveHandler);
157
161
  keycon.destroy();
158
162
  });
159
163
 
@@ -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
  }
@@ -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
+ }