@tmagic/editor 1.3.0-alpha.21 → 1.3.0-alpha.23

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-alpha.21",
2
+ "version": "1.3.0-alpha.23",
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-alpha.21",
50
- "@tmagic/design": "1.3.0-alpha.21",
51
- "@tmagic/form": "1.3.0-alpha.21",
52
- "@tmagic/schema": "1.3.0-alpha.21",
53
- "@tmagic/stage": "1.3.0-alpha.21",
54
- "@tmagic/table": "1.3.0-alpha.21",
55
- "@tmagic/utils": "1.3.0-alpha.21",
49
+ "@tmagic/core": "1.3.0-alpha.23",
50
+ "@tmagic/design": "1.3.0-alpha.23",
51
+ "@tmagic/form": "1.3.0-alpha.23",
52
+ "@tmagic/schema": "1.3.0-alpha.23",
53
+ "@tmagic/stage": "1.3.0-alpha.23",
54
+ "@tmagic/table": "1.3.0-alpha.23",
55
+ "@tmagic/utils": "1.3.0-alpha.23",
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-alpha.21",
68
- "@tmagic/form": "1.3.0-alpha.21",
67
+ "@tmagic/design": "1.3.0-alpha.23",
68
+ "@tmagic/form": "1.3.0-alpha.23",
69
69
  "monaco-editor": "^0.41.0",
70
70
  "vue": "^3.3.4"
71
71
  },
@@ -14,18 +14,21 @@
14
14
  :values="fieldValues"
15
15
  :parentValues="model[name]"
16
16
  :disabled="disabled"
17
+ :width="width"
17
18
  @submit="fieldChange"
18
19
  ></MFormDrawer>
19
20
  </div>
20
21
  </template>
21
22
 
22
23
  <script setup lang="ts">
23
- import { ref } from 'vue';
24
+ import { computed, inject, ref } from 'vue';
24
25
 
25
26
  import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
26
- import { FieldProps, FormConfig, FormState, MFormDrawer } from '@tmagic/form';
27
+ import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
27
28
  import { MagicTable } from '@tmagic/table';
28
29
 
30
+ import type { Services } from '@editor/type';
31
+
29
32
  defineOptions({
30
33
  name: 'MEditorDataSourceFields',
31
34
  });
