@tmagic/editor 1.4.1 → 1.4.3

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.4.1",
2
+ "version": "1.4.3",
3
3
  "name": "@tmagic/editor",
4
4
  "type": "module",
5
5
  "sideEffects": [
@@ -42,14 +42,14 @@
42
42
  "dependencies": {
43
43
  "@babel/core": "^7.18.0",
44
44
  "@element-plus/icons-vue": "^2.3.1",
45
- "@tmagic/core": "1.4.1",
46
- "@tmagic/dep": "1.4.1",
47
- "@tmagic/design": "1.4.1",
48
- "@tmagic/form": "1.4.1",
49
- "@tmagic/schema": "1.4.1",
50
- "@tmagic/stage": "1.4.1",
51
- "@tmagic/table": "1.4.1",
52
- "@tmagic/utils": "1.4.1",
45
+ "@tmagic/core": "1.4.3",
46
+ "@tmagic/dep": "1.4.3",
47
+ "@tmagic/design": "1.4.3",
48
+ "@tmagic/form": "1.4.3",
49
+ "@tmagic/schema": "1.4.3",
50
+ "@tmagic/stage": "1.4.3",
51
+ "@tmagic/table": "1.4.3",
52
+ "@tmagic/utils": "1.4.3",
53
53
  "buffer": "^6.0.3",
54
54
  "color": "^3.1.3",
55
55
  "emmet-monaco-es": "^5.3.0",
@@ -63,8 +63,8 @@
63
63
  "vue": "^3.4.21"
64
64
  },
65
65
  "peerDependencies": {
66
- "@tmagic/design": "1.4.1",
67
- "@tmagic/form": "1.4.1",
66
+ "@tmagic/design": "1.4.3",
67
+ "@tmagic/form": "1.4.3",
68
68
  "monaco-editor": "^0.47.0",
69
69
  "vue": "^3.4.21"
70
70
  },
@@ -169,6 +169,11 @@ const changeRight = ({ deltaX }: OnDrag) => {
169
169
  defineExpose({
170
170
  updateWidth() {
171
171
  clientWidth = props.width ?? el.value?.clientWidth ?? clientWidth;
172
+
173
+ if (clientWidth <= 0) {
174
+ return;
175
+ }
176
+
172
177
  const columnWidth = getCenterWidth(props.left, props.right);
173
178
 
174
179
  emit('change', {
@@ -1,7 +1,16 @@
1
1
  <template>
2
2
  <div class="m-fields-code-select" :class="config.className">
3
3
  <TMagicCard>
4
- <m-form-container :config="codeConfig" :model="model[name]" @change="changeHandler"> </m-form-container>
4
+ <MContainer
5
+ :config="codeConfig"
6
+ :size="size"
7
+ :prop="prop"
8
+ :disabled="disabled"
9
+ :lastValues="lastValues"
10
+ :model="model[name]"
11
+ @change="changeHandler"
12
+ >
13
+ </MContainer>
5
14
  </TMagicCard>
6
15
  </div>
7
16
  </template>
@@ -12,7 +21,7 @@ import { isEmpty } from 'lodash-es';
12
21
 
13
22
  import { TMagicCard } from '@tmagic/design';
14
23
  import type { FieldProps, FormItem } from '@tmagic/form';
15
- import { FormState } from '@tmagic/form';
24
+ import { FormState, MContainer } from '@tmagic/form';
16
25
  import { HookCodeType, HookType } from '@tmagic/schema';
17
26
 
18
27
  import type { Services } from '@editor/type';
@@ -14,21 +14,35 @@
14
14
  :prop="`${prop}${prop ? '.' : ''}${name}`"
15
15
  @change="onChangeHandler"
16
16
  ></component>
17
+ <TMagicButton
18
+ v-if="(showDataSourceFieldSelect || !config.fieldConfig) && selectedDataSourceId"
19
+ style="margin-left: 5px"
20
+ :size="size"
21
+ @click="editHandler(selectedDataSourceId)"
22
+ ><MIcon :icon="Edit"></MIcon
23
+ ></TMagicButton>
17
24
  <TMagicButton
18
25
  v-if="config.fieldConfig"
19
26
  style="margin-left: 5px"
20
- link
21
27
  :type="showDataSourceFieldSelect ? 'primary' : 'default'"
22
28
  :size="size"
23
29
  @click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
24
30
  ><MIcon :icon="Coin"></MIcon
25
31
  ></TMagicButton>
32
+
33
+ <DataSourceConfigPanel
34
+ ref="editDialog"
35
+ :disabled="!editable"
36
+ :values="dataSourceValues"
37
+ :title="dialogTitle"
38
+ @submit="submitDataSourceHandler"
39
+ ></DataSourceConfigPanel>
26
40
  </div>
27
41
  </template>
28
42
 
29
43
  <script setup lang="ts">
30
- import { computed, inject, onMounted, ref, resolveComponent } from 'vue';
31
- import { Coin } from '@element-plus/icons-vue';
44
+ import { computed, inject, ref, resolveComponent, watch } from 'vue';
45
+ import { Coin, Edit } from '@element-plus/icons-vue';
32
46
 
33
47
  import { TMagicButton } from '@tmagic/design';
34
48
  import type { CascaderConfig, CascaderOption, FieldProps, FormState } from '@tmagic/form';
@@ -37,6 +51,8 @@ import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
37
51
  import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
38
52
 
39
53
  import MIcon from '@editor/components/Icon.vue';
54
+ import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
55
+ import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
40
56
  import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
41
57
 
42
58
  defineOptions({
@@ -50,6 +66,15 @@ const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(
50
66
  disabled: false,
51
67
  });
52
68
 
69
+ const selectedDataSourceId = computed(() => {
70
+ const value = props.model[props.name];
71
+ if (!Array.isArray(value) || !value.length) {
72
+ return '';
73
+ }
74
+
75
+ return value[0].replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '');
76
+ });
77
+
53
78
  const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
54
79
 
55
80
  const getOptionChildren = (
@@ -76,7 +101,7 @@ const getOptionChildren = (
76
101
  return;
77
102
  }
78
103
 
79
- if (!dataSourceFieldType.includes(fieldType) && fieldType !== 'object') {
104
+ if (!dataSourceFieldType.includes(fieldType) && !['array', 'object', 'any'].includes(fieldType)) {
80
105
  return;
81
106
  }
82
107
 
@@ -110,16 +135,23 @@ const cascaderConfig = computed<CascaderConfig>(() => {
110
135
 
111
136
  const showDataSourceFieldSelect = ref(false);
112
137
 
113
- onMounted(() => {
114
- const value = props.model[props.name];
115
- if (
116
- Array.isArray(value) &&
117
- typeof value[0] === 'string' &&
118
- value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
119
- ) {
120
- return (showDataSourceFieldSelect.value = true);
121
- }
122
- });
138
+ watch(
139
+ () => props.model[props.name],
140
+ (value) => {
141
+ if (
142
+ Array.isArray(value) &&
143
+ typeof value[0] === 'string' &&
144
+ value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
145
+ ) {
146
+ showDataSourceFieldSelect.value = true;
147
+ } else {
148
+ showDataSourceFieldSelect.value = false;
149
+ }
150
+ },
151
+ {
152
+ immediate: true,
153
+ },
154
+ );
123
155
 
124
156
  const mForm = inject<FormState | undefined>('mForm');
125
157
 
@@ -148,4 +180,8 @@ const tagName = computed(() => {
148
180
  const onChangeHandler = (value: any) => {
149
181
  emit('change', value);
150
182
  };
183
+
184
+ const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } = useDataSourceEdit(
185
+ services?.dataSourceService,
186
+ );
151
187
  </script>
@@ -0,0 +1,46 @@
1
+ import { computed, ref } from 'vue';
2
+
3
+ import type { DataSourceSchema } from '@tmagic/schema';
4
+
5
+ import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
6
+ import type { DataSourceService } from '@editor/services/dataSource';
7
+
8
+ export const useDataSourceEdit = (dataSourceService?: DataSourceService) => {
9
+ const dialogTitle = ref('');
10
+ const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
11
+ const dataSourceValues = ref<Record<string, any>>({});
12
+
13
+ const editable = computed(() => dataSourceService?.get('editable') ?? true);
14
+
15
+ const editHandler = (id: string) => {
16
+ if (!editDialog.value) return;
17
+
18
+ dataSourceValues.value = {
19
+ ...dataSourceService?.getDataSourceById(id),
20
+ };
21
+
22
+ dialogTitle.value = `编辑${dataSourceValues.value.title || ''}`;
23
+
24
+ editDialog.value.show();
25
+ };
26
+
27
+ const submitDataSourceHandler = (value: DataSourceSchema) => {
28
+ if (value.id) {
29
+ dataSourceService?.update(value);
30
+ } else {
31
+ dataSourceService?.add(value);
32
+ }
33
+
34
+ editDialog.value?.hide();
35
+ };
36
+
37
+ return {
38
+ dialogTitle,
39
+ editDialog,
40
+ dataSourceValues,
41
+ editable,
42
+
43
+ editHandler,
44
+ submitDataSourceHandler,
45
+ };
46
+ };
@@ -102,10 +102,13 @@ const RIGHT_COLUMN_WIDTH_STORAGE_KEY = '$MagicEditorRightColumnWidthData';
102
102
  const getLeftColumnWidthCacheData = () =>
103
103
  Number(globalThis.localStorage.getItem(LEFT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_LEFT_COLUMN_WIDTH;
104
104
 
105
+ const getRightColumnWidthCacheData = () =>
106
+ Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH;
107
+
105
108
  const columnWidth = ref<Partial<GetColumnWidth>>({
106
109
  left: getLeftColumnWidthCacheData(),
107
110
  center: 0,
108
- right: Number(globalThis.localStorage.getItem(RIGHT_COLUMN_WIDTH_STORAGE_KEY)) || DEFAULT_RIGHT_COLUMN_WIDTH,
111
+ right: getRightColumnWidthCacheData(),
109
112
  });
110
113
 
111
114
  watch(pageLength, () => {
@@ -42,10 +42,10 @@ import { computed, inject, ref } from 'vue';
42
42
  import { mergeWith } from 'lodash-es';
43
43
 
44
44
  import { TMagicButton, TMagicPopover, TMagicScrollbar } from '@tmagic/design';
45
- import type { DataSourceSchema } from '@tmagic/schema';
46
45
 
47
46
  import SearchInput from '@editor/components/SearchInput.vue';
48
47
  import ToolButton from '@editor/components/ToolButton.vue';
48
+ import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
49
49
  import type { DataSourceListSlots, Services } from '@editor/type';
50
50
 
51
51
  import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
@@ -59,13 +59,9 @@ defineOptions({
59
59
 
60
60
  const { dataSourceService } = inject<Services>('services') || {};
61
61
 
62
- const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
62
+ const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
63
+ useDataSourceEdit(dataSourceService);
63
64
 
64
- const dataSourceValues = ref<Record<string, any>>({});
65
-
66
- const dialogTitle = ref('');
67
-
68
- const editable = computed(() => dataSourceService?.get('editable') ?? true);
69
65
  const datasourceTypeList = computed(() =>
70
66
  [
71
67
  { text: '基础', type: 'base' },
@@ -93,32 +89,10 @@ const addHandler = (type: string) => {
93
89
  editDialog.value.show();
94
90
  };
95
91
 
96
- const editHandler = (id: string) => {
97
- if (!editDialog.value) return;
98
-
99
- dataSourceValues.value = {
100
- ...dataSourceService?.getDataSourceById(id),
101
- };
102
-
103
- dialogTitle.value = `编辑${dataSourceValues.value.title || ''}`;
104
-
105
- editDialog.value.show();
106
- };
107
-
108
92
  const removeHandler = (id: string) => {
109
93
  dataSourceService?.remove(id);
110
94
  };
111
95
 
112
- const submitDataSourceHandler = (value: DataSourceSchema) => {
113
- if (value.id) {
114
- dataSourceService?.update(value);
115
- } else {
116
- dataSourceService?.add(value);
117
- }
118
-
119
- editDialog.value?.hide();
120
- };
121
-
122
96
  const dataSourceList = ref<InstanceType<typeof DataSourceList>>();
123
97
 
124
98
  const filterTextChangeHandler = (val: string) => {
@@ -533,7 +533,11 @@ class Editor extends BaseService {
533
533
 
534
534
  let newConfig = await this.toggleFixedPosition(toRaw(config), node, root);
535
535
 
536
- newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue) => {
536
+ newConfig = mergeWith(cloneDeep(node), newConfig, (objValue, srcValue, key) => {
537
+ if (typeof srcValue === 'undefined' && Object.hasOwn(newConfig, key)) {
538
+ return '';
539
+ }
540
+
537
541
  if (isObject(srcValue) && Array.isArray(objValue)) {
538
542
  // 原来的配置是数组,新的配置是对象,则直接使用新的值
539
543
  return srcValue;
@@ -0,0 +1,81 @@
1
+ import type { DataSourceSchema } from '@tmagic/schema';
2
+ import type { DataSourceService } from '../services/dataSource';
3
+ export declare const useDataSourceEdit: (dataSourceService?: DataSourceService) => {
4
+ dialogTitle: import("vue").Ref<string>;
5
+ editDialog: import("vue").Ref<import("vue").CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
6
+ visible: import("vue").PropType<boolean>;
7
+ width: import("vue").PropType<number>;
8
+ title: {
9
+ type: import("vue").PropType<string>;
10
+ };
11
+ values: {
12
+ type: import("vue").PropType<any>;
13
+ required: true;
14
+ };
15
+ disabled: {
16
+ type: import("vue").PropType<boolean>;
17
+ required: true;
18
+ };
19
+ }>> & {
20
+ onSubmit?: ((...args: any[]) => any) | undefined;
21
+ "onUpdate:width"?: ((width: number) => any) | undefined;
22
+ "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
23
+ }, {
24
+ show(): void;
25
+ hide(): void;
26
+ }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
27
+ "update:width": (width: number) => void;
28
+ "update:visible": (visible: boolean) => void;
29
+ submit: (...args: any[]) => void;
30
+ }, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
31
+ visible: import("vue").PropType<boolean>;
32
+ width: import("vue").PropType<number>;
33
+ title: {
34
+ type: import("vue").PropType<string>;
35
+ };
36
+ values: {
37
+ type: import("vue").PropType<any>;
38
+ required: true;
39
+ };
40
+ disabled: {
41
+ type: import("vue").PropType<boolean>;
42
+ required: true;
43
+ };
44
+ }>> & {
45
+ onSubmit?: ((...args: any[]) => any) | undefined;
46
+ "onUpdate:width"?: ((width: number) => any) | undefined;
47
+ "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
48
+ }, {}, true, {}, {}, {
49
+ P: {};
50
+ B: {};
51
+ D: {};
52
+ C: {};
53
+ M: {};
54
+ Defaults: {};
55
+ }, Readonly<import("vue").ExtractPropTypes<{
56
+ visible: import("vue").PropType<boolean>;
57
+ width: import("vue").PropType<number>;
58
+ title: {
59
+ type: import("vue").PropType<string>;
60
+ };
61
+ values: {
62
+ type: import("vue").PropType<any>;
63
+ required: true;
64
+ };
65
+ disabled: {
66
+ type: import("vue").PropType<boolean>;
67
+ required: true;
68
+ };
69
+ }>> & {
70
+ onSubmit?: ((...args: any[]) => any) | undefined;
71
+ "onUpdate:width"?: ((width: number) => any) | undefined;
72
+ "onUpdate:visible"?: ((visible: boolean) => any) | undefined;
73
+ }, {
74
+ show(): void;
75
+ hide(): void;
76
+ }, {}, {}, {}, {}> | undefined>;
77
+ dataSourceValues: import("vue").Ref<Record<string, any>>;
78
+ editable: import("vue").ComputedRef<boolean>;
79
+ editHandler: (id: string) => void;
80
+ submitDataSourceHandler: (value: DataSourceSchema) => void;
81
+ };