mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-09-12 15:09:43 +00:00
fix(editor): inject eventBus 时提供 null 默认值
避免未处于 Editor 子树时 Vue 报 injection "eventBus" not found。
This commit is contained in:
parent
90e4bec70b
commit
58f2a943b8
@ -84,7 +84,7 @@ defineOptions({
|
||||
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
const { codeBlockService, uiService } = useServices();
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
const emit = defineEmits<{
|
||||
change: [v: any, eventData: ContainerChangeEventData];
|
||||
}>();
|
||||
|
||||
@ -124,7 +124,7 @@ const optionComponent = getDesignConfig('components')?.option;
|
||||
|
||||
const { dataSourceService, uiService } = useServices();
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
|
||||
const allDataSources = computed(() => dataSourceService.get('dataSources') || []);
|
||||
|
||||
|
||||
@ -67,7 +67,7 @@ defineOptions({
|
||||
|
||||
const { dataSourceService, uiService } = useServices();
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
|
||||
@ -50,7 +50,7 @@ const props = withDefaults(defineProps<FieldProps<DataSourceSelect>>(), {
|
||||
|
||||
const mForm = inject<FormState | undefined>('mForm');
|
||||
const { dataSourceService, uiService } = useServices();
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
|
||||
const dataSources = computed(() => dataSourceService.get('dataSources'));
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ const props = defineProps<{
|
||||
customContentMenu: CustomContentMenuFunction;
|
||||
}>();
|
||||
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
|
||||
const { codeBlockService } = useServices();
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import ContentMenu from '@editor/components/ContentMenu.vue';
|
||||
import type { ContentMenuTarget, EventBus, MenuButton, MenuComponent, TreeNodeData } from '@editor/type';
|
||||
|
||||
export const useContentMenu = (deleteCode: (id: string) => void) => {
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
const menuRef = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
||||
|
||||
let selectId = '';
|
||||
|
||||
@ -75,7 +75,7 @@ const props = defineProps<{
|
||||
customContentMenu: CustomContentMenuFunction;
|
||||
}>();
|
||||
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
const { dataSourceService } = useServices();
|
||||
|
||||
const { editDialog, dataSourceValues, dialogTitle, editable, editHandler, submitDataSourceHandler } =
|
||||
|
||||
@ -6,7 +6,7 @@ import ContentMenu from '@editor/components/ContentMenu.vue';
|
||||
import type { ContentMenuTarget, EventBus, MenuButton, MenuComponent, TreeNodeData } from '@editor/type';
|
||||
|
||||
export const useContentMenu = () => {
|
||||
const eventBus = inject<EventBus>('eventBus');
|
||||
const eventBus = inject<EventBus | null>('eventBus', null);
|
||||
const menuRef = useTemplateRef<InstanceType<typeof ContentMenu>>('menu');
|
||||
|
||||
let selectId = '';
|
||||
|
||||
@ -119,6 +119,15 @@ describe('DataSourceSelect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('未 provide eventBus 时不告警,点击编辑也不抛错', async () => {
|
||||
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
dataSourceService.getDataSourceById.mockReturnValue({ id: '1' });
|
||||
const wrapper = mount(DataSourceSelect, { props: baseProps({ model: { ds: '1' } }) as any });
|
||||
expect(warn.mock.calls.some((c) => String(c[0]).includes('eventBus'))).toBe(false);
|
||||
await expect(wrapper.find('button').trigger('click')).resolves.toBeUndefined();
|
||||
warn.mockRestore();
|
||||
});
|
||||
|
||||
test('editHandler emit edit-data-source', async () => {
|
||||
const eventBus = { emit: vi.fn() };
|
||||
dataSourceService.getDataSourceById.mockReturnValue({ id: '1' });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user