@statewalker/fsm-charts 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-UBYXED35.js → chunk-NXS24DZQ.js} +28 -6
- package/dist/{chunk-ZSGS37QH.js → chunk-OTGN3OYG.js} +14 -7
- package/dist/index-layout.js +1 -1
- package/dist/index-runtime.d.ts +20 -2
- package/dist/index-runtime.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
- package/src/layout/buildFlatCharts.ts +13 -8
- package/src/runtime/RuntimeStatechartApi.ts +3 -3
- package/src/runtime/StateChartIndex.ts +28 -2
|
@@ -28,10 +28,10 @@ var RuntimeStatechartApi = class {
|
|
|
28
28
|
onTransitionClick(listener) {
|
|
29
29
|
return this._addListener(this._transitionsClickListeners, listener);
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
openStatePanels() {
|
|
32
32
|
this._setStatePanelStatus(`details[data-state-id]`, true);
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
closeStatePanels() {
|
|
35
35
|
this._setStatePanelStatus(`details[data-state-id]`, false);
|
|
36
36
|
}
|
|
37
37
|
isStatePanelOpen(stateId) {
|
|
@@ -44,7 +44,7 @@ var RuntimeStatechartApi = class {
|
|
|
44
44
|
const lastId = stateIds[stateIds.length - 1];
|
|
45
45
|
const selected = this.isStateSelected(lastId);
|
|
46
46
|
this.deselectStates();
|
|
47
|
-
this.
|
|
47
|
+
this.closeStatePanels();
|
|
48
48
|
this.activateStates(...stateIds);
|
|
49
49
|
if (selected) {
|
|
50
50
|
this.deselectState(lastId);
|
|
@@ -226,6 +226,30 @@ var StateChartIndex = class {
|
|
|
226
226
|
this.statechart = statechart;
|
|
227
227
|
this._buildIndexes();
|
|
228
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Returns a state node or a chart by the specified identifier.
|
|
231
|
+
* @param id the id of a state node or a chart
|
|
232
|
+
* @returns a state node or a chart
|
|
233
|
+
*/
|
|
234
|
+
getNodeById(id) {
|
|
235
|
+
return this._nodesIndex[id] || this._chartsIndex[id];
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Returns a chart by the specified identifier.
|
|
239
|
+
* @param id the id of a state node or a chart
|
|
240
|
+
* @returns a state node or a chart
|
|
241
|
+
*/
|
|
242
|
+
getChartById(id) {
|
|
243
|
+
return this._chartsIndex[id];
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Returns an edge by the specified identifier.
|
|
247
|
+
* @param id the id of a graph edge
|
|
248
|
+
* @returns a graph edge
|
|
249
|
+
*/
|
|
250
|
+
getEdgeById(id) {
|
|
251
|
+
return this._edgeIndex[id];
|
|
252
|
+
}
|
|
229
253
|
/**
|
|
230
254
|
* Transforms a stack of state keys to the corresponding identifiers.
|
|
231
255
|
* If a key in the stack was not found then this method returns
|
|
@@ -242,9 +266,7 @@ var StateChartIndex = class {
|
|
|
242
266
|
if (!node)
|
|
243
267
|
break;
|
|
244
268
|
result.push(node.id);
|
|
245
|
-
list = node.children;
|
|
246
|
-
if (!list?.length)
|
|
247
|
-
list = node.nodes;
|
|
269
|
+
list = [...node.children || [], ...node.nodes || []];
|
|
248
270
|
}
|
|
249
271
|
return result.length === stack.length ? result : [];
|
|
250
272
|
}
|
|
@@ -2474,8 +2474,9 @@ function buildFlatCharts({
|
|
|
2474
2474
|
try {
|
|
2475
2475
|
setLodash(lodash);
|
|
2476
2476
|
const graph = new Graph({
|
|
2477
|
-
directed: true
|
|
2478
|
-
|
|
2477
|
+
directed: true,
|
|
2478
|
+
multigraph: true
|
|
2479
|
+
}).setGraph({ rankdir: vertical ? "tb" : "lr", multigraph: true });
|
|
2479
2480
|
const nodesIndex = {};
|
|
2480
2481
|
const getStateNodeId = (key, state = key) => {
|
|
2481
2482
|
let id = nodesIndex[key];
|
|
@@ -2492,12 +2493,18 @@ function buildFlatCharts({
|
|
|
2492
2493
|
const toStateKey = toState || finalStateKey;
|
|
2493
2494
|
const to = getStateNodeId(toStateKey, toState);
|
|
2494
2495
|
const params = getTransitionParams(fromStateKey, event, toStateKey);
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2496
|
+
const edgeId = newId("t");
|
|
2497
|
+
graph.setEdge(
|
|
2498
|
+
from,
|
|
2499
|
+
to,
|
|
2500
|
+
{
|
|
2501
|
+
id: edgeId,
|
|
2502
|
+
...params
|
|
2503
|
+
},
|
|
2504
|
+
edgeId
|
|
2505
|
+
);
|
|
2499
2506
|
}
|
|
2500
|
-
layout(graph, { rankdir:
|
|
2507
|
+
layout(graph, { rankdir: "lr" });
|
|
2501
2508
|
const [top, right, bottom, left] = getPadding(padding);
|
|
2502
2509
|
const nodes = graph.nodes().map((id) => {
|
|
2503
2510
|
const n = graph.node(id);
|
package/dist/index-layout.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
1
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-OTGN3OYG.js';
|
|
2
2
|
import './chunk-NXWOFQMO.js';
|
|
3
3
|
import './chunk-XEO3YXBM.js';
|
package/dist/index-runtime.d.ts
CHANGED
|
@@ -16,8 +16,8 @@ declare class RuntimeStatechartApi {
|
|
|
16
16
|
close(): void;
|
|
17
17
|
onStateClick(listener: RuntimeListener): () => void;
|
|
18
18
|
onTransitionClick(listener: RuntimeListener): () => void;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
openStatePanels(): void;
|
|
20
|
+
closeStatePanels(): void;
|
|
21
21
|
isStatePanelOpen(stateId: string): boolean;
|
|
22
22
|
toggleState(...stateIds: string[]): boolean;
|
|
23
23
|
activateStates(...stateIds: string[]): void;
|
|
@@ -53,6 +53,24 @@ declare class StateChartIndex {
|
|
|
53
53
|
constructor({ statechart }: {
|
|
54
54
|
statechart: StateChart;
|
|
55
55
|
});
|
|
56
|
+
/**
|
|
57
|
+
* Returns a state node or a chart by the specified identifier.
|
|
58
|
+
* @param id the id of a state node or a chart
|
|
59
|
+
* @returns a state node or a chart
|
|
60
|
+
*/
|
|
61
|
+
getNodeById(id: string): StateGraphNode | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Returns a chart by the specified identifier.
|
|
64
|
+
* @param id the id of a state node or a chart
|
|
65
|
+
* @returns a state node or a chart
|
|
66
|
+
*/
|
|
67
|
+
getChartById(id: string): StateChart | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Returns an edge by the specified identifier.
|
|
70
|
+
* @param id the id of a graph edge
|
|
71
|
+
* @returns a graph edge
|
|
72
|
+
*/
|
|
73
|
+
getEdgeById(id: string): StateGraphEdge | undefined;
|
|
56
74
|
/**
|
|
57
75
|
* Transforms a stack of state keys to the corresponding identifiers.
|
|
58
76
|
* If a key in the stack was not found then this method returns
|
package/dist/index-runtime.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { RuntimeStatechartApi, StateChartIndex } from './chunk-
|
|
1
|
+
export { RuntimeStatechartApi, StateChartIndex } from './chunk-NXS24DZQ.js';
|
|
2
2
|
import './chunk-XEO3YXBM.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
1
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-OTGN3OYG.js';
|
|
2
2
|
export { buildStatechartCss, buildStatechartStyles, buildStatechartSvg, buildStatechartsPanel, serializeCss, toKebabCase } from './chunk-YYNW6Q2T.js';
|
|
3
3
|
import './chunk-NXWOFQMO.js';
|
|
4
|
-
export { RuntimeStatechartApi, StateChartIndex } from './chunk-
|
|
4
|
+
export { RuntimeStatechartApi, StateChartIndex } from './chunk-NXS24DZQ.js';
|
|
5
5
|
import './chunk-XEO3YXBM.js';
|
package/package.json
CHANGED
|
@@ -49,9 +49,8 @@ export function buildFlatCharts({
|
|
|
49
49
|
setLodash(lodash);
|
|
50
50
|
const graph = new Graph({
|
|
51
51
|
directed: true,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
.setDefaultEdgeLabel(() => ({}));
|
|
52
|
+
multigraph: true,
|
|
53
|
+
}).setGraph({ rankdir: vertical ? "tb" : "lr", multigraph: true });
|
|
55
54
|
|
|
56
55
|
const nodesIndex: Record<string, string> = {};
|
|
57
56
|
|
|
@@ -71,12 +70,18 @@ export function buildFlatCharts({
|
|
|
71
70
|
const toStateKey = toState || finalStateKey;
|
|
72
71
|
const to = getStateNodeId(toStateKey, toState);
|
|
73
72
|
const params = getTransitionParams(fromStateKey, event, toStateKey);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const edgeId = newId("t");
|
|
74
|
+
graph.setEdge(
|
|
75
|
+
from,
|
|
76
|
+
to,
|
|
77
|
+
{
|
|
78
|
+
id: edgeId,
|
|
79
|
+
...params,
|
|
80
|
+
},
|
|
81
|
+
edgeId
|
|
82
|
+
);
|
|
78
83
|
}
|
|
79
|
-
layout(graph, { rankdir:
|
|
84
|
+
layout(graph, { rankdir: "lr" });
|
|
80
85
|
|
|
81
86
|
const [top, right, bottom, left] = getPadding(padding);
|
|
82
87
|
|
|
@@ -35,10 +35,10 @@ export class RuntimeStatechartApi {
|
|
|
35
35
|
return this._addListener(this._transitionsClickListeners, listener);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
openStatePanels() {
|
|
39
39
|
this._setStatePanelStatus(`details[data-state-id]`, true);
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
closeStatePanels() {
|
|
42
42
|
this._setStatePanelStatus(`details[data-state-id]`, false);
|
|
43
43
|
}
|
|
44
44
|
isStatePanelOpen(stateId: string) {
|
|
@@ -52,7 +52,7 @@ export class RuntimeStatechartApi {
|
|
|
52
52
|
const lastId = stateIds[stateIds.length - 1];
|
|
53
53
|
const selected = this.isStateSelected(lastId);
|
|
54
54
|
this.deselectStates();
|
|
55
|
-
this.
|
|
55
|
+
this.closeStatePanels();
|
|
56
56
|
this.activateStates(...stateIds);
|
|
57
57
|
if (selected) {
|
|
58
58
|
this.deselectState(lastId);
|
|
@@ -17,6 +17,33 @@ export class StateChartIndex {
|
|
|
17
17
|
this._buildIndexes();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Returns a state node or a chart by the specified identifier.
|
|
22
|
+
* @param id the id of a state node or a chart
|
|
23
|
+
* @returns a state node or a chart
|
|
24
|
+
*/
|
|
25
|
+
getNodeById(id: string): StateGraphNode | undefined {
|
|
26
|
+
return this._nodesIndex[id] || this._chartsIndex[id];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a chart by the specified identifier.
|
|
31
|
+
* @param id the id of a state node or a chart
|
|
32
|
+
* @returns a state node or a chart
|
|
33
|
+
*/
|
|
34
|
+
getChartById(id: string): StateChart | undefined {
|
|
35
|
+
return this._chartsIndex[id];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns an edge by the specified identifier.
|
|
40
|
+
* @param id the id of a graph edge
|
|
41
|
+
* @returns a graph edge
|
|
42
|
+
*/
|
|
43
|
+
getEdgeById(id: string): StateGraphEdge | undefined {
|
|
44
|
+
return this._edgeIndex[id];
|
|
45
|
+
}
|
|
46
|
+
|
|
20
47
|
/**
|
|
21
48
|
* Transforms a stack of state keys to the corresponding identifiers.
|
|
22
49
|
* If a key in the stack was not found then this method returns
|
|
@@ -32,8 +59,7 @@ export class StateChartIndex {
|
|
|
32
59
|
const node = list.find((node) => node.key === key);
|
|
33
60
|
if (!node) break;
|
|
34
61
|
result.push(node.id);
|
|
35
|
-
list = node.children;
|
|
36
|
-
if (!list?.length) list = node.nodes;
|
|
62
|
+
list = [...(node.children || []), ...(node.nodes || [])];
|
|
37
63
|
}
|
|
38
64
|
return result.length === stack.length ? result : [];
|
|
39
65
|
}
|