mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
fix(editor): 编辑器初始化默认选择节点
This commit is contained in:
parent
f050ec1273
commit
45eaea6f68
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
// 初始值变化,重新设置节点信息
|
||||
|
@ -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;
|
||||
|
@ -21,3 +21,4 @@ export * from './props';
|
||||
export * from './logger';
|
||||
export * from './editor';
|
||||
export * from './stage';
|
||||
export * from './operator';
|
||||
|
Loading…
x
Reference in New Issue
Block a user