@tmagic/editor 1.3.0-beta.1 → 1.3.0-beta.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.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0-beta.1",
2
+ "version": "1.3.0-beta.2",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -46,13 +46,13 @@
46
46
  "dependencies": {
47
47
  "@babel/core": "^7.18.0",
48
48
  "@element-plus/icons-vue": "^2.0.9",
49
- "@tmagic/core": "1.3.0-beta.1",
50
- "@tmagic/design": "1.3.0-beta.1",
51
- "@tmagic/form": "1.3.0-beta.1",
52
- "@tmagic/schema": "1.3.0-beta.1",
53
- "@tmagic/stage": "1.3.0-beta.1",
54
- "@tmagic/table": "1.3.0-beta.1",
55
- "@tmagic/utils": "1.3.0-beta.1",
49
+ "@tmagic/core": "1.3.0-beta.2",
50
+ "@tmagic/design": "1.3.0-beta.2",
51
+ "@tmagic/form": "1.3.0-beta.2",
52
+ "@tmagic/schema": "1.3.0-beta.2",
53
+ "@tmagic/stage": "1.3.0-beta.2",
54
+ "@tmagic/table": "1.3.0-beta.2",
55
+ "@tmagic/utils": "1.3.0-beta.2",
56
56
  "buffer": "^6.0.3",
57
57
  "color": "^3.1.3",
58
58
  "events": "^3.3.0",
@@ -64,8 +64,8 @@
64
64
  "vue": "^3.3.4"
65
65
  },
66
66
  "peerDependencies": {
67
- "@tmagic/design": "1.3.0-beta.1",
68
- "@tmagic/form": "1.3.0-beta.1",
67
+ "@tmagic/design": "1.3.0-beta.2",
68
+ "@tmagic/form": "1.3.0-beta.2",
69
69
  "monaco-editor": "^0.41.0",
70
70
  "vue": "^3.3.4"
71
71
  },
@@ -16,7 +16,7 @@
16
16
  ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
17
17
  >
18
18
  </TMagicTooltip>
19
- <TMagicButton v-else size="small" text :disabled="disabled"
19
+ <TMagicButton v-else size="small" text :disabled="disabled" :title="data.text"
20
20
  ><MIcon v-if="data.icon" :icon="data.icon"></MIcon><span>{{ data.text }}</span></TMagicButton
21
21
  >
22
22
  </template>
@@ -175,7 +175,7 @@ const dataSourceFieldsConfig: FormConfig = [
175
175
  if (model.type === 'number') return 'number';
176
176
  if (model.type === 'boolean') return 'select';
177
177
 
178
- return 'string';
178
+ return 'text';
179
179
  },
180
180
  options: [
181
181
  { text: 'true', value: true },
@@ -52,6 +52,7 @@ import { computed, inject } from 'vue';
52
52
  import { Delete } from '@element-plus/icons-vue';
53
53
  import { has } from 'lodash-es';
54
54
 
55
+ import type { EventOption } from '@tmagic/core';
55
56
  import { TMagicButton } from '@tmagic/design';
56
57
  import type { FieldProps, FormState } from '@tmagic/form';
57
58
  import { ActionType } from '@tmagic/schema';
@@ -75,11 +76,22 @@ const eventNameConfig = computed(() => {
75
76
  text: '事件',
76
77
  type: 'select',
77
78
  labelWidth: '40px',
78
- options: (mForm: FormState, { formValue }: any) =>
79
- services?.eventsService.getEvent(formValue.type).map((option: any) => ({
79
+ options: (mForm: FormState, { formValue }: any) => {
80
+ let events: EventOption[] = [];
81
+
82
+ if (!services) return events;
83
+
84
+ if (props.config.src === 'component') {
85
+ events = services.eventsService.getEvent(formValue.type);
86
+ } else if (props.config.src === 'datasource') {
87
+ events = services.dataSourceService.getFormEvent(formValue.type);
88
+ }
89
+
90
+ return events.map((option) => ({
80
91
  text: option.label,
81
92
  value: option.value,
82
- })),
93
+ }));
94
+ },
83
95
  };
84
96
  return { ...defaultEventNameConfig, ...props.config.eventNameConfig };
85
97
  });
