Compare commits

...

2 Commits

Author SHA1 Message Date
roymondchen
26efa75ff2 feat(editor): update 支持 selectedAfterUpdate 参数控制是否更新 nodes
Made-with: Cursor
2026-04-28 15:50:03 +08:00
roymondchen
59716e909b chore(vue-runtime-help): release v2.0.3
useEditorDsl 返回 root 以便外部访问根节点

Made-with: Cursor
2026-04-24 16:23:11 +08:00
3 changed files with 13 additions and 7 deletions

View File

@ -509,7 +509,10 @@ class Editor extends BaseService {
public async doUpdate(
config: MNode,
{ changeRecords = [] }: { changeRecords?: ChangeRecord[] } = {},
{
changeRecords = [],
selectedAfterUpdate = true,
}: { changeRecords?: ChangeRecord[]; selectedAfterUpdate?: boolean } = {},
): Promise<{ newNode: MNode; oldNode: MNode; changeRecords?: ChangeRecord[] }> {
const root = this.get('root');
if (!root) throw new Error('root为空');
@ -554,10 +557,12 @@ class Editor extends BaseService {
parentNodeItems[index] = newConfig;
// 将update后的配置更新到nodes中
if (selectedAfterUpdate) {
const nodes = this.get('nodes');
const targetIndex = nodes.findIndex((nodeItem: MNode) => `${nodeItem.id}` === `${newConfig.id}`);
nodes.splice(targetIndex, 1, newConfig);
this.set('nodes', [...nodes]);
}
if (isPage(newConfig) || isPageFragment(newConfig)) {
this.set('page', newConfig as MPage | MPageFragment);
@ -580,7 +585,7 @@ class Editor extends BaseService {
*/
public async update(
config: MNode | MNode[],
data: { changeRecords?: ChangeRecord[] } = {},
data: { changeRecords?: ChangeRecord[]; selectedAfterUpdate?: boolean } = {},
): Promise<MNode | MNode[]> {
this.captureSelectionBeforeOp();

View File

@ -1,5 +1,5 @@
{
"version": "2.0.2",
"version": "2.0.3",
"name": "@tmagic/vue-runtime-help",
"type": "module",
"sideEffects": false,

View File

@ -161,6 +161,7 @@ export const useEditorDsl = (app = inject<TMagicApp>('app'), runtimeApi: Runtime
});
return {
root,
pageConfig,
app,
};