@tmagic/editor 1.5.0-beta.9 → 1.5.1
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 → tmagic-editor.css} +228 -22
- package/dist/tmagic-editor.js +1670 -1012
- package/dist/tmagic-editor.umd.cjs +1705 -1048
- package/package.json +14 -12
- package/src/Editor.vue +24 -6
- package/src/components/CodeBlockEditor.vue +14 -8
- package/src/components/CodeParams.vue +5 -5
- package/src/components/ContentMenu.vue +18 -18
- package/src/components/FloatingBox.vue +3 -3
- package/src/components/Resizer.vue +4 -4
- package/src/components/ScrollBar.vue +3 -3
- package/src/components/ScrollViewer.vue +3 -3
- package/src/components/SplitView.vue +2 -2
- package/src/components/ToolButton.vue +2 -1
- package/src/editorProps.ts +6 -2
- package/src/fields/Code.vue +1 -2
- package/src/fields/CodeSelect.vue +13 -11
- package/src/fields/CodeSelectCol.vue +32 -5
- package/src/fields/CondOpSelect.vue +5 -2
- package/src/fields/DataSourceFields.vue +31 -12
- package/src/fields/DataSourceInput.vue +2 -2
- package/src/fields/DataSourceMethods.vue +72 -14
- package/src/fields/DataSourceMocks.vue +0 -1
- package/src/fields/DisplayConds.vue +8 -3
- package/src/fields/EventSelect.vue +28 -12
- package/src/fields/KeyValue.vue +17 -12
- package/src/fields/UISelect.vue +6 -3
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-code-block-edit.ts +3 -3
- package/src/hooks/use-data-source-edit.ts +3 -2
- package/src/hooks/use-filter.ts +1 -1
- package/src/hooks/use-getso.ts +7 -7
- package/src/hooks/use-node-status.ts +2 -2
- package/src/index.ts +2 -1
- package/src/initService.ts +177 -74
- package/src/layouts/CodeEditor.vue +2 -2
- package/src/layouts/Framework.vue +13 -12
- package/src/layouts/NavMenu.vue +2 -2
- package/src/layouts/page-bar/AddButton.vue +29 -9
- package/src/layouts/page-bar/PageBar.vue +79 -66
- package/src/layouts/page-bar/PageBarScrollContainer.vue +84 -98
- package/src/layouts/page-bar/PageList.vue +5 -3
- package/src/layouts/page-bar/Search.vue +67 -0
- package/src/layouts/props-panel/FormPanel.vue +123 -0
- package/src/layouts/props-panel/PropsPanel.vue +146 -0
- package/src/layouts/props-panel/use-style-panel.ts +29 -0
- package/src/layouts/sidebar/Sidebar.vue +7 -1
- package/src/layouts/sidebar/code-block/CodeBlockList.vue +18 -2
- package/src/layouts/sidebar/code-block/CodeBlockListPanel.vue +35 -4
- package/src/layouts/sidebar/code-block/useContentMenu.ts +83 -0
- package/src/layouts/sidebar/data-source/DataSourceConfigPanel.vue +7 -5
- package/src/layouts/sidebar/data-source/DataSourceList.vue +13 -8
- package/src/layouts/sidebar/data-source/DataSourceListPanel.vue +40 -4
- package/src/layouts/sidebar/data-source/useContentMenu.ts +81 -0
- package/src/layouts/sidebar/layer/LayerMenu.vue +7 -13
- package/src/layouts/sidebar/layer/LayerPanel.vue +11 -4
- package/src/layouts/sidebar/layer/use-click.ts +2 -2
- package/src/layouts/sidebar/layer/use-keybinding.ts +2 -2
- package/src/layouts/sidebar/layer/use-node-status.ts +2 -3
- package/src/layouts/workspace/Workspace.vue +13 -3
- package/src/layouts/workspace/viewer/NodeListMenu.vue +3 -3
- package/src/layouts/workspace/viewer/Stage.vue +41 -11
- package/src/layouts/workspace/viewer/StageOverlay.vue +2 -2
- package/src/layouts/workspace/viewer/ViewerMenu.vue +4 -6
- package/src/services/dataSource.ts +12 -5
- package/src/services/dep.ts +61 -13
- package/src/services/editor.ts +46 -51
- package/src/services/storage.ts +2 -1
- package/src/services/ui.ts +1 -0
- package/src/theme/common/var.scss +12 -10
- package/src/theme/component-list-panel.scss +9 -7
- package/src/theme/content-menu.scss +7 -5
- package/src/theme/data-source.scss +3 -1
- package/src/theme/floating-box.scss +4 -2
- package/src/theme/framework.scss +7 -5
- package/src/theme/index.scss +4 -5
- package/src/theme/key-value.scss +2 -2
- package/src/theme/layer-panel.scss +3 -1
- package/src/theme/layout.scss +1 -1
- package/src/theme/nav-menu.scss +7 -5
- package/src/theme/page-bar.scss +51 -27
- package/src/theme/props-panel.scss +81 -1
- package/src/theme/resizer.scss +1 -1
- package/src/theme/search-input.scss +1 -0
- package/src/theme/sidebar.scss +4 -2
- package/src/theme/stage.scss +3 -1
- package/src/theme/theme.scss +28 -28
- package/src/theme/tree.scss +14 -12
- package/src/type.ts +10 -1
- package/src/utils/content-menu.ts +2 -2
- package/src/utils/data-source/formConfigs/http.ts +2 -0
- package/src/utils/data-source/index.ts +2 -2
- package/src/utils/editor.ts +78 -22
- package/src/utils/idle-task.ts +36 -4
- package/src/utils/props.ts +48 -6
- package/types/index.d.ts +2312 -2080
- package/src/hooks/use-data-source-method.ts +0 -100
- package/src/layouts/PropsPanel.vue +0 -131
- package/src/layouts/page-bar/SwitchTypeButton.vue +0 -45
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { nextTick, ref } from 'vue';
|
|
2
|
-
import { cloneDeep } from 'lodash-es';
|
|
3
|
-
|
|
4
|
-
import type { CodeBlockContent, DataSourceSchema } from '@tmagic/core';
|
|
5
|
-
import { tMagicMessage } from '@tmagic/design';
|
|
6
|
-
|
|
7
|
-
import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
|
|
8
|
-
import { getEditorConfig } from '@editor/utils/config';
|
|
9
|
-
|
|
10
|
-
export const useDataSourceMethod = () => {
|
|
11
|
-
const codeConfig = ref<CodeBlockContent>();
|
|
12
|
-
const codeBlockEditor = ref<InstanceType<typeof CodeBlockEditor>>();
|
|
13
|
-
|
|
14
|
-
const dataSource = ref<DataSourceSchema>();
|
|
15
|
-
const dataSourceMethod = ref('');
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
codeConfig,
|
|
19
|
-
codeBlockEditor,
|
|
20
|
-
|
|
21
|
-
createCode: async (model: DataSourceSchema) => {
|
|
22
|
-
codeConfig.value = {
|
|
23
|
-
name: '',
|
|
24
|
-
content: `({ params, dataSource, app }) => {\n // place your code here\n}`,
|
|
25
|
-
params: [],
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
await nextTick();
|
|
29
|
-
|
|
30
|
-
dataSource.value = model;
|
|
31
|
-
dataSourceMethod.value = '';
|
|
32
|
-
|
|
33
|
-
codeBlockEditor.value?.show();
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
editCode: async (model: DataSourceSchema, methodName: string) => {
|
|
37
|
-
const method = model.methods?.find((method) => method.name === methodName);
|
|
38
|
-
|
|
39
|
-
if (!method) {
|
|
40
|
-
tMagicMessage.error('获取数据源方法失败');
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let codeContent = method.content || `({ params, dataSource, app }) => {\n // place your code here\n}`;
|
|
45
|
-
|
|
46
|
-
if (typeof codeContent !== 'string') {
|
|
47
|
-
codeContent = codeContent.toString();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
codeConfig.value = {
|
|
51
|
-
...cloneDeep(method),
|
|
52
|
-
content: codeContent,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
await nextTick();
|
|
56
|
-
|
|
57
|
-
dataSource.value = model;
|
|
58
|
-
dataSourceMethod.value = methodName;
|
|
59
|
-
|
|
60
|
-
codeBlockEditor.value?.show();
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
deleteCode: async (model: DataSourceSchema, methodName: string) => {
|
|
64
|
-
if (!model.methods) return;
|
|
65
|
-
|
|
66
|
-
const index = model.methods.findIndex((method) => method.name === methodName);
|
|
67
|
-
|
|
68
|
-
if (index === -1) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
model.methods.splice(index, 1);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
submitCode: (values: CodeBlockContent) => {
|
|
76
|
-
if (!dataSource.value) return;
|
|
77
|
-
|
|
78
|
-
if (!dataSource.value.methods) {
|
|
79
|
-
dataSource.value.methods = [];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (values.content) {
|
|
83
|
-
// 在保存的时候转换代码内容
|
|
84
|
-
const parseDSL = getEditorConfig('parseDSL');
|
|
85
|
-
if (typeof values.content === 'string') {
|
|
86
|
-
values.content = parseDSL<(...args: any[]) => any>(values.content);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (dataSourceMethod.value) {
|
|
91
|
-
const index = dataSource.value.methods.findIndex((method) => method.name === dataSourceMethod.value);
|
|
92
|
-
dataSource.value.methods.splice(index, 1, values);
|
|
93
|
-
} else {
|
|
94
|
-
dataSource.value.methods.push(values);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
codeBlockEditor.value?.hide();
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="m-editor-props-panel" v-show="nodes.length === 1">
|
|
3
|
-
<slot name="props-panel-header"></slot>
|
|
4
|
-
<MForm
|
|
5
|
-
ref="configForm"
|
|
6
|
-
:class="propsPanelSize"
|
|
7
|
-
:popper-class="`m-editor-props-panel-popper ${propsPanelSize}`"
|
|
8
|
-
:size="propsPanelSize"
|
|
9
|
-
:init-values="values"
|
|
10
|
-
:config="curFormConfig"
|
|
11
|
-
:extend-state="extendState"
|
|
12
|
-
@change="submit"
|
|
13
|
-
@error="errorHandler"
|
|
14
|
-
></MForm>
|
|
15
|
-
|
|
16
|
-
<TMagicButton
|
|
17
|
-
v-if="!disabledShowSrc"
|
|
18
|
-
class="m-editor-props-panel-src-icon"
|
|
19
|
-
circle
|
|
20
|
-
size="large"
|
|
21
|
-
title="源码"
|
|
22
|
-
:type="showSrc ? 'primary' : ''"
|
|
23
|
-
@click="showSrc = !showSrc"
|
|
24
|
-
>
|
|
25
|
-
<MIcon :icon="DocumentIcon"></MIcon>
|
|
26
|
-
</TMagicButton>
|
|
27
|
-
|
|
28
|
-
<CodeEditor
|
|
29
|
-
v-if="showSrc"
|
|
30
|
-
class="m-editor-props-panel-src-code"
|
|
31
|
-
:height="`${editorContentHeight}px`"
|
|
32
|
-
:init-values="values"
|
|
33
|
-
:options="codeOptions"
|
|
34
|
-
:parse="true"
|
|
35
|
-
@save="saveCode"
|
|
36
|
-
></CodeEditor>
|
|
37
|
-
</div>
|
|
38
|
-
</template>
|
|
39
|
-
|
|
40
|
-
<script lang="ts" setup>
|
|
41
|
-
import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted, ref, watchEffect } from 'vue';
|
|
42
|
-
import { Document as DocumentIcon } from '@element-plus/icons-vue';
|
|
43
|
-
|
|
44
|
-
import type { MNode } from '@tmagic/core';
|
|
45
|
-
import { TMagicButton } from '@tmagic/design';
|
|
46
|
-
import type { FormState, FormValue } from '@tmagic/form';
|
|
47
|
-
import { MForm } from '@tmagic/form';
|
|
48
|
-
|
|
49
|
-
import MIcon from '@editor/components/Icon.vue';
|
|
50
|
-
import { useEditorContentHeight } from '@editor/hooks/use-editor-content-height';
|
|
51
|
-
import type { PropsPanelSlots, Services } from '@editor/type';
|
|
52
|
-
|
|
53
|
-
import CodeEditor from './CodeEditor.vue';
|
|
54
|
-
|
|
55
|
-
defineSlots<PropsPanelSlots>();
|
|
56
|
-
|
|
57
|
-
defineOptions({
|
|
58
|
-
name: 'MEditorPropsPanel',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
defineProps<{
|
|
62
|
-
disabledShowSrc?: boolean;
|
|
63
|
-
extendState?: (state: FormState) => Record<string, any> | Promise<Record<string, any>>;
|
|
64
|
-
}>();
|
|
65
|
-
|
|
66
|
-
const codeOptions = inject('codeOptions', {});
|
|
67
|
-
|
|
68
|
-
const emit = defineEmits(['mounted', 'submit-error', 'form-error']);
|
|
69
|
-
|
|
70
|
-
const showSrc = ref(false);
|
|
71
|
-
|
|
72
|
-
const internalInstance = getCurrentInstance();
|
|
73
|
-
const values = ref<FormValue>({});
|
|
74
|
-
const configForm = ref<InstanceType<typeof MForm>>();
|
|
75
|
-
// ts类型应该是FormConfig, 但是打包时会出错,所以暂时用any
|
|
76
|
-
const curFormConfig = ref<any>([]);
|
|
77
|
-
const services = inject<Services>('services');
|
|
78
|
-
const node = computed(() => services?.editorService.get('node'));
|
|
79
|
-
const nodes = computed(() => services?.editorService.get('nodes') || []);
|
|
80
|
-
const propsPanelSize = computed(() => services?.uiService.get('propsPanelSize') || 'small');
|
|
81
|
-
const stage = computed(() => services?.editorService.get('stage'));
|
|
82
|
-
|
|
83
|
-
const { height: editorContentHeight } = useEditorContentHeight();
|
|
84
|
-
|
|
85
|
-
const init = async () => {
|
|
86
|
-
if (!node.value) {
|
|
87
|
-
curFormConfig.value = [];
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const type = node.value.type || (node.value.items ? 'container' : 'text');
|
|
92
|
-
curFormConfig.value = (await services?.propsService.getPropsConfig(type)) || [];
|
|
93
|
-
values.value = node.value;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
watchEffect(init);
|
|
97
|
-
services?.propsService.on('props-configs-change', init);
|
|
98
|
-
|
|
99
|
-
onMounted(() => {
|
|
100
|
-
emit('mounted', internalInstance);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
onBeforeUnmount(() => {
|
|
104
|
-
services?.propsService.off('props-configs-change', init);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
watchEffect(() => {
|
|
108
|
-
if (configForm.value && stage.value) {
|
|
109
|
-
configForm.value.formState.stage = stage.value;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const submit = async () => {
|
|
114
|
-
try {
|
|
115
|
-
const values = await configForm.value?.submitForm();
|
|
116
|
-
services?.editorService.update(values);
|
|
117
|
-
} catch (e: any) {
|
|
118
|
-
emit('submit-error', e);
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const errorHandler = (e: any) => {
|
|
123
|
-
emit('form-error', e);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const saveCode = (values: MNode) => {
|
|
127
|
-
services?.editorService.update(values);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
defineExpose({ configForm, submit });
|
|
131
|
-
</script>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<TMagicButton
|
|
3
|
-
v-for="item in data"
|
|
4
|
-
class="m-editor-page-bar-switch-type-button"
|
|
5
|
-
size="small"
|
|
6
|
-
:key="item.type"
|
|
7
|
-
link
|
|
8
|
-
:class="{ active: modelValue === item.type }"
|
|
9
|
-
:type="modelValue === item.type ? 'primary' : ''"
|
|
10
|
-
@click="clickHandler(item.type)"
|
|
11
|
-
>{{ item.text }}</TMagicButton
|
|
12
|
-
>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<script setup lang="ts">
|
|
16
|
-
import { NodeType } from '@tmagic/core';
|
|
17
|
-
import { TMagicButton } from '@tmagic/design';
|
|
18
|
-
|
|
19
|
-
defineOptions({
|
|
20
|
-
name: 'MEditorPageBarSwitchTypeButton',
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
defineProps<{
|
|
24
|
-
modelValue: NodeType.PAGE | NodeType.PAGE_FRAGMENT;
|
|
25
|
-
}>();
|
|
26
|
-
|
|
27
|
-
const data: { type: NodeType.PAGE | NodeType.PAGE_FRAGMENT; text: string }[] = [
|
|
28
|
-
{
|
|
29
|
-
type: NodeType.PAGE,
|
|
30
|
-
text: '页面',
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
type: NodeType.PAGE_FRAGMENT,
|
|
34
|
-
text: '页面片',
|
|
35
|
-
},
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
const emit = defineEmits<{
|
|
39
|
-
'update:modelValue': [value: NodeType.PAGE | NodeType.PAGE_FRAGMENT];
|
|
40
|
-
}>();
|
|
41
|
-
|
|
42
|
-
const clickHandler = (value: NodeType.PAGE | NodeType.PAGE_FRAGMENT) => {
|
|
43
|
-
emit('update:modelValue', value);
|
|
44
|
-
};
|
|
45
|
-
</script>
|