-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
7509e81
commit 25bbd38
Showing
17 changed files
with
197 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Clipboard as C } from '@antv/x6-plugin-clipboard'; | ||
import { useEffect } from 'react'; | ||
|
||
import { useGraphInstance } from '../hooks/useGraphInstance'; | ||
|
||
const Clipboard = (props: Omit<C.Options, 'enabled'>) => { | ||
const graph = useGraphInstance(); | ||
|
||
useEffect(() => { | ||
if (graph) { | ||
if (graph.getPlugin('clipboard')) { | ||
graph.disposePlugins('clipboard'); | ||
} | ||
graph.use( | ||
new C({ | ||
enabled: true, | ||
...props, | ||
}), | ||
); | ||
} | ||
}, [graph, props]); | ||
|
||
return null; | ||
}; | ||
|
||
export { Clipboard }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type { Clipboard } from '@antv/x6-plugin-clipboard'; | ||
import { useCallback } from 'react'; | ||
|
||
import { useGraphInstance } from './useGraphInstance'; | ||
import { useGraphStore } from './useGraphStore'; | ||
|
||
export const useClipboard = () => { | ||
const graph = useGraphInstance(); | ||
const addNodes = useGraphStore((state) => state.addNodes); | ||
const addEdges = useGraphStore((state) => state.addEdges); | ||
|
||
const isLoaded = useCallback(() => { | ||
const loaded = graph && graph.getPlugin('clipboard'); | ||
if (!loaded) { | ||
console.warn('clipboard is not loaded, please use clipboard component first'); | ||
} | ||
return loaded; | ||
}, [graph]); | ||
|
||
const copy = useCallback( | ||
(ids: string[], copyOptions?: Clipboard.CopyOptions) => { | ||
if (graph && isLoaded()) { | ||
const cells = ids.map((id) => graph?.getCellById(id)).filter(Boolean); | ||
graph.copy(cells, copyOptions); | ||
} | ||
}, | ||
[graph, isLoaded], | ||
); | ||
|
||
const cut = useCallback( | ||
(ids: string[], cutOptions?: Clipboard.CopyOptions) => { | ||
if (graph && isLoaded()) { | ||
const cells = ids.map((id) => graph?.getCellById(id)).filter(Boolean); | ||
graph.cut(cells, cutOptions); | ||
} | ||
}, | ||
[graph, isLoaded], | ||
); | ||
|
||
const paste = useCallback( | ||
(pasteOptions?: Clipboard.PasteOptions) => { | ||
if (graph && isLoaded()) { | ||
const cells = graph.paste(pasteOptions); | ||
cells.forEach((cell) => { | ||
if (cell.isNode()) { | ||
addNodes([cell.toJSON()], { silent: true }); | ||
} else if (cell.isEdge()) { | ||
addEdges([cell.toJSON()], { silent: true }); | ||
} | ||
}); | ||
} | ||
}, | ||
[graph, isLoaded, addNodes, addEdges], | ||
); | ||
|
||
return { copy, cut, paste }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Keyboard } from '@antv/x6-plugin-keyboard'; | ||
import { useEffect, useRef } from 'react'; | ||
|
||
import { useGraphInstance } from './useGraphInstance'; | ||
|
||
export const useBindKey = () => { | ||
const graph = useGraphInstance(); | ||
const ref = useRef<Keyboard>(); | ||
|
||
graph?.bindKey(); | ||
useEffect(() => { | ||
if (graph && !ref.current) { | ||
ref.current = new Keyboard({ | ||
enabled: true, | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [graph]); | ||
|
||
return { clipboard: ref.current }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { Graph } from '@antv/x6'; | ||
|
||
export * from './components'; | ||
export * from './hooks'; | ||
export * from './util'; | ||
export * from './types'; | ||
|
||
export * from '@antv/x6-react-shape'; | ||
export { Graph }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
import * as Util from './main'; | ||
|
||
export { Util }; | ||
export * from './algorithm'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.