Skip to content

Commit

Permalink
feat: allow redo/undo customlink
Browse files Browse the repository at this point in the history
  • Loading branch information
SSShooter committed Nov 4, 2023
1 parent 323d156 commit 7323255
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
24 changes: 17 additions & 7 deletions src/customLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const drawCustomLink = function (this: MindElixirInstance, from: Topic, t
}

export const createLink = function (this: MindElixirInstance, from: Topic, to: Topic) {
const newLinkObj = {
const linkObj = {
id: generateUUID(),
label: 'Custom Link',
from: from.nodeObj.id,
Expand All @@ -143,7 +143,12 @@ export const createLink = function (this: MindElixirInstance, from: Topic, to: T
y: -200,
},
}
this.drawCustomLink(from, to, newLinkObj)
this.drawCustomLink(from, to, linkObj)

this.bus.fire('operation', {
name: 'createCustomLink',
obj: linkObj,
})
}

export const removeLink = function (this: MindElixirInstance, linkSvg?: CustomSvg) {
Expand All @@ -158,6 +163,12 @@ export const removeLink = function (this: MindElixirInstance, linkSvg?: CustomSv
const id = link.linkObj!.id
delete this.linkData[id]
link.remove()
this.bus.fire('operation', {
name: 'removeCustomLink',
obj: {
id,
},
})
}

export const selectLink = function (this: MindElixirInstance, link: CustomSvg) {
Expand Down Expand Up @@ -307,11 +318,10 @@ export function editCutsomLinkLabel(this: MindElixirInstance, el: CustomSvg) {
if (text === origin) return
textEl.innerHTML = node.label
this.linkDiv()
// this.bus.fire('operation', {
// name: 'finishEditSummary',
// obj: node,
// origin,
// })
this.bus.fire('operation', {
name: 'finishEditCustomLinkLabel',
obj: node,
})
})
console.timeEnd('editSummary')
}
Expand Down
5 changes: 5 additions & 0 deletions src/plugin/operationHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const calcCurentObject = function (operation: Operation): History['currentObject
type: 'summary',
value: (operation as any).obj.id,
}
} else if (['createCustomLink', 'removeCustomLink', 'finishEditCustomLinkLabel'].includes(operation.name)) {
return {
type: 'customLink',
value: (operation as any).obj.id,
}
} else if (['removeNodes'].includes(operation.name)) {
return {
type: 'nodes',
Expand Down
17 changes: 16 additions & 1 deletion src/utils/pubsub.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { LinkItem } from '../customLink'
import type { Summary } from '../summary'
import type { NodeObj } from '../types/index'

Expand Down Expand Up @@ -47,7 +48,21 @@ export type SummaryOperation =
obj: Summary
}

export type Operation = NodeOperation | SummaryOperation
export type CustomLinkOperation =
| {
name: 'createCustomLink'
obj: LinkItem
}
| {
name: 'removeCustomLink'
obj: { id: string }
}
| {
name: 'finishEditCustomLinkLabel'
obj: LinkItem
}

export type Operation = NodeOperation | SummaryOperation | CustomLinkOperation
export type OperationType = Operation['name']

export type EventMap = {
Expand Down

0 comments on commit 7323255

Please sign in to comment.