@tmagic/editor 1.3.0-alpha.4 → 1.3.0-alpha.6

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.
@@ -0,0 +1,240 @@
1
+ import KeyController from 'keycon';
2
+
3
+ import { isPage } from '@tmagic/utils';
4
+
5
+ import BaseService from './BaseService';
6
+ import editorService from './editor';
7
+ import uiService from './ui';
8
+
9
+ class Keybinding extends BaseService {
10
+ private keycon = new KeyController();
11
+
12
+ private ctrlKey = /mac os x/.test(navigator.userAgent.toLowerCase()) ? 'meta' : 'ctrl';
13
+
14
+ constructor() {
15
+ super();
16
+
17
+ this.keycon
18
+ .keyup((e) => {
19
+ this.emit('keyup', e.inputEvent);
20
+ })
21
+ .keyup('delete', (e) => {
22
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
23
+ return;
24
+ }
25
+
26
+ e.inputEvent.preventDefault();
27
+
28
+ this.removeNode();
29
+ })
30
+ .keyup('backspace', (e) => {
31
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
32
+ return;
33
+ }
34
+
35
+ e.inputEvent.preventDefault();
36
+
37
+ this.removeNode();
38
+ })
39
+ .keydown([this.ctrlKey, 'c'], (e) => {
40
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
41
+ return;
42
+ }
43
+
44
+ e.inputEvent.preventDefault();
45
+
46
+ const nodes = editorService.get('nodes');
47
+ nodes && editorService.copy(nodes);
48
+ })
49
+ .keydown([this.ctrlKey, 'v'], (e) => {
50
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
51
+ return;
52
+ }
53
+
54
+ e.inputEvent.preventDefault();
55
+
56
+ const nodes = editorService.get('nodes');
57
+ nodes && editorService.paste({ offsetX: 10, offsetY: 10 });
58
+ })
59
+ .keydown([this.ctrlKey, 'x'], (e) => {
60
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
61
+ return;
62
+ }
63
+
64
+ e.inputEvent.preventDefault();
65
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
66
+ return;
67
+ }
68
+
69
+ const nodes = editorService.get('nodes');
70
+
71
+ if (!nodes || isPage(nodes[0])) return;
72
+ editorService.copy(nodes);
73
+ editorService.remove(nodes);
74
+ })
75
+ .keydown([this.ctrlKey, 'z'], (e) => {
76
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
77
+ return;
78
+ }
79
+
80
+ e.inputEvent.preventDefault();
81
+ editorService.undo();
82
+ })
83
+ .keydown([this.ctrlKey, 'shift', 'z'], (e) => {
84
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
85
+ return;
86
+ }
87
+
88
+ e.inputEvent.preventDefault();
89
+ editorService.redo();
90
+ })
91
+ .keydown('up', (e) => {
92
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
93
+ return;
94
+ }
95
+
96
+ e.inputEvent.preventDefault();
97
+ editorService.move(0, -1);
98
+ })
99
+ .keydown('down', (e) => {
100
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
101
+ return;
102
+ }
103
+
104
+ e.inputEvent.preventDefault();
105
+ editorService.move(0, 1);
106
+ })
107
+ .keydown('left', (e) => {
108
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
109
+ return;
110
+ }
111
+
112
+ e.inputEvent.preventDefault();
113
+ editorService.move(-1, 0);
114
+ })
115
+ .keydown('right', (e) => {
116
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
117
+ return;
118
+ }
119
+
120
+ e.inputEvent.preventDefault();
121
+ editorService.move(1, 0);
122
+ })
123
+ .keydown([this.ctrlKey, 'up'], (e) => {
124
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
125
+ return;
126
+ }
127
+
128
+ e.inputEvent.preventDefault();
129
+ editorService.move(0, -10);
130
+ })
131
+ .keydown([this.ctrlKey, 'down'], (e) => {
132
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
133
+ return;
134
+ }
135
+
136
+ e.inputEvent.preventDefault();
137
+ editorService.move(0, 10);
138
+ })
139
+ .keydown([this.ctrlKey, 'left'], (e) => {
140
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
141
+ return;
142
+ }
143
+
144
+ e.inputEvent.preventDefault();
145
+ editorService.move(-10, 0);
146
+ })
147
+ .keydown([this.ctrlKey, 'right'], (e) => {
148
+ e.inputEvent.preventDefault();
149
+ editorService.move(10, 0);
150
+ })
151
+ .keydown('tab', (e) => {
152
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
153
+ return;
154
+ }
155
+
156
+ e.inputEvent.preventDefault();
157
+ editorService.selectNextNode();
158
+ })
159
+ .keydown([this.ctrlKey, 'tab'], (e) => {
160
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
161
+ return;
162
+ }
163
+
164
+ e.inputEvent.preventDefault();
165
+ editorService.selectNextPage();
166
+ })
167
+ .keydown([this.ctrlKey, '='], (e) => {
168
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
169
+ return;
170
+ }
171
+
172
+ e.inputEvent.preventDefault();
173
+ uiService.zoom(0.1);
174
+ })
175
+ .keydown([this.ctrlKey, 'numpadplus'], (e) => {
176
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
177
+ return;
178
+ }
179
+
180
+ e.inputEvent.preventDefault();
181
+ uiService.zoom(0.1);
182
+ })
183
+ .keydown([this.ctrlKey, '-'], (e) => {
184
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
185
+ return;
186
+ }
187
+
188
+ e.inputEvent.preventDefault();
189
+ uiService.zoom(-0.1);
190
+ })
191
+ .keydown([this.ctrlKey, 'numpad-'], (e) => {
192
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
193
+ return;
194
+ }
195
+
196
+ e.inputEvent.preventDefault();
197
+ uiService.zoom(-0.1);
198
+ })
199
+ .keydown([this.ctrlKey, '0'], async (e) => {
200
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
201
+ return;
202
+ }
203
+
204
+ e.inputEvent.preventDefault();
205
+ uiService.set('zoom', await uiService.calcZoom());
206
+ })
207
+ .keydown([this.ctrlKey, '1'], (e) => {
208
+ if (this.isDisabledKeyEvent(e.inputEvent.target)) {
209
+ return;
210
+ }
211
+
212
+ e.inputEvent.preventDefault();
213
+ uiService.set('zoom', 1);
214
+ });
215
+ }
216
+
217
+ public destroy() {
218
+ this.keycon.destroy();
219
+ }
220
+
221
+ private isDisabledKeyEvent(node: EventTarget | null) {
222
+ const el = node as HTMLElement | null;
223
+
224
+ if (!el) return false;
225
+
226
+ // 当前是在输入框中,禁止响应画布快捷键
227
+ return el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable;
228
+ }
229
+
230
+ private removeNode() {
231
+ const nodes = editorService.get('nodes');
232
+
233
+ if (!nodes || isPage(nodes[0])) return;
234
+ editorService.remove(nodes);
235
+ }
236
+ }
237
+
238
+ export type KeybindingService = Keybinding;
239
+
240
+ export default new Keybinding();
@@ -4,14 +4,38 @@
4
4
  width: 8px;
