fix(editor): 编辑器初始化默认选择节点

This commit is contained in:
roymondchen 2022-12-05 20:05:23 +08:00
parent f050ec1273
commit 45eaea6f68
3 changed files with 19 additions and 8 deletions

View File

@ -224,15 +224,25 @@ export default defineComponent({
setup(props, { emit }) {
editorService.on('root-change', (value) => {
const node = editorService.get<MNode | null>('node');
const nodeId = node?.id || props.defaultSelected;
if (nodeId && node !== value) {
editorService.select(nodeId);
} else {
editorService.set('nodes', [value]);
const nodeId = editorService.get<MNode | null>('node')?.id || props.defaultSelected;
let node;
if (nodeId) {
node = editorService.getNodeById(nodeId);
}
emit('update:modelValue', toRaw(editorService.get('root')));
if (node && node !== value) {
editorService.select(node.id);
} else if (value?.items?.length) {
editorService.select(value.items[0]);
} else if (value?.id) {
editorService.set('nodes', [value]);
editorService.set('parent', null);
editorService.set('page', null);
}
if (toRaw(value) !== toRaw(editorService.get('root'))) {
emit('update:modelValue', value);
}
});
//

View File

@ -62,7 +62,7 @@ const zoom = computed(() => services?.uiService.get<number>('zoom') || 1);
const node = computed(() => services?.editorService.get<MNode>('node'));
watchEffect(() => {
if (stage) return;
if (stage || !page.value) return;
if (!stageContainer.value) return;
if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;

View File

@ -21,3 +21,4 @@ export * from './props';
export * from './logger';
export * from './editor';
export * from './stage';
export * from './operator';