mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 17:48:13 +00:00
feat: 增加 node replaceWith 方法
This commit is contained in:
parent
5adff447c1
commit
d44f95b643
@ -158,6 +158,13 @@ export class NodeChildren {
|
||||
return this.children.indexOf(node);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
splice(start: number, deleteCount: number, node: Node): Node[] {
|
||||
return this.children.splice(start, deleteCount, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据索引获得节点
|
||||
*/
|
||||
|
||||
@ -175,9 +175,9 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
if (!autoruns || autoruns.length < 1) {
|
||||
return;
|
||||
}
|
||||
this.autoruns = autoruns.map(item => {
|
||||
this.autoruns = autoruns.map((item) => {
|
||||
return autorun(() => {
|
||||
item.autorun(this.props.get(item.name, true) as any)
|
||||
item.autorun(this.props.get(item.name, true) as any);
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
@ -384,9 +384,33 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
// todo
|
||||
}
|
||||
|
||||
replaceWith(schema: Schema, migrate = true) {
|
||||
replaceWith(schema: Schema, migrate = false) {
|
||||
// reuse the same id? or replaceSelection
|
||||
//
|
||||
schema = Object.assign({}, migrate ? this.export() : {}, schema);
|
||||
return this.parent?.replaceChild(this, schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换子节点
|
||||
*
|
||||
* @param {Node} node
|
||||
* @param {object} data
|
||||
*/
|
||||
replaceChild(node: Node, data: any) {
|
||||
if (this.children?.has(node)) {
|
||||
const selected = this.document.selection.has(node.id);
|
||||
|
||||
delete data.id;
|
||||
const newNode = this.document.createNode(data);
|
||||
|
||||
this.insertBefore(newNode, node);
|
||||
node.remove();
|
||||
|
||||
if (selected) {
|
||||
this.document.selection.select(newNode.id);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
getProp(path: string, stash = true): Prop | null {
|
||||
@ -442,7 +466,6 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
return this.parent.children.indexOf(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取下一个兄弟节点
|
||||
*/
|
||||
@ -607,7 +630,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
|
||||
if (this.isParental()) {
|
||||
this.children.purge();
|
||||
}
|
||||
this.autoruns?.forEach(dispose => dispose());
|
||||
this.autoruns?.forEach((dispose) => dispose());
|
||||
this.props.purge();
|
||||
this.document.internalRemoveAndPurgeNode(this);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user