5
5
  margin: 0 -5px;
6
6
  height: 100%;
7
- opacity: 0.9;
7
+ opacity: 0.8;
8
8
  background: padding-box #d8dee8;
9
9
  box-sizing: border-box;
10
10
  cursor: col-resize;
11
11
  z-index: 1;
12
+ position: relative;
12
13
 
13
14
  &:hover {
14
15
  border-color: #d8dee8;
16
+
17
+ .icon-container {
18
+ visibility: visible;
19
+ opacity: 1;
20
+ }
21
+ }
22
+
23
+ &.m-editor-resizer-draging {
24
+ &::after {
25
+ content: "";
26
+ position: absolute;
27
+ width: 600px;
28
+ height: 100%;
29
+ left: 0;
30
+ }
31
+
32
+ &::before {
33
+ content: "";
34
+ position: absolute;
35
+ width: 600px;
36
+ height: 100%;
37
+ right: 0;
38
+ }
15
39
  }
16
40
 
17
41
  .icon-container {
@@ -40,12 +64,3 @@
40
64
  font-size: 18px;
41
65
  }
42
66
  }
43
-
44
- .magic-editor-resizer:hover {
45
- .icon-container {
46
- visibility: visible;
47
- opacity: 1;
48
- }
49
- // border-left: 5px solid rgba(0,0,0,.5);
50
- // border-right: 5px solid rgba(0,0,0,.5);
51
- }
package/src/type.ts CHANGED
@@ -30,11 +30,12 @@ import type {
30
30
 
31
31
  import type { CodeBlockService } from './services/codeBlock';
32
32
  import type { ComponentListService } from './services/componentList';
33
- import { DataSourceService } from './services/dataSource';
33
+ import type { DataSourceService } from './services/dataSource';
34
34
  import type { DepService } from './services/dep';
35
35
  import type { EditorService } from './services/editor';
36
36
  import type { EventsService } from './services/events';
37
37
  import type { HistoryService } from './services/history';
38
+ import type { KeybindingService } from './services/keybinding';
38
39
  import type { PropsService } from './services/props';
39
40
  import type { StorageService } from './services/storage';
40
41
  import type { UiService } from './services/ui';
@@ -58,6 +59,7 @@ export interface Services {
58
59
  codeBlockService: CodeBlockService;
59
60
  depService: DepService;
60
61
  dataSourceService: DataSourceService;
62
+ keybindingService: KeybindingService;
61
63
  }
62
64
 
63
65
  export interface StageOptions {
@@ -70,9 +70,9 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
70
70
  class?: unknown;
71
71
  style?: unknown;
72
72
  readonly id: Id;
73
+ readonly language?: string | undefined;
73
74
  readonly codeOptions?: Object | undefined;
74
75
  readonly content: string;
75
- readonly language?: string | undefined;
76
76
  onClose?: ((...args: any[]) => any) | undefined;
77
77
  onSaveAndClose?: ((...args: any[]) => any) | undefined;
78
78
  };
@@ -98,6 +98,9 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
98
98
  type: import("vue").PropType<boolean>;
99
99
  default: boolean;
100
100
  };
