@tmagic/editor 1.3.16 → 1.4.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/dist/style.css +25 -9
- package/dist/tmagic-editor.js +1048 -632
- package/dist/tmagic-editor.umd.cjs +1065 -647
- package/package.json +23 -21
- package/src/components/CodeBlockEditor.vue +82 -59
- package/src/components/FloatingBox.vue +71 -25
- package/src/components/SplitView.vue +46 -35
- package/src/fields/Code.vue +12 -10
- package/src/fields/CodeLink.vue +9 -9
- package/src/fields/CodeSelect.vue +7 -5
- package/src/fields/CodeSelectCol.vue +1 -1
- package/src/fields/DataSourceFieldSelect.vue +118 -27
- package/src/fields/DataSourceFields.vue +10 -3
- package/src/fields/DataSourceInput.vue +7 -7
- package/src/fields/DataSourceMethodSelect.vue +1 -1
- package/src/fields/DataSourceMethods.vue +3 -3
- package/src/fields/DataSourceMocks.vue +3 -3
- package/src/fields/DataSourceSelect.vue +6 -18
- package/src/fields/EventSelect.vue +1 -1
- package/src/fields/KeyValue.vue +8 -8
- package/src/fields/PageFragmentSelect.vue +1 -1
- package/src/fields/UISelect.vue +5 -5
- package/src/hooks/index.ts +2 -0
- package/src/hooks/use-code-block-edit.ts +1 -2
- package/src/hooks/use-editor-content-height.ts +20 -0
- package/src/hooks/use-float-box.ts +8 -8
- package/src/hooks/use-window-rect.ts +20 -0
- package/src/index.ts +2 -2
- package/src/layouts/Framework.vue +33 -34
- package/src/layouts/NavMenu.vue +21 -2
- package/src/layouts/PropsPanel.vue +35 -0
- package/src/layouts/sidebar/Sidebar.vue +18 -8
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +0 -1
- package/src/layouts/workspace/viewer/NodeListMenu.vue +1 -0
- package/src/services/BaseService.ts +5 -2
- package/src/services/codeBlock.ts +14 -8
- package/src/services/dataSource.ts +39 -26
- package/src/services/editor.ts +46 -25
- package/src/services/events.ts +4 -4
- package/src/services/props.ts +44 -35
- package/src/services/stageOverlay.ts +16 -9
- package/src/services/storage.ts +14 -8
- package/src/services/ui.ts +26 -19
- package/src/theme/code-block.scss +0 -5
- package/src/theme/code-editor.scss +6 -0
- package/src/theme/floating-box.scss +4 -2
- package/src/theme/props-panel.scss +14 -0
- package/src/theme/sidebar.scss +6 -3
- package/src/type.ts +87 -37
- package/src/utils/operator.ts +37 -39
- package/src/utils/props.ts +174 -37
- package/types/components/CodeBlockEditor.vue.d.ts +46 -25
- package/types/components/CodeParams.vue.d.ts +5 -5
- package/types/components/ContentMenu.vue.d.ts +12 -12
- package/types/components/FloatingBox.vue.d.ts +42 -55
- package/types/components/Icon.vue.d.ts +3 -3
- package/types/components/Resizer.vue.d.ts +3 -3
- package/types/components/ScrollBar.vue.d.ts +3 -3
- package/types/components/ScrollViewer.vue.d.ts +12 -12
- package/types/components/SearchInput.vue.d.ts +1 -1
- package/types/components/SplitView.vue.d.ts +13 -11
- package/types/components/ToolButton.vue.d.ts +13 -13
- package/types/components/Tree.vue.d.ts +24 -14
- package/types/components/TreeNode.vue.d.ts +22 -12
- package/types/fields/Code.vue.d.ts +14 -14
- package/types/fields/CodeLink.vue.d.ts +6 -10
- package/types/fields/CodeSelect.vue.d.ts +14 -14
- package/types/fields/CodeSelectCol.vue.d.ts +11 -11
- package/types/fields/DataSourceFieldSelect.vue.d.ts +11 -11
- package/types/fields/DataSourceFields.vue.d.ts +11 -11
- package/types/fields/DataSourceInput.vue.d.ts +14 -18
- package/types/fields/DataSourceMethodSelect.vue.d.ts +11 -11
- package/types/fields/DataSourceMethods.vue.d.ts +11 -11
- package/types/fields/DataSourceMocks.vue.d.ts +11 -11
- package/types/fields/DataSourceSelect.vue.d.ts +13 -26
- package/types/fields/EventSelect.vue.d.ts +3 -3
- package/types/fields/KeyValue.vue.d.ts +14 -18
- package/types/fields/PageFragmentSelect.vue.d.ts +11 -11
- package/types/fields/UISelect.vue.d.ts +8 -4
- package/types/hooks/index.d.ts +2 -0
- package/types/hooks/use-code-block-edit.d.ts +66 -90
- package/types/hooks/use-data-source-method.d.ts +66 -90
- package/types/hooks/use-editor-content-height.d.ts +3 -0
- package/types/hooks/use-node-status.d.ts +6 -1
- package/types/hooks/use-window-rect.d.ts +6 -0
- package/types/icons/AppManageIcon.vue.d.ts +1 -1
- package/types/icons/CenterIcon.vue.d.ts +1 -1
- package/types/icons/CodeIcon.vue.d.ts +1 -1
- package/types/icons/FolderMinusIcon.vue.d.ts +1 -1
- package/types/icons/PinIcon.vue.d.ts +1 -1
- package/types/icons/PinnedIcon.vue.d.ts +1 -1
- package/types/layouts/AddPageBox.vue.d.ts +3 -3
- package/types/layouts/CodeEditor.vue.d.ts +12 -12
- package/types/layouts/Framework.vue.d.ts +9 -9
- package/types/layouts/NavMenu.vue.d.ts +11 -11
- package/types/layouts/PropsPanel.vue.d.ts +193 -243
- package/types/layouts/page-bar/AddButton.vue.d.ts +3 -3
- package/types/layouts/page-bar/PageBar.vue.d.ts +8 -8
- package/types/layouts/page-bar/PageBarScrollContainer.vue.d.ts +8 -8
- package/types/layouts/page-bar/SwitchTypeButton.vue.d.ts +3 -3
- package/types/layouts/sidebar/ComponentListPanel.vue.d.ts +1 -1
- package/types/layouts/sidebar/Sidebar.vue.d.ts +13 -13
- package/types/layouts/sidebar/code-block/CodeBlockList.vue.d.ts +10 -10
- package/types/layouts/sidebar/code-block/CodeBlockListPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/data-source/DataSourceConfigPanel.vue.d.ts +3 -3
- package/types/layouts/sidebar/data-source/DataSourceList.vue.d.ts +3 -3
- package/types/layouts/sidebar/data-source/DataSourceListPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/LayerMenu.vue.d.ts +11 -11
- package/types/layouts/sidebar/layer/LayerNodeTool.vue.d.ts +3 -3
- package/types/layouts/sidebar/layer/LayerPanel.vue.d.ts +9 -9
- package/types/layouts/sidebar/layer/use-click.d.ts +42 -76
- package/types/layouts/sidebar/layer/use-node-status.d.ts +6 -1
- package/types/layouts/workspace/Breadcrumb.vue.d.ts +1 -1
- package/types/layouts/workspace/Workspace.vue.d.ts +12 -12
- package/types/layouts/workspace/viewer/NodeListMenu.vue.d.ts +1 -1
- package/types/layouts/workspace/viewer/Stage.vue.d.ts +11 -11
- package/types/layouts/workspace/viewer/StageOverlay.vue.d.ts +1 -1
- package/types/layouts/workspace/viewer/ViewerMenu.vue.d.ts +12 -12
- package/types/services/BaseService.d.ts +5 -2
- package/types/services/codeBlock.d.ts +8 -0
- package/types/services/dataSource.d.ts +9 -2
- package/types/services/editor.d.ts +8 -1
- package/types/services/props.d.ts +15 -22
- package/types/services/stageOverlay.d.ts +9 -2
- package/types/services/storage.d.ts +8 -0
- package/types/services/ui.d.ts +20 -8
- package/types/type.d.ts +56 -32
- package/types/utils/operator.d.ts +1 -1
- package/types/utils/props.d.ts +2 -13
package/src/fields/CodeLink.vue
CHANGED
|
@@ -6,22 +6,22 @@
|
|
|
6
6
|
import { computed, reactive, watch } from 'vue';
|
|
7
7
|
import serialize from 'serialize-javascript';
|
|
8
8
|
|
|
9
|
-
import type { FieldProps } from '@tmagic/form';
|
|
9
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
10
10
|
|
|
11
11
|
import { getConfig } from '@editor/utils/config';
|
|
12
12
|
|
|
13
13
|
defineOptions({
|
|
14
|
-
name: '
|
|
14
|
+
name: 'MFieldsCodeLink',
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
const props = defineProps<
|
|
18
|
-
FieldProps<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
FieldProps<
|
|
19
|
+
{
|
|
20
|
+
type: 'code-link';
|
|
21
|
+
formTitle?: string;
|
|
22
|
+
codeOptions?: Object;
|
|
23
|
+
} & FormItem
|
|
24
|
+
>
|
|
25
25
|
>();
|
|
26
26
|
|
|
27
27
|
const emit = defineEmits(['change']);
|
|
@@ -11,14 +11,14 @@ import { computed, inject, watch } from 'vue';
|
|
|
11
11
|
import { isEmpty } from 'lodash-es';
|
|
12
12
|
|
|
13
13
|
import { TMagicCard } from '@tmagic/design';
|
|
14
|
-
import type { FieldProps } from '@tmagic/form';
|
|
14
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
15
15
|
import { FormState } from '@tmagic/form';
|
|
16
16
|
import { HookCodeType, HookType } from '@tmagic/schema';
|
|
17
17
|
|
|
18
18
|
import type { Services } from '@editor/type';
|
|
19
19
|
|
|
20
20
|
defineOptions({
|
|
21
|
-
name: '
|
|
21
|
+
name: 'MFieldsCodeSelect',
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
const emit = defineEmits(['change']);
|
|
@@ -27,9 +27,11 @@ const services = inject<Services>('services');
|
|
|
27
27
|
|
|
28
28
|
const props = withDefaults(
|
|
29
29
|
defineProps<
|
|
30
|
-
FieldProps<
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
FieldProps<
|
|
31
|
+
{
|
|
32
|
+
className?: string;
|
|
33
|
+
} & FormItem
|
|
34
|
+
>
|
|
33
35
|
>(),
|
|
34
36
|
{},
|
|
35
37
|
);
|
|
@@ -49,7 +49,7 @@ import { useCodeBlockEdit } from '@editor/hooks/use-code-block-edit';
|
|
|
49
49
|
import type { CodeParamStatement, CodeSelectColConfig, Services } from '@editor/type';
|
|
50
50
|
|
|
51
51
|
defineOptions({
|
|
52
|
-
name: '
|
|
52
|
+
name: 'MFieldsCodeSelectCol',
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const mForm = inject<FormState | undefined>('mForm');
|
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
<div style="width: 100%; display: flex; align-items: center">
|
|
3
|
+
<component
|
|
4
|
+
style="width: 100%"
|
|
5
|
+
:is="tagName"
|
|
6
|
+
:config="showDataSourceFieldSelect || !config.fieldConfig ? cascaderConfig : config.fieldConfig"
|
|
7
|
+
:model="model"
|
|
8
|
+
:name="name"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
:size="size"
|
|
11
|
+
:last-values="lastValues"
|
|
12
|
+
:init-values="initValues"
|
|
13
|
+
:values="values"
|
|
14
|
+
:prop="`${prop}${prop ? '.' : ''}${name}`"
|
|
15
|
+
@change="onChangeHandler"
|
|
16
|
+
></component>
|
|
17
|
+
<TMagicButton
|
|
18
|
+
v-if="config.fieldConfig"
|
|
19
|
+
style="margin-left: 5px"
|
|
20
|
+
link
|
|
21
|
+
:type="showDataSourceFieldSelect ? 'primary' : 'default'"
|
|
22
|
+
:icon="Coin"
|
|
23
|
+
:size="size"
|
|
24
|
+
@click="showDataSourceFieldSelect = !showDataSourceFieldSelect"
|
|
25
|
+
></TMagicButton>
|
|
26
|
+
</div>
|
|
10
27
|
</template>
|
|
11
28
|
|
|
12
29
|
<script setup lang="ts">
|
|
13
|
-
import { computed, inject } from 'vue';
|
|
30
|
+
import { computed, inject, onMounted, ref, resolveComponent } from 'vue';
|
|
31
|
+
import { Coin } from '@element-plus/icons-vue';
|
|
14
32
|
|
|
15
|
-
import
|
|
16
|
-
import type {
|
|
33
|
+
import { TMagicButton } from '@tmagic/design';
|
|
34
|
+
import type { CascaderConfig, CascaderOption, FieldProps, FormState } from '@tmagic/form';
|
|
35
|
+
import { MCascader } from '@tmagic/form';
|
|
36
|
+
import type { DataSchema, DataSourceFieldType } from '@tmagic/schema';
|
|
17
37
|
import { DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX } from '@tmagic/utils';
|
|
18
38
|
|
|
19
39
|
import type { DataSourceFieldSelectConfig, Services } from '@editor/type';
|
|
20
40
|
|
|
41
|
+
defineOptions({
|
|
42
|
+
name: 'MFieldsDataSourceFieldSelect',
|
|
43
|
+
});
|
|
44
|
+
|
|
21
45
|
const services = inject<Services>('services');
|
|
22
46
|
const emit = defineEmits(['change']);
|
|
23
47
|
|
|
@@ -27,32 +51,99 @@ const props = withDefaults(defineProps<FieldProps<DataSourceFieldSelectConfig>>(
|
|
|
27
51
|
|
|
28
52
|
const dataSources = computed(() => services?.dataSourceService.get('dataSources'));
|
|
29
53
|
|
|
30
|
-
const getOptionChildren = (
|
|
31
|
-
fields
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
54
|
+
const getOptionChildren = (
|
|
55
|
+
fields: DataSchema[] = [],
|
|
56
|
+
dataSourceFieldType: DataSourceFieldType[] = ['any'],
|
|
57
|
+
): CascaderOption[] => {
|
|
58
|
+
const child: CascaderOption[] = [];
|
|
59
|
+
fields.forEach((field) => {
|
|
60
|
+
if (!dataSourceFieldType.length) {
|
|
61
|
+
dataSourceFieldType.push('any');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const children = getOptionChildren(field.fields, dataSourceFieldType);
|
|
65
|
+
|
|
66
|
+
const item = {
|
|
67
|
+
label: field.title || field.name,
|
|
68
|
+
value: field.name,
|
|
69
|
+
children,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const fieldType = field.type || 'any';
|
|
73
|
+
if (dataSourceFieldType.includes('any') || dataSourceFieldType.includes(fieldType)) {
|
|
74
|
+
child.push(item);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!dataSourceFieldType.includes(fieldType) && fieldType !== 'object') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!children.length && ['object', 'array', 'any'].includes(field.type || '')) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
child.push(item);
|
|
87
|
+
});
|
|
88
|
+
return child;
|
|
89
|
+
};
|
|
36
90
|
|
|
37
|
-
const cascaderConfig = computed(() => {
|
|
91
|
+
const cascaderConfig = computed<CascaderConfig>(() => {
|
|
38
92
|
const valueIsKey = props.config.value === 'key';
|
|
39
93
|
|
|
40
94
|
return {
|
|
41
95
|
type: 'cascader',
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
?.filter((ds) => ds.fields?.length)
|
|
48
|
-
?.map((ds) => ({
|
|
96
|
+
checkStrictly: props.config.checkStrictly ?? !valueIsKey,
|
|
97
|
+
popperClass: 'm-editor-data-source-field-select-popper',
|
|
98
|
+
options: () => {
|
|
99
|
+
const options =
|
|
100
|
+
dataSources.value?.map((ds) => ({
|
|
49
101
|
label: ds.title || ds.id,
|
|
50
102
|
value: valueIsKey ? ds.id : `${DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX}${ds.id}`,
|
|
51
|
-
children: getOptionChildren(ds.fields),
|
|
52
|
-
})) || []
|
|
103
|
+
children: getOptionChildren(ds.fields, props.config.dataSourceFieldType),
|
|
104
|
+
})) || [];
|
|
105
|
+
return options.filter((option) => option.children.length);
|
|
106
|
+
},
|
|
53
107
|
};
|
|
54
108
|
});
|
|
55
109
|
|
|
110
|
+
const showDataSourceFieldSelect = ref(false);
|
|
111
|
+
|
|
112
|
+
onMounted(() => {
|
|
113
|
+
const value = props.model[props.name];
|
|
114
|
+
if (
|
|
115
|
+
Array.isArray(value) &&
|
|
116
|
+
typeof value[0] === 'string' &&
|
|
117
|
+
value[0].startsWith(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX)
|
|
118
|
+
) {
|
|
119
|
+
return (showDataSourceFieldSelect.value = true);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const mForm = inject<FormState | undefined>('mForm');
|
|
124
|
+
|
|
125
|
+
const type = computed((): string => {
|
|
126
|
+
let type = props.config.fieldConfig?.type;
|
|
127
|
+
if (typeof type === 'function') {
|
|
128
|
+
type = type(mForm, {
|
|
129
|
+
model: props.model,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (type === 'form') return '';
|
|
133
|
+
if (type === 'container') return '';
|
|
134
|
+
return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (props.config.items ? '' : 'text');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const tagName = computed(() => {
|
|
138
|
+
if (showDataSourceFieldSelect.value || !props.config.fieldConfig) {
|
|
139
|
+
return MCascader;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const component = resolveComponent(`m-${props.config.items ? 'form' : 'fields'}-${type.value}`);
|
|
143
|
+
if (typeof component !== 'string') return component;
|
|
144
|
+
return 'm-fields-text';
|
|
145
|
+
});
|
|
146
|
+
|
|
56
147
|
const onChangeHandler = (value: any) => {
|
|
57
148
|
emit('change', value);
|
|
58
149
|
};
|
|
@@ -37,13 +37,13 @@ import { computed, inject, ref } from 'vue';
|
|
|
37
37
|
import { TMagicButton, tMagicMessage, tMagicMessageBox } from '@tmagic/design';
|
|
38
38
|
import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
|
|
39
39
|
import type { DataSchema } from '@tmagic/schema';
|
|
40
|
-
import { MagicTable } from '@tmagic/table';
|
|
40
|
+
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
41
41
|
import { getDefaultValueFromFields } from '@tmagic/utils';
|
|
42
42
|
|
|
43
43
|
import type { Services } from '@editor/type';
|
|
44
44
|
|
|
45
45
|
defineOptions({
|
|
46
|
-
name: '
|
|
46
|
+
name: 'MFieldsDataSourceFields',
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
const props = withDefaults(
|
|
@@ -86,7 +86,7 @@ const fieldChange = ({ index, ...value }: Record<string, any>) => {
|
|
|
86
86
|
emit('change', props.model[props.name]);
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
const fieldColumns = [
|
|
89
|
+
const fieldColumns: ColumnConfig[] = [
|
|
90
90
|
{
|
|
91
91
|
label: '属性名称',
|
|
92
92
|
prop: 'title',
|
|
@@ -102,6 +102,13 @@ const fieldColumns = [
|
|
|
102
102
|
{
|
|
103
103
|
label: '默认值',
|
|
104
104
|
prop: 'defaultValue',
|
|
105
|
+
formatter(item, row) {
|
|
106
|
+
try {
|
|
107
|
+
return JSON.stringify(row.defaultValue);
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return row.defaultValue;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
105
112
|
},
|
|
106
113
|
{
|
|
107
114
|
label: '操作',
|
|
@@ -48,7 +48,7 @@ import { computed, inject, nextTick, ref, watch } from 'vue';
|
|
|
48
48
|
import { Coin } from '@element-plus/icons-vue';
|
|
49
49
|
|
|
50
50
|
import { getConfig, TMagicAutocomplete, TMagicTag } from '@tmagic/design';
|
|
51
|
-
import type { FieldProps } from '@tmagic/form';
|
|
51
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
52
52
|
import type { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
|
53
53
|
|
|
54
54
|
import Icon from '@editor/components/Icon.vue';
|
|
@@ -56,16 +56,16 @@ import type { Services } from '@editor/type';
|
|
|
56
56
|
import { getDisplayField } from '@editor/utils/data-source';
|
|
57
57
|
|
|
58
58
|
defineOptions({
|
|
59
|
-
name: '
|
|
59
|
+
name: 'MFieldsDataSourceInput',
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
const props = withDefaults(
|
|
63
63
|
defineProps<
|
|
64
|
-
FieldProps<
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
FieldProps<
|
|
65
|
+
{
|
|
66
|
+
type: 'data-source-input';
|
|
67
|
+
} & FormItem
|
|
68
|
+
>
|
|
69
69
|
>(),
|
|
70
70
|
{
|
|
71
71
|
disabled: false,
|
|
@@ -49,7 +49,7 @@ import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
|
49
49
|
import type { CodeParamStatement, DataSourceMethodSelectConfig, Services } from '@editor/type';
|
|
50
50
|
|
|
51
51
|
defineOptions({
|
|
52
|
-
name: '
|
|
52
|
+
name: 'MFieldsDataSourceMethodSelect',
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
const mForm = inject<FormState | undefined>('mForm');
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
import { TMagicButton } from '@tmagic/design';
|
|
25
25
|
import type { FieldProps } from '@tmagic/form';
|
|
26
26
|
import type { CodeBlockContent } from '@tmagic/schema';
|
|
27
|
-
import { MagicTable } from '@tmagic/table';
|
|
27
|
+
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
28
28
|
|
|
29
29
|
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
30
30
|
import { useDataSourceMethod } from '@editor/hooks/use-data-source-method';
|
|
31
31
|
import type { CodeParamStatement } from '@editor/type';
|
|
32
32
|
|
|
33
33
|
defineOptions({
|
|
34
|
-
name: '
|
|
34
|
+
name: 'MFieldsDataSourceMethods',
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
const props = withDefaults(
|
|
@@ -49,7 +49,7 @@ const emit = defineEmits(['change']);
|
|
|
49
49
|
|
|
50
50
|
const { codeConfig, codeBlockEditor, createCode, editCode, deleteCode, submitCode } = useDataSourceMethod();
|
|
51
51
|
|
|
52
|
-
const methodColumns = [
|
|
52
|
+
const methodColumns: ColumnConfig[] = [
|
|
53
53
|
{
|
|
54
54
|
label: '名称',
|
|
55
55
|
prop: 'name',
|
|
@@ -26,14 +26,14 @@ import { computed, inject, ref } from 'vue';
|
|
|
26
26
|
import { TMagicButton, tMagicMessageBox, TMagicSwitch } from '@tmagic/design';
|
|
27
27
|
import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
|
|
28
28
|
import type { MockSchema } from '@tmagic/schema';
|
|
29
|
-
import { MagicTable } from '@tmagic/table';
|
|
29
|
+
import { type ColumnConfig, MagicTable } from '@tmagic/table';
|
|
30
30
|
import { getDefaultValueFromFields } from '@tmagic/utils';
|
|
31
31
|
|
|
32
32
|
import CodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
33
33
|
import { Services } from '@editor/type';
|
|
34
34
|
|
|
35
35
|
defineOptions({
|
|
36
|
-
name: '
|
|
36
|
+
name: 'MFieldsDataSourceMocks',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
const props = withDefaults(
|
|
@@ -117,7 +117,7 @@ const formConfig: FormConfig = [
|
|
|
117
117
|
},
|
|
118
118
|
];
|
|
119
119
|
|
|
120
|
-
const columns = [
|
|
120
|
+
const columns: ColumnConfig[] = [
|
|
121
121
|
{
|
|
122
122
|
type: 'expand',
|
|
123
123
|
component: CodeEditor,
|
|
@@ -14,31 +14,19 @@
|
|
|
14
14
|
<script setup lang="ts">
|
|
15
15
|
import { computed, inject } from 'vue';
|
|
16
16
|
|
|
17
|
-
import { FieldProps, MSelect, SelectConfig } from '@tmagic/form';
|
|
17
|
+
import { type FieldProps, MSelect, type SelectConfig } from '@tmagic/form';
|
|
18
18
|
|
|
19
|
-
import { Services } from '../type';
|
|
19
|
+
import type { DataSourceSelect, Services } from '../type';
|
|
20
20
|
|
|
21
21
|
defineOptions({
|
|
22
|
-
name: '
|
|
22
|
+
name: 'MFieldsDataSourceSelect',
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
const emit = defineEmits(['change']);
|
|
26
26
|
|
|
27
|
-
const props = withDefaults(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: 'data-source-select';
|
|
31
|
-
name: string;
|
|
32
|
-
text?: string;
|
|
33
|
-
placeholder?: string;
|
|
34
|
-
dataSourceType?: string;
|
|
35
|
-
value?: 'id' | 'value';
|
|
36
|
-
}>
|
|
37
|
-
>(),
|
|
38
|
-
{
|
|
39
|
-
disabled: false,
|
|
40
|
-
},
|
|
41
|
-
);
|
|
27
|
+
const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
|
|
28
|
+
disabled: false,
|
|
29
|
+
});
|
|
42
30
|
|
|
43
31
|
const { dataSourceService } = inject<Services>('services') || {};
|
|
44
32
|
|
|
@@ -61,7 +61,7 @@ import { ActionType } from '@tmagic/schema';
|
|
|
61
61
|
import type { CodeSelectColConfig, DataSourceMethodSelectConfig, EventSelectConfig, Services } from '@editor/type';
|
|
62
62
|
|
|
63
63
|
defineOptions({
|
|
64
|
-
name: '
|
|
64
|
+
name: 'MFieldsEventSelect',
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
const props = defineProps<FieldProps<EventSelectConfig>>();
|
package/src/fields/KeyValue.vue
CHANGED
|
@@ -63,23 +63,23 @@ import { ref, watchEffect } from 'vue';
|
|
|
63
63
|
import { Delete, Plus } from '@element-plus/icons-vue';
|
|
64
64
|
|
|
65
65
|
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
|
66
|
-
import type { FieldProps } from '@tmagic/form';
|
|
66
|
+
import type { FieldProps, FormItem } from '@tmagic/form';
|
|
67
67
|
|
|
68
68
|
import CodeIcon from '@editor/icons/CodeIcon.vue';
|
|
69
69
|
import MagicCodeEditor from '@editor/layouts/CodeEditor.vue';
|
|
70
70
|
|
|
71
71
|
defineOptions({
|
|
72
|
-
name: '
|
|
72
|
+
name: 'MFieldsKeyValue',
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
const props = withDefaults(
|
|
76
76
|
defineProps<
|
|
77
|
-
FieldProps<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
FieldProps<
|
|
78
|
+
{
|
|
79
|
+
type: 'key-value';
|
|
80
|
+
advanced?: boolean;
|
|
81
|
+
} & FormItem
|
|
82
|
+
>
|
|
83
83
|
>(),
|
|
84
84
|
{
|
|
85
85
|
disabled: false,
|
|
@@ -26,7 +26,7 @@ import Icon from '@editor/components/Icon.vue';
|
|
|
26
26
|
import type { PageFragmentSelectConfig, Services } from '@editor/type';
|
|
27
27
|
|
|
28
28
|
defineOptions({
|
|
29
|
-
name: '
|
|
29
|
+
name: 'MFieldsPageFragmentSelect',
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
const services = inject<Services>('services');
|
package/src/fields/UISelect.vue
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
:size="size"
|
|
27
27
|
@click="selectNode(val)"
|
|
28
28
|
@mouseenter="highlight(val)"
|
|
29
|
-
@mouseleave="
|
|
29
|
+
@mouseleave="unhighlight"
|
|
30
30
|
>{{ `${toName}_${val}` }}</TMagicButton
|
|
31
31
|
>
|
|
32
32
|
</TMagicTooltip>
|
|
@@ -46,16 +46,16 @@ import { Close, Delete } from '@element-plus/icons-vue';
|
|
|
46
46
|
import { throttle } from 'lodash-es';
|
|
47
47
|
|
|
48
48
|
import { TMagicButton, TMagicTooltip } from '@tmagic/design';
|
|
49
|
-
import type { FieldProps, FormState } from '@tmagic/form';
|
|
49
|
+
import type { FieldProps, FormItem, FormState } from '@tmagic/form';
|
|
50
50
|
import type { Id } from '@tmagic/schema';
|
|
51
51
|
|
|
52
52
|
import { Services, UI_SELECT_MODE_EVENT_NAME } from '@editor/type';
|
|
53
53
|
|
|
54
54
|
defineOptions({
|
|
55
|
-
name: '
|
|
55
|
+
name: 'MFieldsUISelect',
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
const props = defineProps<FieldProps<
|
|
58
|
+
const props = defineProps<FieldProps<{ type: 'ui-select' } & FormItem>>();
|
|
59
59
|
|
|
60
60
|
const emit = defineEmits(['change']);
|
|
61
61
|
|
|
@@ -115,7 +115,7 @@ const highlight = throttle((id: Id) => {
|
|
|
115
115
|
services?.stageOverlayService.get('stage')?.highlight(id);
|
|
116
116
|
}, 150);
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const unhighlight = () => {
|
|
119
119
|
services?.editorService.set('highlightNode', null);
|
|
120
120
|
services?.editorService.get('stage')?.clearHighlight();
|
|
121
121
|
services?.stageOverlayService.get('stage')?.clearHighlight();
|
package/src/hooks/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
codeConfig.value = {
|
|
23
|
-
name: '
|
|
23
|
+
name: '',
|
|
24
24
|
content: `({app, params}) => {\n // place your code here\n}`,
|
|
25
25
|
params: [],
|
|
26
26
|
};
|
|
@@ -54,7 +54,6 @@ export const useCodeBlockEdit = (codeBlockService?: CodeBlockService) => {
|
|
|
54
54
|
codeId.value = id;
|
|
55
55
|
|
|
56
56
|
await nextTick();
|
|
57
|
-
|
|
58
57
|
codeBlockEditor.value?.show();
|
|
59
58
|
};
|
|
60
59
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { computed, inject, ref, watchEffect } from 'vue';
|
|
2
|
+
|
|
3
|
+
import type { Services } from '@editor/type';
|
|
4
|
+
|
|
5
|
+
export const useEditorContentHeight = () => {
|
|
6
|
+
const services = inject<Services>('services');
|
|
7
|
+
const frameworkHeight = computed(() => services?.uiService.get('frameworkRect').height || 0);
|
|
8
|
+
const navMenuHeight = computed(() => services?.uiService.get('navMenuRect').height || 0);
|
|
9
|
+
const editorContentHeight = computed(() => frameworkHeight.value - navMenuHeight.value);
|
|
10
|
+
|
|
11
|
+
const height = ref(0);
|
|
12
|
+
watchEffect(() => {
|
|
13
|
+
if (height.value > 0) return;
|
|
14
|
+
height.value = editorContentHeight.value;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
height,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -26,34 +26,34 @@ export const useFloatBox = (slideKeys: ComputedRef<string[]>) => {
|
|
|
26
26
|
const showingBoxKeys = computed(() =>
|
|
27
27
|
Object.keys(floatBoxStates.value).filter((key) => floatBoxStates.value[key].status),
|
|
28
28
|
);
|
|
29
|
-
const
|
|
29
|
+
const isDragging = ref(false);
|
|
30
30
|
|
|
31
|
-
const dragstartHandler = () => (
|
|
31
|
+
const dragstartHandler = () => (isDragging.value = true);
|
|
32
32
|
const dragendHandler = (key: string, e: DragEvent) => {
|
|
33
33
|
floatBoxStates.value[key] = {
|
|
34
34
|
left: e.clientX,
|
|
35
35
|
top: e.clientY,
|
|
36
36
|
status: true,
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
isDragging.value = false;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
document.body.addEventListener('dragover', (e: DragEvent) => {
|
|
42
|
-
if (!
|
|
42
|
+
if (!isDragging.value) return;
|
|
43
43
|
e.preventDefault();
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
watch(
|
|
47
47
|
() => slideKeys.value,
|
|
48
|
-
() => {
|
|
49
|
-
|
|
50
|
-
if (floatBoxStates.value[key])
|
|
48
|
+
(slideKeys) => {
|
|
49
|
+
slideKeys.forEach((key) => {
|
|
50
|
+
if (floatBoxStates.value[key]) return;
|
|
51
51
|
floatBoxStates.value[key] = {
|
|
52
52
|
status: false,
|
|
53
53
|
top: 0,
|
|
54
54
|
left: 0,
|
|
55
55
|
};
|
|
56
|
-
}
|
|
56
|
+
});
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
deep: true,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { onBeforeUnmount, reactive } from 'vue';
|
|
2
|
+
|
|
3
|
+
export const useWindowRect = () => {
|
|
4
|
+
const rect = reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
|
|
5
|
+
|
|
6
|
+
const windowResizeHandler = () => {
|
|
7
|
+
rect.width = globalThis.innerWidth;
|
|
8
|
+
rect.height = globalThis.innerHeight;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
globalThis.addEventListener('resize', windowResizeHandler);
|
|
12
|
+
|
|
13
|
+
onBeforeUnmount(() => {
|
|
14
|
+
globalThis.removeEventListener('resize', windowResizeHandler);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
rect,
|
|
19
|
+
};
|
|
20
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -96,11 +96,11 @@ export default {
|
|
|
96
96
|
// eslint-disable-next-line no-param-reassign
|
|
97
97
|
app.config.globalProperties.$TMAGIC_EDITOR = option;
|
|
98
98
|
setConfig(option);
|
|
99
|
-
app.component(Editor.name
|
|
99
|
+
app.component(`${Editor.name || 'MEditor'}`, Editor);
|
|
100
|
+
app.component('magic-code-editor', CodeEditor);
|
|
100
101
|
app.component('m-fields-ui-select', uiSelect);
|
|
101
102
|
app.component('m-fields-code-link', CodeLink);
|
|
102
103
|
app.component('m-fields-vs-code', Code);
|
|
103
|
-
app.component('magic-code-editor', CodeEditor);
|
|
104
104
|
app.component('m-fields-code-select', CodeSelect);
|
|
105
105
|
app.component('m-fields-code-select-col', CodeSelectCol);
|
|
106
106
|
app.component('m-fields-event-select', EventSelect);
|