Skip to content

Commit 7323255

Browse files
committed
feat: allow redo/undo customlink
1 parent 323d156 commit 7323255

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

src/customLink.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const drawCustomLink = function (this: MindElixirInstance, from: Topic, t
129129
}
130130

131131
export const createLink = function (this: MindElixirInstance, from: Topic, to: Topic) {
132-
const newLinkObj = {
132+
const linkObj = {
133133
id: generateUUID(),
134134
label: 'Custom Link',
135135
from: from.nodeObj.id,
@@ -143,7 +143,12 @@ export const createLink = function (this: MindElixirInstance, from: Topic, to: T
143143
y: -200,
144144
},
145145
}
146-
this.drawCustomLink(from, to, newLinkObj)
146+
this.drawCustomLink(from, to, linkObj)
147+
148+
this.bus.fire('operation', {
149+
name: 'createCustomLink',
150+
obj: linkObj,
151+
})
147152
}
148153

149154
export const removeLink = function (this: MindElixirInstance, linkSvg?: CustomSvg) {
@@ -158,6 +163,12 @@ export const removeLink = function (this: MindElixirInstance, linkSvg?: CustomSv
158163
const id = link.linkObj!.id
159164
delete this.linkData[id]
160165
link.remove()
166+
this.bus.fire('operation', {
167+
name: 'removeCustomLink',
168+
obj: {
169+
id,
170+
},
171+
})
161172
}
162173

163174
export const selectLink = function (this: MindElixirInstance, link: CustomSvg) {
@@ -307,11 +318,10 @@ export function editCutsomLinkLabel(this: MindElixirInstance, el: CustomSvg) {
307318
if (text === origin) return
308319
textEl.innerHTML = node.label
309320
this.linkDiv()
310-
// this.bus.fire('operation', {
311-
// name: 'finishEditSummary',
312-
// obj: node,
313-
// origin,
314-
// })
321+
this.bus.fire('operation', {
322+
name: 'finishEditCustomLinkLabel',
323+
obj: node,
324+
})
315325
})
316326
console.timeEnd('editSummary')
317327
}

src/plugin/operationHistory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ const calcCurentObject = function (operation: Operation): History['currentObject
2323
type: 'summary',
2424
value: (operation as any).obj.id,
2525
}
26+
} else if (['createCustomLink', 'removeCustomLink', 'finishEditCustomLinkLabel'].includes(operation.name)) {
27+
return {
28+
type: 'customLink',
29+
value: (operation as any).obj.id,
30+
}
2631
} else if (['removeNodes'].includes(operation.name)) {
2732
return {
2833
type: 'nodes',

src/utils/pubsub.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { LinkItem } from '../customLink'
12
import type { Summary } from '../summary'
23
import type { NodeObj } from '../types/index'
34

@@ -47,7 +48,21 @@ export type SummaryOperation =
4748
obj: Summary
4849
}
4950

50-
export type Operation = NodeOperation | SummaryOperation
51+
export type CustomLinkOperation =
52+
| {
53+
name: 'createCustomLink'
54+
obj: LinkItem
55+
}
56+
| {
57+
name: 'removeCustomLink'
58+
obj: { id: string }
59+
}
60+
| {
61+
name: 'finishEditCustomLinkLabel'
62+
obj: LinkItem
63+
}
64+
65+
export type Operation = NodeOperation | SummaryOperation | CustomLinkOperation
5166
export type OperationType = Operation['name']
5267

5368
export type EventMap = {

0 commit comments

Comments
 (0)