@@ -1,6 +1,8 @@
1
1
  <template>
2
- <content-menu
2
+ <ContentMenu
3
3
  ref="menu"
4
+ class="magic-editor-node-list-menu"
5
+ style="max-width: 280px"
4
6
  :menu-data="menuData"
5
7
  :active="node?.id"
6
8
  :auto-hide="!pinned"
@@ -9,7 +11,7 @@
9
11
  <template #title>
10
12
  <NodeListMenuTitle v-model:pinned="pinned" @change="dragMenuHandler" @close="closeHandler"></NodeListMenuTitle>
11
13
  </template>
12
- </content-menu>
14
+ </ContentMenu>
13
15
  </template>
14
16
 
15
17
  <script lang="ts" setup>
@@ -53,6 +55,14 @@ const cancel = () => {
53
55
  menu.value?.hide();
54
56
  };
55
57
 
58
+ const clearTimeoutLazy = () => {
59
+ globalThis.setTimeout(() => {
60
+ if (timeout) {
61
+ globalThis.clearTimeout(timeout);
62
+ }
63
+ }, 300);
64
+ };
65
+
56
66
  const unWatch = watch(
57
67
  stage,
58
68
  (stage) => {
@@ -90,7 +100,8 @@ const unWatch = watch(
90
100
  });
91
101
 
92
102
  stage.on('mouseleave', () => {
93
- cancel();
103
+ // mouseleave后,大概率还有最后一个mousemove事件,这里延迟清除
104
+ clearTimeoutLazy();
94
105
  });
95
106
 
96
107
  unWatch();
@@ -135,11 +146,7 @@ const menuData = computed<MenuButton[]>(() =>
135
146
 
136
147
  const mouseenterHandler = () => {
137
148
  // menu的mouseenter后,大概率还有最后一个mousemove事件,这里延迟清除
138
- globalThis.setTimeout(() => {
139
- if (timeout) {
140
- globalThis.clearTimeout(timeout);
141
- }
142
- }, 300);
149
+ clearTimeoutLazy();
143
150
  };
144
151
 
145
152
  const dragMenuHandler = ({ deltaY, deltaX }: OnDrag) => {
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <content-menu :menu-data="menuData" ref="menu"></content-menu>
2
+ <ContentMenu :menu-data="menuData" ref="menu"></ContentMenu>
3
3
  </template>
4
4
 
5
5
  <script lang="ts" setup>
@@ -1,6 +1,7 @@
1
1
  import { reactive } from 'vue';
2
2
  import { cloneDeep } from 'lodash-es';
3
3
 
4
+ import type { EventOption } from '@tmagic/core';
4
5
  import type { FormConfig } from '@tmagic/form';
5
6
  import type { DataSourceSchema } from '@tmagic/schema';
6
7
  import { guid } from '@tmagic/utils';
@@ -16,6 +17,7 @@ interface State {
16
17
  editable: boolean;
17
18
  configs: Record<string, FormConfig>;
18
19
  values: Record<string, Partial<DataSourceSchema>>;
20
+ events: Record<string, EventOption[]>;
19
21
  }
20
22
 
21
23
  type StateKey = keyof State;
@@ -26,6 +28,7 @@ class DataSource extends BaseService {
26
28
  editable: true,
27
29
  configs: {},
28
30
  values: {},
31
+ events: {},
29
32
  });
30
33
 
31
34
  public set<K extends StateKey, T extends State[K]>(name: K, value: T) {
@@ -52,6 +55,14 @@ class DataSource extends BaseService {
52
55
  this.get('values')[type] = value;
53
56
  }
54
57
 
58
+ public getFormEvent(type = 'base') {
59
+ return this.get('events')[type] || [];
60
+ }
61
+
62
+ public setFormEvent(type: string, value: EventOption[] = []) {
63
+ this.get('events')[type] = value;
64
+ }
65
+
55
66
  public add(config: DataSourceSchema) {
56
67
  const newConfig = {
57
68
  ...config,
@@ -44,30 +44,32 @@
44
44
  }
45
45
  }
46
46
 
47
- &.active {
48
- background-color: $--theme-color;
49
- .tmagic-design-button,
50
- .tmagic-design-button:active,
51
- .tmagic-design-button:focus {
52
- color: #fff;
53
- background-color: $--theme-color;
54
- }
47
+ &.button {
48
+ &:hover {
49
+ background-color: $--hover-color;
50
+ .tmagic-design-button,
51
+ .tmagic-design-button:active,
52
+ .tmagic-design-button:focus {
53
+ color: $--font-color;
54
+ }
55
55
 
56
- &.menu-item i {
57
- color: #fff;
56
+ &.menu-item i {
57
+ color: $--font-color;
58
+ }
58
59
  }
59
- }
60
60
 
61
- &:hover {
62
- background-color: $--hover-color;
63
- .tmagic-design-button,
64
- .tmagic-design-button:active,
65
- .tmagic-design-button:focus {
66
- color: $--font-color;
67
- }
61
+ &.active {
62
+ background-color: $--theme-color;
63
+ .tmagic-design-button,
64
+ .tmagic-design-button:active,
65
+ .tmagic-design-button:focus {
66
+ color: #fff;
67
+ background-color: transparent;
68
+ }
68
69
 
69
- &.menu-item i {
70
- color: $--font-color;
70
+ &.menu-item i {
71
+ color: #fff;
72
+ }
71
73
  }
72
74
  }
73
75
  }
package/src/type.ts CHANGED
@@ -418,6 +418,7 @@ export interface HistoryState {
418
418
  export interface EventSelectConfig {
419
419
  name: string;
420
420
  type: 'event-select';
421
+ src: 'datasource' | 'component';
421
422
  /** 事件名称表单配置 */
422
423
  eventNameConfig?: FormItem;
423
424
  /** 动作类型配置 */
@@ -29,6 +29,18 @@ const fillConfig = (config: FormConfig): FormConfig => [
29
29
  },
30
30
  ],
31
31
  },
32
+ {
33
+ type: 'panel',
34
+ title: '事件配置',
35
+ display: false,
36
+ items: [
37
+ {
38
+ name: 'events',
39
+ src: 'datasource',
40
+ type: 'event-select',
41
+ },
42
+ ],
43
+ },
32
44
  ];
33
45
 
34
46
  export const getFormConfig = (type: string, configs: Record<string, FormConfig>): FormConfig => {
@@ -205,6 +205,7 @@ export const eventTabConfig: TabPaneConfig = {
205
205
  items: [
206
206
  {
207
207
  name: 'events',
208
+ src: 'component',
208
209
  type: 'event-select',
209
210
  },
210
211
  ],
@@ -1,3 +1,4 @@
1
+ import type { EventOption } from '@tmagic/core';
1
2
  import type { FormConfig } from '@tmagic/form';
2
3
  import type { DataSourceSchema } from '@tmagic/schema';
3
4
  import type { DatasourceTypeOption } from '../type';
@@ -8,6 +9,7 @@ interface State {
8
9
  editable: boolean;
9
10
  configs: Record<string, FormConfig>;
10
11
  values: Record<string, Partial<DataSourceSchema>>;
12
+ events: Record<string, EventOption[]>;
11
13
  }
12
14
  type StateKey = keyof State;
13
15
  declare class DataSource extends BaseService {
@@ -18,6 +20,8 @@ declare class DataSource extends BaseService {
18
20
  setFormConfig(type: string, config: FormConfig): void;
19
21
  getFormValue(type?: string): Partial<DataSourceSchema>;
20
22
  setFormValue(type: string, value: Partial<DataSourceSchema>): void;
23
+ getFormEvent(type?: string): EventOption[];
24
+ setFormEvent(type: string, value?: EventOption[]): void;
21
25
  add(config: DataSourceSchema): void;
22
26
  update(config: DataSourceSchema): void;
23
27
  remove(id: string): void;
package/types/type.d.ts CHANGED
@@ -335,6 +335,7 @@ export interface HistoryState {
335
335
  export interface EventSelectConfig {
336
336
  name: string;
337
337
  type: 'event-select';
338
+ src: 'datasource' | 'component';
338
339
  /** 事件名称表单配置 */
339
340
  eventNameConfig?: FormItem;
340
341
  /** 动作类型配置 */