mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 12:14:27 +08:00
feat(editor): 编辑代码块/数据源时高亮列表中对应的项
This commit is contained in:
parent
f91eb415db
commit
54e00f2852
@ -59,7 +59,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, Ref, ref, useTemplateRef } from 'vue';
|
import { computed, inject, nextTick, Ref, ref, useTemplateRef, watch } from 'vue';
|
||||||
|
|
||||||
import type { CodeBlockContent } from '@tmagic/core';
|
import type { CodeBlockContent } from '@tmagic/core';
|
||||||
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
import { TMagicButton, TMagicDialog, tMagicMessage, tMagicMessageBox, TMagicTag } from '@tmagic/design';
|
||||||
@ -95,6 +95,8 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
submit: [values: CodeBlockContent, eventData: ContainerChangeEventData];
|
submit: [values: CodeBlockContent, eventData: ContainerChangeEventData];
|
||||||
|
close: [];
|
||||||
|
open: [];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { codeBlockService, uiService } = useServices();
|
const { codeBlockService, uiService } = useServices();
|
||||||
@ -261,6 +263,16 @@ const closedHandler = () => {
|
|||||||
const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
|
const parentFloating = inject<Ref<HTMLDivElement | null>>('parentFloating', ref(null));
|
||||||
const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(uiService, parentFloating);
|
const { boxPosition, calcBoxPosition } = useNextFloatBoxPosition(uiService, parentFloating);
|
||||||
|
|
||||||
|
watch(boxVisible, (visible) => {
|
||||||
|
nextTick(() => {
|
||||||
|
if (!visible) {
|
||||||
|
emit('close');
|
||||||
|
} else {
|
||||||
|
emit('open');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
async show() {
|
async show() {
|
||||||
calcBoxPosition();
|
calcBoxPosition();
|
||||||
|
@ -173,6 +173,7 @@ const nodeContentMenuHandler = (event: MouseEvent, data: TreeNodeData) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
nodeStatusMap,
|
||||||
filter: filterTextChangeHandler,
|
filter: filterTextChangeHandler,
|
||||||
deleteCode,
|
deleteCode,
|
||||||
});
|
});
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
:disabled="!editable"
|
:disabled="!editable"
|
||||||
:content="codeConfig"
|
:content="codeConfig"
|
||||||
@submit="submitCodeBlockHandler"
|
@submit="submitCodeBlockHandler"
|
||||||
|
@close="editDialogCloseHandler"
|
||||||
|
@open="editDialogOpenHandler"
|
||||||
></CodeBlockEditor>
|
></CodeBlockEditor>
|
||||||
|
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
@ -87,7 +89,7 @@ const { codeBlockService } = useServices();
|
|||||||
|
|
||||||
const editable = computed(() => codeBlockService.getEditStatus());
|
const editable = computed(() => codeBlockService.getEditStatus());
|
||||||
|
|
||||||
const { codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
|
const { codeId, codeBlockEditor, codeConfig, editCode, deleteCode, createCodeBlock, submitCodeBlockHandler } =
|
||||||
useCodeBlockEdit(codeBlockService);
|
useCodeBlockEdit(codeBlockService);
|
||||||
|
|
||||||
const codeBlockListRef = useTemplateRef<InstanceType<typeof CodeBlockList>>('codeBlockList');
|
const codeBlockListRef = useTemplateRef<InstanceType<typeof CodeBlockList>>('codeBlockList');
|
||||||
@ -100,6 +102,22 @@ eventBus?.on('edit-code', (id: string) => {
|
|||||||
editCode(id);
|
editCode(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const editDialogOpenHandler = () => {
|
||||||
|
if (codeBlockListRef.value) {
|
||||||
|
for (const [statusId, status] of codeBlockListRef.value.nodeStatusMap.entries()) {
|
||||||
|
status.selected = statusId === codeId.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const editDialogCloseHandler = () => {
|
||||||
|
if (codeBlockListRef.value) {
|
||||||
|
for (const [, status] of codeBlockListRef.value.nodeStatusMap.entries()) {
|
||||||
|
status.selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
nodeContentMenuHandler,
|
nodeContentMenuHandler,
|
||||||
menuData: contentMenuData,
|
menuData: contentMenuData,
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { inject, Ref, ref, watchEffect } from 'vue';
|
import { inject, nextTick, Ref, ref, watch, watchEffect } from 'vue';
|
||||||
|
|
||||||
import type { DataSourceSchema } from '@tmagic/core';
|
import type { DataSourceSchema } from '@tmagic/core';
|
||||||
import { tMagicMessage } from '@tmagic/design';
|
import { tMagicMessage } from '@tmagic/design';
|
||||||
@ -48,6 +48,8 @@ const width = defineModel<number>('width', { default: 670 });
|
|||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
submit: [v: any, eventData: ContainerChangeEventData];
|
submit: [v: any, eventData: ContainerChangeEventData];
|
||||||
|
close: [];
|
||||||
|
open: [id: string];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { uiService, dataSourceService } = useServices();
|
const { uiService, dataSourceService } = useServices();
|
||||||
@ -73,6 +75,16 @@ const errorHandler = (error: any) => {
|
|||||||
tMagicMessage.error(error.message);
|
tMagicMessage.error(error.message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
watch(boxVisible, (visible) => {
|
||||||
|
nextTick(() => {
|
||||||
|
if (!visible) {
|
||||||
|
emit('close');
|
||||||
|
} else if (initValues.value?.id) {
|
||||||
|
emit('open', initValues.value.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
show() {
|
show() {
|
||||||
calcBoxPosition();
|
calcBoxPosition();
|
||||||
|
@ -178,6 +178,7 @@ const nodeContentMenuHandler = (event: MouseEvent, data: TreeNodeData) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
|
nodeStatusMap,
|
||||||
filter: filterTextChangeHandler,
|
filter: filterTextChangeHandler,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
:values="dataSourceValues"
|
:values="dataSourceValues"
|
||||||
:title="dialogTitle"
|
:title="dialogTitle"
|
||||||
@submit="submitDataSourceHandler"
|
@submit="submitDataSourceHandler"
|
||||||
|
@close="editDialogCloseHandler"
|
||||||
|
@open="editDialogOpenHandler"
|
||||||
></DataSourceConfigPanel>
|
></DataSourceConfigPanel>
|
||||||
|
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
@ -93,6 +95,22 @@ const { dataSourceService } = useServices();
|
|||||||
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
||||||
useDataSourceEdit(dataSourceService);
|
useDataSourceEdit(dataSourceService);
|
||||||
|
|
||||||
|
const editDialogOpenHandler = (id: string) => {
|
||||||
|
if (dataSourceList.value) {
|
||||||
|
for (const [statusId, status] of dataSourceList.value.nodeStatusMap.entries()) {
|
||||||
|
status.selected = statusId === id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const editDialogCloseHandler = () => {
|
||||||
|
if (dataSourceList.value) {
|
||||||
|
for (const [, status] of dataSourceList.value.nodeStatusMap.entries()) {
|
||||||
|
status.selected = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const datasourceTypeList = computed(() =>
|
const datasourceTypeList = computed(() =>
|
||||||
[
|
[
|
||||||
{ text: '基础', type: 'base' },
|
{ text: '基础', type: 'base' },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user