101
+ language: {
102
+ type: import("vue").PropType<string>;
103
+ };
101
104
  codeOptions: {
102
105
  type: import("vue").PropType<Object>;
103
106
  };
@@ -105,9 +108,6 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
105
108
  type: import("vue").PropType<string>;
106
109
  required: true;
107
110
  };
108
- language: {
109
- type: import("vue").PropType<string>;
110
- };
111
111
  autoSaveDraft: {
112
112
  type: import("vue").PropType<boolean>;
113
113
  default: boolean;
@@ -150,6 +150,9 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
150
150
  type: import("vue").PropType<boolean>;
151
151
  default: boolean;
152
152
  };
153
+ language: {
154
+ type: import("vue").PropType<string>;
155
+ };
153
156
  codeOptions: {
154
157
  type: import("vue").PropType<Object>;
155
158
  };
@@ -157,9 +160,6 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
157
160
  type: import("vue").PropType<string>;
158
161
  required: true;
159
162
  };
160
- language: {
161
- type: import("vue").PropType<string>;
162
- };
163
163
  autoSaveDraft: {
164
164
  type: import("vue").PropType<boolean>;
165
165
  default: boolean;
package/types/index.d.ts CHANGED
@@ -28,7 +28,8 @@ export { default as PropsPanel } from './layouts/PropsPanel.vue';
28
28
  export { default as ToolButton } from './components/ToolButton.vue';
29
29
  export { default as ContentMenu } from './components/ContentMenu.vue';
30
30
  export { default as Icon } from './components/Icon.vue';
31
- export { default as LayoutContainer } from './components/Layout.vue';
31
+ export { default as LayoutContainer } from './components/SplitView.vue';
32
+ export { default as SplitView } from './components/SplitView.vue';
32
33
  declare const _default: {
33
34
  install: (app: App, opt?: InstallOptions) => void;
34
35
  };
@@ -1,7 +1,7 @@
1
1
  import * as monaco from 'monaco-editor';
2
2
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
3
- initValues?: string | Object | undefined;
4
- modifiedValues?: string | Object | undefined;
3
+ initValues?: string | Record<string | number, any> | null | undefined;
4
+ modifiedValues?: string | Record<string | number, any> | null | undefined;
5
5
  type?: "diff" | undefined;
6
6
  language?: string | undefined;
7
7
  options?: {
@@ -18,9 +18,9 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
18
18
  getEditor(): monaco.editor.IStandaloneCodeEditor | monaco.editor.IStandaloneDiffEditor | null;
19
19
  setEditorValue: (v: any, m: any) => void | undefined;
20
20
  focus(): void;
21
- }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("save" | "initd")[], "save" | "initd", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
22
- initValues?: string | Object | undefined;
23
- modifiedValues?: string | Object | undefined;
21
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("initd" | "save")[], "initd" | "save", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
22
+ initValues?: string | Record<string | number, any> | null | undefined;
23
+ modifiedValues?: string | Record<string | number, any> | null | undefined;
24
24
  type?: "diff" | undefined;
25
25
  language?: string | undefined;
26
26
  options?: {
@@ -34,8 +34,8 @@ declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_T
34
34
  tabSize: number;
35
35
  };
36
36
  }>>> & {
37
- onSave?: ((...args: any[]) => any) | undefined;
38
37
  onInitd?: ((...args: any[]) => any) | undefined;
38
+ onSave?: ((...args: any[]) => any) | undefined;
39
39
  }, {
40
40
  options: {
41
41
  [key: string]: any;
@@ -1,42 +1,18 @@
1
- declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
2
- codeOptions?: Record<string, any> | undefined;
3
- }>, {
4
- codeOptions: () => {};
5
- }>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
6
- codeOptions?: Record<string, any> | undefined;
7
- }>, {
8
- codeOptions: () => {};
9
- }>>>, {
10
- codeOptions: Record<string, any>;
11
- }, {}>, {
12
- nav?(_: {
13
- class: string;
14
- }): any;
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
2
+ header?(_: {}): any;
3
+ nav?(_: {}): any;
4
+ "content-before"?(_: {}): any;
5
+ "src-code"?(_: {}): any;
15
6
  sidebar?(_: {}): any;
16
7
  workspace?(_: {}): any;
17
8
  empty?(_: {}): any;
18
9
  "props-panel"?(_: {}): any;
10
+ "content-after"?(_: {}): any;
11
+ footer?(_: {}): any;
19
12
  }>;
