-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: history add max stack size (#3253)
* feat: init * feat: add demo * feat: add demo * feat: add demo * feat: limit undoStack size * feat: 0 means not limit --------- Co-authored-by: lijianqiang.seven <[email protected]> Co-authored-by: zhangzirui.1993 <[email protected]>
- Loading branch information
1 parent
04656f3
commit fba5310
Showing
3 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
examples/x6-example-features/src/pages/history/index.tsx
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,104 @@ | ||
import React from 'react' | ||
import { Graph } from '@antv/x6' | ||
import { Keyboard } from '@antv/x6-plugin-keyboard' | ||
import { Selection } from '@antv/x6-plugin-selection' | ||
import { History } from '@antv/x6-plugin-history' | ||
import '../index.less' | ||
|
||
export default class Example extends React.Component< | ||
{}, | ||
{ graph: Graph | undefined } | ||
> { | ||
private container: HTMLDivElement | ||
|
||
componentDidMount() { | ||
const graph = new Graph({ | ||
container: this.container, | ||
width: 800, | ||
height: 600, | ||
grid: true, | ||
}) | ||
|
||
this.setState({ graph }) | ||
|
||
const selection = new Selection({ enabled: true }) | ||
const keyboard = new Keyboard({ enabled: true }) | ||
const history = new History({ enabled: true, stackSize: 5 }) | ||
|
||
graph.use(selection) | ||
graph.use(keyboard) | ||
graph.use(history) | ||
|
||
graph.addNode({ | ||
x: 50, | ||
y: 50, | ||
width: 100, | ||
height: 40, | ||
attrs: { label: { text: 'A' } }, | ||
}) | ||
|
||
graph.addNode({ | ||
x: 250, | ||
y: 50, | ||
width: 100, | ||
height: 40, | ||
attrs: { label: { text: 'B' } }, | ||
}) | ||
|
||
graph.addNode({ | ||
x: 350, | ||
y: 150, | ||
width: 100, | ||
height: 40, | ||
attrs: { label: { text: 'C' } }, | ||
}) | ||
|
||
keyboard.bindKey('backspace', () => { | ||
graph.removeCells(selection.getSelectedCells()) | ||
}) | ||
keyboard.bindKey('command+z', () => { | ||
this.undo() | ||
}) | ||
keyboard.bindKey('command+shift+z', () => { | ||
this.redo() | ||
}) | ||
} | ||
|
||
refContainer = (container: HTMLDivElement) => { | ||
this.container = container | ||
} | ||
|
||
enablePlugins = () => { | ||
const { graph } = this.state | ||
graph?.enablePlugins('keyboard') | ||
} | ||
|
||
disablePlugins = () => { | ||
const { graph } = this.state | ||
graph?.disablePlugins('keyboard') | ||
} | ||
|
||
undo = () => { | ||
const { graph } = this.state | ||
const history = graph?.getPlugin('history') as History | ||
history?.undo() | ||
} | ||
|
||
redo = () => { | ||
const { graph } = this.state | ||
const history = graph?.getPlugin('history') as History | ||
history?.redo() | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="x6-graph-wrap"> | ||
<div ref={this.refContainer} className="x6-graph" /> | ||
<button onClick={this.enablePlugins}>enable</button> | ||
<button onClick={this.disablePlugins}>disable</button> | ||
<button onClick={this.undo}>undo</button> | ||
<button onClick={this.redo}>redo</button> | ||
</div> | ||
) | ||
} | ||
} |
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