mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-05-05 01:38:57 +08:00
fix(editor): 编辑器初始化默认选择节点
This commit is contained in:
parent
f050ec1273
commit
45eaea6f68
@ -224,15 +224,25 @@ export default defineComponent({
|
|||||||
|
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
editorService.on('root-change', (value) => {
|
editorService.on('root-change', (value) => {
|
||||||
const node = editorService.get<MNode | null>('node');
|
const nodeId = editorService.get<MNode | null>('node')?.id || props.defaultSelected;
|
||||||
const nodeId = node?.id || props.defaultSelected;
|
let node;
|
||||||
if (nodeId && node !== value) {
|
if (nodeId) {
|
||||||
editorService.select(nodeId);
|
node = editorService.getNodeById(nodeId);
|
||||||
} else {
|
|
||||||
editorService.set('nodes', [value]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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'));
|
const node = computed(() => services?.editorService.get<MNode>('node'));
|
||||||
|
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
if (stage) return;
|
if (stage || !page.value) return;
|
||||||
|
|
||||||
if (!stageContainer.value) return;
|
if (!stageContainer.value) return;
|
||||||
if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
|
if (!(stageOptions?.runtimeUrl || stageOptions?.render) || !root.value) return;
|
||||||
|
@ -21,3 +21,4 @@ export * from './props';
|
|||||||
export * from './logger';
|
export * from './logger';
|
||||||
export * from './editor';
|
export * from './editor';
|
||||||
export * from './stage';
|
export * from './stage';
|
||||||
|
export * from './operator';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user