20
13
  export default _default;
21
- type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
22
- type __VLS_TypePropsToRuntimeProps<T> = {
23
- [K in keyof T]-?: {} extends Pick<T, K> ? {
24
- type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
25
- } : {
26
- type: import('vue').PropType<T[K]>;
27
- required: true;
28
- };
29
- };
30
- type __VLS_WithDefaults<P, D> = {
31
- [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
32
- default: D[K];
33
- }> : P[K];
34
- };
35
14
  type __VLS_WithTemplateSlots<T, S> = T & {
36
15
  new (): {
37
16
  $slots: S;
38
17
  };
39
18
  };
40
- type __VLS_Prettify<T> = {
41
- [K in keyof T]: T[K];
42
- } & {};
@@ -0,0 +1,12 @@
1
+ import BaseService from './BaseService';
2
+ declare class Keybinding extends BaseService {
3
+ private keycon;
4
+ private ctrlKey;
5
+ constructor();
6
+ destroy(): void;
7
+ private isDisabledKeyEvent;
8
+ private removeNode;
9
+ }
10
+ export type KeybindingService = Keybinding;
11
+ declare const _default: Keybinding;
12
+ export default _default;
package/types/type.d.ts CHANGED
@@ -5,11 +5,12 @@ import type StageCore from '@tmagic/stage';
5
5
  import type { ContainerHighlightType, CustomizeMoveableOptionsCallbackConfig, MoveableOptions, UpdateDragEl } from '@tmagic/stage';
6
6
  import type { CodeBlockService } from './services/codeBlock';
7
7
  import type { ComponentListService } from './services/componentList';
8
- import { DataSourceService } from './services/dataSource';
8
+ import type { DataSourceService } from './services/dataSource';
9
9
  import type { DepService } from './services/dep';
10
10
  import type { EditorService } from './services/editor';
11
11
  import type { EventsService } from './services/events';
12
12
  import type { HistoryService } from './services/history';
13
+ import type { KeybindingService } from './services/keybinding';
13
14
  import type { PropsService } from './services/props';
14
15
  import type { StorageService } from './services/storage';
15
16
  import type { UiService } from './services/ui';
@@ -30,6 +31,7 @@ export interface Services {
30
31
  codeBlockService: CodeBlockService;
31
32
  depService: DepService;
32
33
  dataSourceService: DataSourceService;
34
+ keybindingService: KeybindingService;
33
35
  }
34
36
  export interface StageOptions {
35
37
  runtimeUrl: string;
File without changes