diff --git a/package.json b/package.json index 1aecdf5..c1b0ea2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@statecharts/xstate-viz", - "version": "0.1.2", + "name": "@sierralabs/xstate-viz", + "version": "0.2.1", "description": "Visualizer for XState.", "main": "lib/index.js", "scripts": { diff --git a/src/StateChart.tsx b/src/StateChart.tsx index 3125b5c..4f833bc 100755 --- a/src/StateChart.tsx +++ b/src/StateChart.tsx @@ -372,7 +372,23 @@ export class StateChart extends React.Component< } ); } - onSelectionChange(stateChartNode: StateChartNode) { + selectStateNodePath(path: string[]) { + for (const stateChartNode of this.stateChartNodes) { + let index = 0; + for (const part of path) { + // attempt to match all path parts + if (stateChartNode.props.stateNode.path[index] !== part) { + break; // not a match + } else if (index === path.length - 1) { + // found the stateChartNode to select + this.changeSelection(stateChartNode); + return; + } + index++; + } + } + } + changeSelection(stateChartNode: StateChartNode) { if (this.selected) { // unselect previous state this.selected.setState({ selected: false }); @@ -380,6 +396,9 @@ export class StateChart extends React.Component< // set the current selected state stateChartNode.setState({ selected: true }); this.selected = stateChartNode; + } + onSelectionChange(stateChartNode: StateChartNode) { + this.changeSelection(stateChartNode); // notify a start chart was selected if (this.props.onSelectionChange) { this.props.onSelectionChange(stateChartNode);