@tmagic/editor 1.4.0 → 1.4.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/dist/tmagic-editor.js +236 -182
- package/dist/tmagic-editor.umd.cjs +255 -201
- package/package.json +11 -11
- package/src/components/SplitView.vue +5 -0
- package/src/fields/CodeSelect.vue +11 -2
- package/src/fields/DataSourceFieldSelect.vue +34 -3
- package/src/hooks/use-data-source-edit.ts +46 -0
- package/src/layouts/Framework.vue +4 -1
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +4 -30
- package/src/services/editor.ts +5 -1
- package/types/hooks/use-data-source-edit.d.ts +81 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.4.
|
|
2
|
+
"version": "1.4.2",
|
|
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.
|
|
46
|
-
"@tmagic/dep": "1.4.
|
|
47
|
-
"@tmagic/design": "1.4.
|
|
48
|
-
"@tmagic/form": "1.4.
|
|
49
|
-
"@tmagic/schema": "1.4.
|
|
50
|
-
"@tmagic/stage": "1.4.
|
|
51
|
-
"@tmagic/table": "1.4.
|
|
52
|
-
"@tmagic/utils": "1.4.
|
|
45
|
+
"@tmagic/core": "1.4.2",
|
|
46
|
+
"@tmagic/dep": "1.4.2",
|
|
47
|
+
"@tmagic/design": "1.4.2",
|
|
48
|
+
"@tmagic/form": "1.4.2",
|
|
49
|
+
"@tmagic/schema": "1.4.2",
|
|
50
|
+
"@tmagic/stage": "1.4.2",
|
|
51
|
+
"@tmagic/table": "1.4.2",
|
|
52
|
+
"@tmagic/utils": "1.4.2",
|
|
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.
|
|
67
|
-
"@tmagic/form": "1.4.
|
|
66
|
+
"@tmagic/design": "1.4.2",
|
|
67
|
+
"@tmagic/form": "1.4.2",
|
|
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
|
-
<
|
|
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,6 +14,14 @@
|
|
|
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
|
+
link
|
|
21
|
+
:size="size"
|
|
22
|
+
@click="editHandler(selectedDataSourceId)"
|
|
23
|
+
><MIcon :icon="Edit"></MIcon
|
|
24
|
+
></TMagicButton>
|
|
17
25
|
<TMagicButton
|
|
18
26
|
v-if="config.fieldConfig"
|
|
19
27
|
style="margin-left: 5px"
|
|
@@ -23,12 +31,20 @@
|
|
|
23
31
|
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
|
24
32
|
><MIcon :icon="Coin"></MIcon
|
|
25
33
|
></TMagicButton>
|
|
34
|
+
|
|
35
|
+
<DataSourceConfigPanel
|
|
36
|
+
ref="editDialog"
|
|
37
|
+
:disabled="!editable"
|
|
38
|
+
:values="dataSourceValues"
|
|
39
|
+
:title="dialogTitle"
|
|
40
|
+
@submit="submitDataSourceHandler"
|
|
41
|
+
></DataSourceConfigPanel>
|
|
26
42
|
</div>
|
|
27
43
|
</template>
|
|
28
44
|
|
|
29
45
|
<script setup lang="ts">
|
|
30
46
|
import { computed, inject, onMounted, ref, resolveComponent } from 'vue';
|
|
31
|
-
import { Coin } from '@element-plus/icons-vue';
|
|
47
|
+
import { Coin, Edit } from '@element-plus/icons-vue';
|
|
32
48
|
|
|
33
49
|
import { TMagicButton } from '@tmagic/design';
|
|
34
50
|
import type { CascaderConfig, CascaderOption, FieldProps, FormState } from '@tmagic/form';
|
|
@@ -37,6 +53,8 @@ import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
|
|
|
37
53
|
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
|
38
54
|
|
|
39
55
|
import MIcon from '@editor/components/Icon.vue';
|
|
56
|
+
import { useDataSourceEdit } from '@editor/hooks/use-data-source-edit';
|
|
57
|
+
import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
|
|
40
58
|
import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
|
|
41
59
|
|
|
42
60
|
defineOptions({
|
|
@@ -50,6 +68,15 @@ const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(
|
|
|
50
68
|
disabled: false,
|
|
51
69
|
});
|
|
52
70
|
|
|
71
|
+
const selectedDataSourceId = computed(() => {
|
|
72
|
+
const value = props.model[props.name];
|
|
73
|
+
if (!Array.isArray(value) || !value.length) {
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return value[0].replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '');
|
|
78
|
+
});
|
|
79
|
+
|
|
53
80
|
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
54
81
|
|
|
55
82
|
const getOptionChildren = (
|
|
@@ -76,7 +103,7 @@ const getOptionChildren = (
|
|
|
76
103
|
return;
|
|
77
104
|
}
|
|
78
105
|
|
|
79
|
-
if (!dataSourceFieldType.includes(fieldType) &&
|
|
106
|
+
if (!dataSourceFieldType.includes(fieldType) && !['array', 'object', 'any'].includes(fieldType)) {
|
|
80
107
|
return;
|
|
81
108
|
}
|
|
82
109
|
|
|
@@ -117,7 +144,7 @@ onMounted(() => {
|
|
|
117
144
|
typeof value[0] === 'string' &&
|
|
118
145
|
value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
|
|
119
146
|
) {
|
|
120
|
-
|
|
147
|
+
showDataSourceFieldSelect.value = true;
|
|
121
148
|
}
|
|
122
149
|
});
|
|
123
150
|
|
|
@@ -148,4 +175,8 @@ const tagName = computed(() => {
|
|
|
148
175
|
const onChangeHandler = (value: any) => {
|
|
149
176
|
emit('change', value);
|
|
150
177
|
};
|
|
178
|
+
|
|
179
|
+
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } = useDataSourceEdit(
|
|
180
|
+
services?.dataSourceService,
|
|
181
|
+
);
|
|
151
182
|
</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:
|
|
111
|
+
right: getRightColumnWidthCacheData(),
|
|
109
112
|
});
|
|
110
113
|
|
|
111
114
|
watch(pageLength, () => {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
</div>
|
|
26
26
|
|
|
27
27
|
<!-- 数据源列表 -->
|
|
28
|
-
<DataSourceList @edit="editHandler" @remove="removeHandler"></DataSourceList>
|
|
28
|
+
<DataSourceList ref="dataSourceList" @edit="editHandler" @remove="removeHandler"></DataSourceList>
|
|
29
29
|
</TMagicScrollbar>
|
|
30
30
|
|
|
31
31
|
<DataSourceConfigPanel
|
|
@@ -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
|
|
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) => {
|
package/src/services/editor.ts
CHANGED
|
@@ -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
|
+
};
|