@@ -43,10 +46,14 @@ const props = withDefaults(
43
46
 
44
47
  const emit = defineEmits(['change']);
45
48
 
49
+ const services = inject<Services>('services');
50
+
46
51
  const addDialog = ref<InstanceType<typeof MFormDrawer>>();
47
52
  const fieldValues = ref<Record<string, any>>({});
48
53
  const filedTitle = ref('');
49
54
 
55
+ const width = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
56
+
50
57
  const newHandler = () => {
51
58
  fieldValues.value = {};
52
59
  filedTitle.value = '新增属性';
@@ -16,7 +16,6 @@
16
16
  "
17
17
  style="width: 100%"
18
18
  @blur="blurHandler"
19
- @change="changeHandler"
20
19
  @input="inputHandler"
21
20
  @select="selectHandler"
22
21
  >
@@ -111,6 +110,8 @@ const blurHandler = () => {
111
110
  isFocused.value = false;
112
111
 
113
112
  setDisplayState();
113
+
114
+ emit('change', state.value);
114
115
  };
115
116
 
116
117
  const changeHandler = (v: string) => {
@@ -314,5 +315,7 @@ const selectHandler = async ({ value, type }: { value: string; type: 'dataSource
314
315
  newSelectionStart = dotIndex + suggestText.length + 1;
315
316
  }
316
317
  input.value?.setSelectionRange(newSelectionStart, newSelectionStart);
318
+
319
+ changeHandler(state.value);
317
320
  };
318
321
  </script>
@@ -1,24 +1,23 @@
1
1
  <template>
2
- <component
3
- v-if="data.type === 'tabs' && data.items.length"
4
- v-model="activeTabName"
5
- class="m-editor-sidebar tmagic-design-tabs"
6
- v-bind="tabsComponent?.props({ type: 'card', tabPosition: 'left' }) || {}"
7
- :is="tabsComponent?.component || 'el-tabs'"
8
- >
9
- <component
2
+ <div class="m-editor-sidebar" v-if="data.type === 'tabs' && data.items.length">
3
+ <div class="m-editor-sidebar-header">
4
+ <div
5
+ class="m-editor-sidebar-header-item"
6
+ v-for="(config, index) in sideBarItems"
7
+ :key="config.$key ?? index"
8
+ :class="{ 'is-active': activeTabName === config.text }"
9
+ @click="activeTabName = config.text || `${index}`"
10
+ >
11
+ <MIcon v-if="config.icon" :icon="config.icon"></MIcon>
12
+ <div v-if="config.text" class="magic-editor-tab-panel-title">{{ config.text }}</div>
13
+ </div>
14
+ </div>
15
+ <div
16
+ class="m-editor-sidebar-content"
10
17
  v-for="(config, index) in sideBarItems"
11
- v-bind="tabPaneComponent?.props({ name: config.text, lazy: config.lazy }) || {}"
12
- :is="tabPaneComponent?.component || 'el-tab-pane'"
13
- :key="config.$key || index"
18
+ :key="config.$key ?? index"
19
+ v-show="activeTabName === config.text"
14
20
  >
15
- <template #label>
16
- <div :key="config.text">
17
- <MIcon v-if="config.icon" :icon="config.icon"></MIcon>
18
- <div v-if="config.text" class="magic-editor-tab-panel-title">{{ config.text }}</div>
19
- </div>
20
- </template>
21
-
22
21
  <component v-if="config" :is="config.component" v-bind="config.props || {}" v-on="config?.listeners || {}">
23
22
  <template
24
23
  #component-list-panel-header
@@ -71,16 +70,14 @@
71
70
  />
72
71
  </template>
73
72
  </component>
74
- </component>
75
- </component>
73
+ </div>
74
+ </div>
76
75
  </template>
77
76
 
78
- <script lang="ts" setup>
77
+ <script setup lang="ts">
79
78
  import { computed, ref, watch } from 'vue';
80
79
  import { Coin, EditPen, Goods, List } from '@element-plus/icons-vue';
81
80
 
82
- import { getConfig } from '@tmagic/design';
83
-
84
81
  import MIcon from '@editor/components/Icon.vue';
85
82
  import type { MenuButton, MenuComponent, SideComponent, SideItem } from '@editor/type';
86
83
  import { SideBarData } from '@editor/type';
@@ -104,9 +101,6 @@ const props = withDefaults(
104
101
  },
105
102
  );
106
103
 
107
- const tabPaneComponent = getConfig('components')?.tabPane;
108
- const tabsComponent = getConfig('components')?.tabs;
109
-
110
104
  const activeTabName = ref(props.data?.status);
111
105
 
112
106
  const getItemConfig = (data: SideItem): SideComponent => {
@@ -6,6 +6,7 @@
6
6
  <TMagicButton v-if="editable" class="create-code-button" type="primary" size="small" @click="createCodeBlock"
7
7
  >新增</TMagicButton
8
8
  >
9
+ <slot name="code-block-panel-search"></slot>
9
10
  </div>
10
11
  </slot>
11
12
 
@@ -2,7 +2,24 @@
2
2
  <TMagicScrollbar class="data-source-list-panel m-editor-dep-list-panel">
3
3
  <div class="search-wrapper">
4
4
  <SearchInput @search="filterTextChangeHandler"></SearchInput>
5
- <TMagicButton v-if="editable" type="primary" size="small" @click="addHandler">新增</TMagicButton>
5
+ <TMagicPopover v-if="editable" placement="right">
6
+ <template #reference>
7
+ <TMagicButton type="primary" size="small">新增</TMagicButton>
8
+ </template>
9
+ <div class="data-source-list-panel-add-menu">
10
+ <ToolButton
11
+ v-for="(item, index) in datasourceTypeList"
12
+ :data="{
13
+ type: 'button',
14
+ text: item.text,
15
+ handler: () => {
16
+ addHandler(item.type);
17
+ },
18
+ }"
19
+ :key="index"
20
+ ></ToolButton>
21
+ </div>
22
+ </TMagicPopover>
6
23
  </div>
7
24
 
8
25
  <!-- 数据源列表 -->
@@ -12,7 +29,7 @@
12
29
  ref="editDialog"
13
30
  :disabled="!editable"
14
31
  :values="dataSourceValues"
15
- :title="typeof dataSourceValues.id !== 'undefined' ? `编辑${dataSourceValues.title}` : '新增'"
32
+ :title="dialogTitle"
16
33
  @submit="submitDataSourceHandler"
17
34
  ></DataSourceConfigPanel>
18
35
  </TMagicScrollbar>
@@ -21,10 +38,11 @@
21
38
  <script setup lang="ts" name="MEditorDataSourceListPanel">
22
39
  import { computed, inject, ref } from 'vue';
23
40
 
24
- import { TMagicButton, TMagicScrollbar } from '@tmagic/design';
41
+ import { TMagicButton, TMagicPopover, TMagicScrollbar } from '@tmagic/design';
25
42
  import type { DataSourceSchema } from '@tmagic/schema';
26
43
 
27
44
  import SearchInput from '@editor/components/SearchInput.vue';
45
+ import ToolButton from '@editor/components/ToolButton.vue';
28
46
  import type { Services } from '@editor/type';
29
47
 
30
48
  import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
@@ -40,12 +58,26 @@ const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
40
58
 
41
59
  const dataSourceValues = ref<Record<string, any>>({});
42
60
 
43
- const editable = computed(() => dataSourceService?.get('editable') ?? true);
61
+ const dialogTitle = ref('');
44
62
 
45
- const addHandler = () => {
63
+ const editable = computed(() => dataSourceService?.get('editable') ?? true);
64
+ const datasourceTypeList = computed(() =>
65
+ [
66
+ { text: '基础', type: 'base' },
67
+ { text: 'HTTP', type: 'http' },
68
+ ].concat(dataSourceService?.get('datasourceTypeList') ?? []),
69
+ );
70
+
71
+ const addHandler = (type: string) => {
46
72
  if (!editDialog.value) return;
47
73
 
48
- dataSourceValues.value = {};
74
+ dataSourceValues.value = {
75
+ type,
76
+ };
77
+
78
+ const datasourceType = datasourceTypeList.value.find((item) => item.type === type);
79
+
80
+ dialogTitle.value = `新增${datasourceType?.text || ''}`;
49
81
 
50
82
  editDialog.value.show();
51
83
  };
@@ -57,6 +89,8 @@ const editHandler = (id: string) => {
57
89
  ...dataSourceService?.getDataSourceById(id),
58
90
  };
59
91
 
92
+ dialogTitle.value = `新增${dataSourceValues.value.title || ''}`;
93
+
60
94
  editDialog.value.show();
61
95
  };
62
96
 
@@ -37,7 +37,7 @@ class DataSource extends BaseService {
37
37
  }
38
38
 
39
39
  public getFormConfig(type = 'base') {
40
- return getFormConfig(type, this.get('datasourceTypeList'), this.get('configs'));
40
+ return getFormConfig(type, this.get('configs'));
41
41
  }
42
42
 
43
43
  public setFormConfig(type: string, config: FormConfig) {
@@ -648,12 +648,14 @@ class Editor extends BaseService {
648
648
 
649
649
  if (doc) {
650
650
  const el = doc.getElementById(`${node.id}`);
651
- const parentEl = el?.offsetParent;
651
+ const parentEl = layout === Layout.FIXED ? doc.body : el?.offsetParent;
652
652
  if (parentEl && el) {
653
653
  node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
654
+ node.style.right = '';
654
655
  }
655
656
  } else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
656
657
  node.style.left = (parent.style.width - node.style.width) / 2;
658
+ node.style.right = '';
657
659
  }
658
660
 
659
661
  return node;
@@ -792,20 +794,46 @@ class Editor extends BaseService {
792
794
  if (!node || isPage(node)) return;
793
795
 
794
796
  const { style, id, type } = node;
795
- if (!style || style.position !== 'absolute') return;
796
-
797
- if (top && !isNumber(style.top)) return;
798
- if (left && !isNumber(style.left)) return;
799
-
800
- this.update({
801
- id,
802
- type,
803
- style: {
804
- ...style,
805
- left: Number(style.left) + left,
806
- top: Number(style.top) + top,
807
- },
808
- });
797
+ if (!style || !['absolute', 'fixed'].includes(style.position)) return;
798
+
799
+ const update = (style: { [key: string]: any }) =>
800
+ this.update({
801
+ id,
802
+ type,
803
+ style,
804
+ });
805
+
806
+ if (top) {
807
+ if (isNumber(style.top)) {
808
+ update({
809
+ ...style,
810
+ top: Number(style.top) + Number(top),
811
+ bottom: '',
812
+ });
813
+ } else if (isNumber(style.bottom)) {
814
+ update({
815
+ ...style,
816
+ bottom: Number(style.bottom) - Number(top),
817
+ top: '',
818
+ });
819
+ }
820
+ }
821
+
822
+ if (left) {
823
+ if (isNumber(style.left)) {
824
+ update({
825
+ ...style,
826
+ left: Number(style.left) + Number(left),
827
+ right: '',
828
+ });
829
+ } else if (isNumber(style.right)) {
830
+ update({
831
+ ...style,
832
+ right: Number(style.right) - Number(left),
833
+ left: '',
834
+ });
835
+ }
836
+ }
809
837
  }
810
838
 
811
839
  public resetState() {
@@ -15,3 +15,14 @@
15
15
  }
16
16
  }
17
17
  }
18
+
19
+ .data-source-list-panel-add-menu {
20
+ .tmagic-design-button {
21
+ width: 100%;
22
+ text-align: left;
23
+
24
+ span {
25
+ width: 100%;
26
+ }
27
+ }
28
+ }
@@ -1,76 +1,33 @@
1
- .m-editor-sidebar.tmagic-design-tabs {
1
+ .m-editor-sidebar {
2
+ display: flex;
2
3
  height: 100%;
3
4
 
4
- .el-tabs__header,
5
- .t-tabs__header {
5
+ .m-editor-sidebar-header {
6
6
  background: $--sidebar-heder-background-color;
7
- border: 0;
8
7
  height: 100%;
8
+ width: 40px;
9
9
 
10
- .t-tabs__nav--card {
11
- background-color: transparent;
12
- }
13
-
14
- .t-tabs__nav--card.t-tabs__nav-item:not(.t-is-disabled):not(
15
- .t-is-active
16
- ):hover {
17
- background-color: transparent;
18
- }
19
-
20
- &.is-left,
21
- &.t-is-left {
22
- width: 40px;
23
- margin-right: 0;
24
- }
25
-
26
- .el-tabs__nav-wrap {
27
- margin: 0;
28
- }
29
-
30
- .el-tabs__nav {
31
- border: 0;
32
- border-radius: 0;
33
- }
34
-
35
- .tab-label {
36
- margin-left: 2px;
37
- }
38
-
39
- .el-tabs__item.is-left,
40
- .t-tabs__nav-item {
10
+ .m-editor-sidebar-header-item {
41
11
  line-height: 15px;
42
- border: 0;
43
12
  height: auto;
44
13
  padding: 8px;
45
14
  color: rgb(255, 255, 255);
46
15
  box-sizing: border-box;
16
+ cursor: pointer;
47
17
 
48
- &.is-left,
49
- &.t-is-left {
50
- &.is-active,
51
- &.t-is-active {
52
- background: $--sidebar-content-background-color;
53
- border: 0;
54
-
55
- i {
56
- color: #353140;
57
- }
18
+ &.is-active {
19
+ background: $--sidebar-content-background-color;
58
20
 
59
- .magic-editor-tab-panel-title {
60
- color: #353140;
61
- }
21
+ i {
22
+ color: #353140;
62
23
  }
63
24
 
64
- &:first-child {
65
- border-right: 0;
25
+ .magic-editor-tab-panel-title {
26
+ color: #353140;
66
27
  }
67
28
  }
68
29
  }
69
30
 
70
- .t-tabs__nav-item {
71
- padding: 7px;
72
- }
73
-
74
31
  i {
75
32
  font-size: 25px;
76
33
  color: rgba(255, 255, 255, 0.6);
@@ -86,6 +43,12 @@
86
43
  }
87
44
  }
88
45
 
46
+ .m-editor-sidebar-content {
47
+ height: 100%;
48
+ width: calc(100% - 40px);
49
+ overflow: auto;
50
+ }
51
+
89
52
  .el-scrollbar {
90
53
  height: 100%;
91
54
  }
@@ -109,9 +72,4 @@
109
72
  background: rgba(0, 0, 0, 0.2);
110
73
  }
111
74
  }
112
-
113
- .el-tabs__content,
114
- .el-tab-pane {
115
- height: 100%;
116
- }
117
75
  }
@@ -1,8 +1,6 @@
1
1
  import type { FormConfig } from '@tmagic/form';
2
2
 
3
- import type { DatasourceTypeOption } from '@editor/type';
4
-
5
- export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormConfig {
3
+ export default function (): FormConfig {
6
4
  return [
7
5
  {
8
6
  name: 'id',
@@ -11,12 +9,7 @@ export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormC
11
9
  {
12
10
  name: 'type',
13
11
  text: '类型',
14
- type: 'select',
15
- options: [
16
- { text: '基础', value: 'base' },
17
- { text: 'HTTP', value: 'http' },
18
- ...datasourceTypeList.map((item) => ({ text: item.text, value: item.type })),
19
- ],
12
+ type: 'hidden',
20
13
  defaultValue: 'base',
21
14
  },
22
15
  {
@@ -1,13 +1,11 @@
1
1
  import { FormConfig } from '@tmagic/form';
2
2
  import { DataSchema, DataSourceSchema } from '@tmagic/schema';
3
3
 
4
- import { DatasourceTypeOption } from '@editor/type';
5
-
6
4
  import BaseFormConfig from './formConfigs/base';
7
5
  import HttpFormConfig from './formConfigs/http';
8
6
 
9
- const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption[]): FormConfig => [
10
- ...BaseFormConfig(datasourceTypeList),
7
+ const fillConfig = (config: FormConfig): FormConfig => [
8
+ ...BaseFormConfig(),
11
9
  ...config,
12
10
  {
13
11
  type: 'panel',
@@ -16,7 +14,7 @@ const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption
16
14
  {
17
15
  name: 'fields',
18
16
  type: 'data-source-fields',
19
- defaultValue: [],
17
+ defaultValue: () => [],
20
18
  },
21
19
  ],
22
20
  },
@@ -27,24 +25,20 @@ const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption
27
25
  {
28
26
  name: 'methods',
29
27
  type: 'data-source-methods',
30
- defaultValue: [],
28
+ defaultValue: () => [],
31
29
  },
32
30
  ],
33
31
  },
34
32
  ];
35
33
 
36
- export const getFormConfig = (
37
- type: string,
38
- datasourceTypeList: DatasourceTypeOption[],
39
- configs: Record<string, FormConfig>,
40
- ): FormConfig => {
34
+ export const getFormConfig = (type: string, configs: Record<string, FormConfig>): FormConfig => {
41
35
  switch (type) {
42
36
  case 'base':
43
- return fillConfig([], datasourceTypeList);
37
+ return fillConfig([]);
44
38
  case 'http':
45
- return fillConfig(HttpFormConfig, datasourceTypeList);
39
+ return fillConfig(HttpFormConfig);
46
40
  default:
47
- return fillConfig(configs[type] || [], datasourceTypeList);
41
+ return fillConfig(configs[type] || []);
48
42
  }
49
43
  };
50
44
 
@@ -1,4 +1,4 @@
1
- import { FieldProps } from '@tmagic/form';
1
+ import { type FieldProps } from '@tmagic/form';
2
2
  declare const _default: import("vue").DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<FieldProps<{
3
3
  type: "data-source-fields";
4
4
  }>>, {
@@ -6,6 +6,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<__
6
6
  customError?: ((id: Id, errorType: CodeDeleteErrorType) => any) | undefined;
7
7
  }>>>, {}, {}>, {
8
8
  "code-block-panel-header"?(_: {}): any;
9
+ "code-block-panel-search"?(_: {}): any;
9
10
  "code-block-panel-tool"?(_: {
10
11
  id: any;
11
12
  data: any;
@@ -1,3 +1,2 @@
1
1
  import type { FormConfig } from '@tmagic/form';
2
- import type { DatasourceTypeOption } from '../../../type';
3
- export default function (datasourceTypeList?: DatasourceTypeOption[]): FormConfig;
2
+ export default function (): FormConfig;
@@ -1,7 +1,6 @@
1
1
  import { FormConfig } from '@tmagic/form';
2
2
  import { DataSourceSchema } from '@tmagic/schema';
3
- import { DatasourceTypeOption } from '../../type';
4
- export declare const getFormConfig: (type: string, datasourceTypeList: DatasourceTypeOption[], configs: Record<string, FormConfig>) => FormConfig;
3
+ export declare const getFormConfig: (type: string, configs: Record<string, FormConfig>) => FormConfig;
5
4
  export declare const getDisplayField: (dataSources: DataSourceSchema[], key: string) => {
6
5
  value: string;
7
6
  type: 'var' | 'text';