mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-04-23 10:18:55 +00:00
fix(editor): 历史记录信息中添加页面信息
This commit is contained in:
parent
99c8274a1e
commit
26dc70d70c
@ -398,7 +398,10 @@ class Editor extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(isPage(newNodes[0]) || isPageFragment(newNodes[0]))) {
|
if (!(isPage(newNodes[0]) || isPageFragment(newNodes[0]))) {
|
||||||
this.pushOpHistory('add', {
|
const pageForOp = this.getNodeInfo(newNodes[0].id, false).page;
|
||||||
|
this.pushOpHistory(
|
||||||
|
'add',
|
||||||
|
{
|
||||||
nodes: newNodes.map((n) => cloneDeep(toRaw(n))),
|
nodes: newNodes.map((n) => cloneDeep(toRaw(n))),
|
||||||
parentId: (this.getParentById(newNodes[0].id, false) ?? this.get('root'))!.id,
|
parentId: (this.getParentById(newNodes[0].id, false) ?? this.get('root'))!.id,
|
||||||
indexMap: Object.fromEntries(
|
indexMap: Object.fromEntries(
|
||||||
@ -407,7 +410,9 @@ class Editor extends BaseService {
|
|||||||
return [n.id, p ? getNodeIndex(n.id, p) : -1];
|
return [n.id, p ? getNodeIndex(n.id, p) : -1];
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
});
|
},
|
||||||
|
{ name: pageForOp?.name || '', id: pageForOp!.id },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('add', newNodes);
|
this.emit('add', newNodes);
|
||||||
@ -475,10 +480,14 @@ class Editor extends BaseService {
|
|||||||
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
const nodes = Array.isArray(nodeOrNodeList) ? nodeOrNodeList : [nodeOrNodeList];
|
||||||
|
|
||||||
const removedItems: { node: MNode; parentId: Id; index: number }[] = [];
|
const removedItems: { node: MNode; parentId: Id; index: number }[] = [];
|
||||||
|
let pageForOp: { name: string; id: Id } | null = null;
|
||||||
if (!(isPage(nodes[0]) || isPageFragment(nodes[0]))) {
|
if (!(isPage(nodes[0]) || isPageFragment(nodes[0]))) {
|
||||||
for (const n of nodes) {
|
for (const n of nodes) {
|
||||||
const { parent, node: curNode } = this.getNodeInfo(n.id, false);
|
const { parent, node: curNode, page } = this.getNodeInfo(n.id, false);
|
||||||
if (parent && curNode) {
|
if (parent && curNode) {
|
||||||
|
if (!pageForOp && page) {
|
||||||
|
pageForOp = { name: page.name || '', id: page.id };
|
||||||
|
}
|
||||||
const idx = getNodeIndex(curNode.id, parent);
|
const idx = getNodeIndex(curNode.id, parent);
|
||||||
removedItems.push({
|
removedItems.push({
|
||||||
node: cloneDeep(toRaw(curNode)),
|
node: cloneDeep(toRaw(curNode)),
|
||||||
@ -491,8 +500,8 @@ class Editor extends BaseService {
|
|||||||
|
|
||||||
await Promise.all(nodes.map((node) => this.doRemove(node)));
|
await Promise.all(nodes.map((node) => this.doRemove(node)));
|
||||||
|
|
||||||
if (removedItems.length > 0) {
|
if (removedItems.length > 0 && pageForOp) {
|
||||||
this.pushOpHistory('remove', { removedItems });
|
this.pushOpHistory('remove', { removedItems }, pageForOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('remove', nodes);
|
this.emit('remove', nodes);
|
||||||
@ -582,12 +591,17 @@ class Editor extends BaseService {
|
|||||||
if (updateData[0].oldNode?.type !== NodeType.ROOT) {
|
if (updateData[0].oldNode?.type !== NodeType.ROOT) {
|
||||||
const curNodes = this.get('nodes');
|
const curNodes = this.get('nodes');
|
||||||
if (!this.isHistoryStateChange && curNodes.length) {
|
if (!this.isHistoryStateChange && curNodes.length) {
|
||||||
this.pushOpHistory('update', {
|
const pageForOp = this.getNodeInfo(nodes[0].id, false).page;
|
||||||
|
this.pushOpHistory(
|
||||||
|
'update',
|
||||||
|
{
|
||||||
updatedItems: updateData.map((d) => ({
|
updatedItems: updateData.map((d) => ({
|
||||||
oldNode: cloneDeep(d.oldNode),
|
oldNode: cloneDeep(d.oldNode),
|
||||||
newNode: cloneDeep(toRaw(d.newNode)),
|
newNode: cloneDeep(toRaw(d.newNode)),
|
||||||
})),
|
})),
|
||||||
});
|
},
|
||||||
|
{ name: pageForOp?.name || '', id: pageForOp!.id },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.isHistoryStateChange = false;
|
this.isHistoryStateChange = false;
|
||||||
}
|
}
|
||||||
@ -772,9 +786,14 @@ class Editor extends BaseService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.addModifiedNodeId(parent.id);
|
this.addModifiedNodeId(parent.id);
|
||||||
this.pushOpHistory('update', {
|
const pageForOp = this.getNodeInfo(node.id, false).page;
|
||||||
|
this.pushOpHistory(
|
||||||
|
'update',
|
||||||
|
{
|
||||||
updatedItems: [{ oldNode: oldParent, newNode: cloneDeep(toRaw(parent)) }],
|
updatedItems: [{ oldNode: oldParent, newNode: cloneDeep(toRaw(parent)) }],
|
||||||
});
|
},
|
||||||
|
{ name: pageForOp?.name || '', id: pageForOp!.id },
|
||||||
|
);
|
||||||
|
|
||||||
this.emit('move-layer', offset);
|
this.emit('move-layer', offset);
|
||||||
}
|
}
|
||||||
@ -788,7 +807,7 @@ class Editor extends BaseService {
|
|||||||
this.captureSelectionBeforeOp();
|
this.captureSelectionBeforeOp();
|
||||||
|
|
||||||
const root = this.get('root');
|
const root = this.get('root');
|
||||||
const { node, parent } = this.getNodeInfo(config.id, false);
|
const { node, parent, page: pageForOp } = this.getNodeInfo(config.id, false);
|
||||||
const target = this.getNodeById(targetId, false) as MContainer;
|
const target = this.getNodeById(targetId, false) as MContainer;
|
||||||
|
|
||||||
const stage = this.get('stage');
|
const stage = this.get('stage');
|
||||||
@ -826,12 +845,16 @@ class Editor extends BaseService {
|
|||||||
|
|
||||||
this.addModifiedNodeId(target.id);
|
this.addModifiedNodeId(target.id);
|
||||||
this.addModifiedNodeId(parent.id);
|
this.addModifiedNodeId(parent.id);
|
||||||
this.pushOpHistory('update', {
|
this.pushOpHistory(
|
||||||
|
'update',
|
||||||
|
{
|
||||||
updatedItems: [
|
updatedItems: [
|
||||||
{ oldNode: oldSourceParent, newNode: cloneDeep(toRaw(parent)) },
|
{ oldNode: oldSourceParent, newNode: cloneDeep(toRaw(parent)) },
|
||||||
{ oldNode: oldTarget, newNode: cloneDeep(toRaw(target)) },
|
{ oldNode: oldTarget, newNode: cloneDeep(toRaw(target)) },
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
{ name: pageForOp?.name || '', id: pageForOp!.id },
|
||||||
|
);
|
||||||
|
|
||||||
return newConfig;
|
return newConfig;
|
||||||
}
|
}
|
||||||
@ -897,7 +920,8 @@ class Editor extends BaseService {
|
|||||||
updatedItems.push({ oldNode, newNode: cloneDeep(toRaw(newNode)) });
|
updatedItems.push({ oldNode, newNode: cloneDeep(toRaw(newNode)) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.pushOpHistory('update', { updatedItems });
|
const pageForOp = this.getNodeInfo(configs[0].id, false).page;
|
||||||
|
this.pushOpHistory('update', { updatedItems }, { name: pageForOp?.name || '', id: pageForOp!.id });
|
||||||
|
|
||||||
this.emit('drag-to', { targetIndex, configs, targetParent });
|
this.emit('drag-to', { targetIndex, configs, targetParent });
|
||||||
}
|
}
|
||||||
@ -991,12 +1015,14 @@ class Editor extends BaseService {
|
|||||||
this.selectionBeforeOp = this.get('nodes').map((n) => n.id);
|
this.selectionBeforeOp = this.get('nodes').map((n) => n.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private pushOpHistory(opType: HistoryOpType, extra: Partial<StepValue>) {
|
private pushOpHistory(opType: HistoryOpType, extra: Partial<StepValue>, pageData: { name: string; id: Id }) {
|
||||||
if (this.isHistoryStateChange) {
|
if (this.isHistoryStateChange) {
|
||||||
this.selectionBeforeOp = null;
|
this.selectionBeforeOp = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const step: StepValue = {
|
const step: StepValue = {
|
||||||
|
data: pageData,
|
||||||
opType,
|
opType,
|
||||||
selectedBefore: this.selectionBeforeOp ?? [],
|
selectedBefore: this.selectionBeforeOp ?? [],
|
||||||
selectedAfter: this.get('nodes').map((n) => n.id),
|
selectedAfter: this.get('nodes').map((n) => n.id),
|
||||||
|
|||||||
@ -550,6 +550,8 @@ export interface CodeParamStatement {
|
|||||||
export type HistoryOpType = 'add' | 'remove' | 'update';
|
export type HistoryOpType = 'add' | 'remove' | 'update';
|
||||||
|
|
||||||
export interface StepValue {
|
export interface StepValue {
|
||||||
|
/** 页面信息 */
|
||||||
|
data: { name: string; id: Id };
|
||||||
opType: HistoryOpType;
|
opType: HistoryOpType;
|
||||||
/** 操作前选中的节点 ID,用于撤销后恢复选择状态 */
|
/** 操作前选中的节点 ID,用于撤销后恢复选择状态 */
|
||||||
selectedBefore: Id[];
|
selectedBefore: Id[];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user