jssm 5.80.1 → 5.81.0
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/CHANGELOG.md +43 -45
- package/README.md +2 -2
- package/dist/es6/jssm-dot.js +1 -1
- package/dist/es6/jssm.d.ts +31 -15
- package/dist/es6/jssm.js +54 -29
- package/dist/es6/jssm_types.d.ts +6 -1
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +31 -15
- package/jssm_types.d.ts +6 -1
- package/package.json +1 -1
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
|
|
|
94
94
|
* ```typescript
|
|
95
95
|
* import { sm } from 'jssm';
|
|
96
96
|
*
|
|
97
|
-
* const
|
|
97
|
+
* const lswitch = sm`on <=> off;`;
|
|
98
98
|
* ```
|
|
99
99
|
*
|
|
100
100
|
* Method {@link from}:
|
|
@@ -149,7 +149,7 @@ declare function wrap_parse(input: string, options?: Object): any;
|
|
|
149
149
|
* ```typescript
|
|
150
150
|
* import { sm } from 'jssm';
|
|
151
151
|
*
|
|
152
|
-
* const
|
|
152
|
+
* const lswitch = sm`on <=> off;`;
|
|
153
153
|
* ```
|
|
154
154
|
*
|
|
155
155
|
* Method {@link from}:
|
|
@@ -266,6 +266,7 @@ declare class Machine<mDT> {
|
|
|
266
266
|
_terminal_state_style: JssmStateConfig;
|
|
267
267
|
_start_state_style: JssmStateConfig;
|
|
268
268
|
_end_state_style: JssmStateConfig;
|
|
269
|
+
_state_labels: Map<string, string>;
|
|
269
270
|
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config }: JssmGenericConfig<mDT>);
|
|
270
271
|
/********
|
|
271
272
|
*
|
|
@@ -282,17 +283,32 @@ declare class Machine<mDT> {
|
|
|
282
283
|
* ```typescript
|
|
283
284
|
* import * as jssm from 'jssm';
|
|
284
285
|
*
|
|
285
|
-
* const
|
|
286
|
-
* console.log(
|
|
286
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
287
|
+
* console.log( lswitch.state() ); // 'on'
|
|
287
288
|
*
|
|
288
|
-
*
|
|
289
|
-
* console.log(
|
|
289
|
+
* lswitch.transition('off');
|
|
290
|
+
* console.log( lswitch.state() ); // 'off'
|
|
290
291
|
* ```
|
|
291
292
|
*
|
|
292
293
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
293
294
|
*
|
|
294
295
|
*/
|
|
295
296
|
state(): StateType;
|
|
297
|
+
/*********
|
|
298
|
+
*
|
|
299
|
+
* Get the label for a given state, if any; return `undefined` otherwise.
|
|
300
|
+
*
|
|
301
|
+
* ```typescript
|
|
302
|
+
* import * as jssm from 'jssm';
|
|
303
|
+
*
|
|
304
|
+
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
|
|
305
|
+
* console.log( lswitch.label_for('a') ); // 'Foo!'
|
|
306
|
+
* ```
|
|
307
|
+
*
|
|
308
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
309
|
+
*
|
|
310
|
+
*/
|
|
311
|
+
label_for(state: StateType): string;
|
|
296
312
|
/*********
|
|
297
313
|
*
|
|
298
314
|
* Get the current data of a machine.
|
|
@@ -300,8 +316,8 @@ declare class Machine<mDT> {
|
|
|
300
316
|
* ```typescript
|
|
301
317
|
* import * as jssm from 'jssm';
|
|
302
318
|
*
|
|
303
|
-
* const
|
|
304
|
-
* console.log(
|
|
319
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
320
|
+
* console.log( lswitch.data() ); // 1
|
|
305
321
|
* ```
|
|
306
322
|
*
|
|
307
323
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -545,8 +561,8 @@ declare class Machine<mDT> {
|
|
|
545
561
|
* ```typescript
|
|
546
562
|
* import * as jssm from 'jssm';
|
|
547
563
|
*
|
|
548
|
-
* const
|
|
549
|
-
* console.log(
|
|
564
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
565
|
+
* console.log( lswitch.states() ); // ['on', 'off']
|
|
550
566
|
* ```
|
|
551
567
|
*
|
|
552
568
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -561,10 +577,10 @@ declare class Machine<mDT> {
|
|
|
561
577
|
* ```typescript
|
|
562
578
|
* import * as jssm from 'jssm';
|
|
563
579
|
*
|
|
564
|
-
* const
|
|
580
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
565
581
|
*
|
|
566
|
-
* console.log(
|
|
567
|
-
* console.log(
|
|
582
|
+
* console.log( lswitch.has_state('off') ); // true
|
|
583
|
+
* console.log( lswitch.has_state('dance') ); // false
|
|
568
584
|
* ```
|
|
569
585
|
*
|
|
570
586
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -1155,7 +1171,7 @@ declare class Machine<mDT> {
|
|
|
1155
1171
|
* ```typescript
|
|
1156
1172
|
* import * as jssm from 'jssm';
|
|
1157
1173
|
*
|
|
1158
|
-
* const
|
|
1174
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
1159
1175
|
* ```
|
|
1160
1176
|
*
|
|
1161
1177
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -1178,7 +1194,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
|
|
|
1178
1194
|
* ```typescript
|
|
1179
1195
|
* import * as jssm from 'jssm';
|
|
1180
1196
|
*
|
|
1181
|
-
* const
|
|
1197
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
1182
1198
|
* ```
|
|
1183
1199
|
*
|
|
1184
1200
|
* @typeparam mDT The type of the machine data member; usually omitted
|
package/dist/es6/jssm.js
CHANGED
|
@@ -272,7 +272,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
|
|
|
272
272
|
* ```typescript
|
|
273
273
|
* import { sm } from 'jssm';
|
|
274
274
|
*
|
|
275
|
-
* const
|
|
275
|
+
* const lswitch = sm`on <=> off;`;
|
|
276
276
|
* ```
|
|
277
277
|
*
|
|
278
278
|
* Method {@link from}:
|
|
@@ -424,7 +424,7 @@ function compile_rule_handler(rule) {
|
|
|
424
424
|
* ```typescript
|
|
425
425
|
* import { sm } from 'jssm';
|
|
426
426
|
*
|
|
427
|
-
* const
|
|
427
|
+
* const lswitch = sm`on <=> off;`;
|
|
428
428
|
* ```
|
|
429
429
|
*
|
|
430
430
|
* Method {@link from}:
|
|
@@ -574,6 +574,9 @@ function transfer_state_properties(state_decl) {
|
|
|
574
574
|
case 'background-color':
|
|
575
575
|
state_decl.backgroundColor = d.value;
|
|
576
576
|
break;
|
|
577
|
+
case 'state-label':
|
|
578
|
+
state_decl.stateLabel = d.value;
|
|
579
|
+
break;
|
|
577
580
|
case 'border-color':
|
|
578
581
|
state_decl.borderColor = d.value;
|
|
579
582
|
break;
|
|
@@ -629,6 +632,12 @@ function state_style_condense(jssk) {
|
|
|
629
632
|
}
|
|
630
633
|
state_style.backgroundColor = key.value;
|
|
631
634
|
break;
|
|
635
|
+
case 'state-label':
|
|
636
|
+
if (state_style.stateLabel !== undefined) {
|
|
637
|
+
throw new JssmError(this, `cannot redefine 'state-label' in state_style_condense, already defined`);
|
|
638
|
+
}
|
|
639
|
+
state_style.stateLabel = key.value;
|
|
640
|
+
break;
|
|
632
641
|
case 'border-color':
|
|
633
642
|
if (state_style.borderColor !== undefined) {
|
|
634
643
|
throw new JssmError(this, `cannot redefine 'border-color' in state_style_condense, already defined`);
|
|
@@ -731,6 +740,8 @@ class Machine {
|
|
|
731
740
|
this._end_state_style = state_style_condense(default_end_state_config);
|
|
732
741
|
this._history_length = history || 0;
|
|
733
742
|
this._history = new circular_buffer(this._history_length);
|
|
743
|
+
this._state_labels = new Map();
|
|
744
|
+
// consolidate the state declarations
|
|
734
745
|
if (state_declaration) {
|
|
735
746
|
state_declaration.map((state_decl) => {
|
|
736
747
|
if (this._state_declarations.has(state_decl.state)) { // no repeats
|
|
@@ -739,6 +750,17 @@ class Machine {
|
|
|
739
750
|
this._state_declarations.set(state_decl.state, transfer_state_properties(state_decl));
|
|
740
751
|
});
|
|
741
752
|
}
|
|
753
|
+
// walk the decls for labels; aggregate them when found
|
|
754
|
+
[...this._state_declarations].map(sd => {
|
|
755
|
+
const [key, decl] = sd, labelled = decl.declarations.filter(d => d.key === 'state-label');
|
|
756
|
+
if (labelled.length > 1) {
|
|
757
|
+
throw new JssmError(this, `state ${key} may only have one state-label; has ${labelled.length}`);
|
|
758
|
+
}
|
|
759
|
+
if (labelled.length === 1) {
|
|
760
|
+
this._state_labels.set(key, labelled[0].value);
|
|
761
|
+
}
|
|
762
|
+
});
|
|
763
|
+
// walk the transitions
|
|
742
764
|
transitions.map((tr) => {
|
|
743
765
|
if (tr.from === undefined) {
|
|
744
766
|
throw new JssmError(this, `transition must define 'from': ${JSON.stringify(tr)}`);
|
|
@@ -890,11 +912,11 @@ class Machine {
|
|
|
890
912
|
* ```typescript
|
|
891
913
|
* import * as jssm from 'jssm';
|
|
892
914
|
*
|
|
893
|
-
* const
|
|
894
|
-
* console.log(
|
|
915
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
916
|
+
* console.log( lswitch.state() ); // 'on'
|
|
895
917
|
*
|
|
896
|
-
*
|
|
897
|
-
* console.log(
|
|
918
|
+
* lswitch.transition('off');
|
|
919
|
+
* console.log( lswitch.state() ); // 'off'
|
|
898
920
|
* ```
|
|
899
921
|
*
|
|
900
922
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -903,13 +925,23 @@ class Machine {
|
|
|
903
925
|
state() {
|
|
904
926
|
return this._state;
|
|
905
927
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
928
|
+
/*********
|
|
929
|
+
*
|
|
930
|
+
* Get the label for a given state, if any; return `undefined` otherwise.
|
|
931
|
+
*
|
|
932
|
+
* ```typescript
|
|
933
|
+
* import * as jssm from 'jssm';
|
|
934
|
+
*
|
|
935
|
+
* const lswitch = jssm.from('a -> b; state a: { label: "Foo!"; };');
|
|
936
|
+
* console.log( lswitch.label_for('a') ); // 'Foo!'
|
|
937
|
+
* ```
|
|
938
|
+
*
|
|
939
|
+
* @typeparam mDT The type of the machine data member; usually omitted
|
|
940
|
+
*
|
|
941
|
+
*/
|
|
942
|
+
label_for(state) {
|
|
943
|
+
return this._state_labels.get(state);
|
|
944
|
+
}
|
|
913
945
|
/*********
|
|
914
946
|
*
|
|
915
947
|
* Get the current data of a machine.
|
|
@@ -917,8 +949,8 @@ class Machine {
|
|
|
917
949
|
* ```typescript
|
|
918
950
|
* import * as jssm from 'jssm';
|
|
919
951
|
*
|
|
920
|
-
* const
|
|
921
|
-
* console.log(
|
|
952
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
953
|
+
* console.log( lswitch.data() ); // 1
|
|
922
954
|
* ```
|
|
923
955
|
*
|
|
924
956
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -927,13 +959,6 @@ class Machine {
|
|
|
927
959
|
data() {
|
|
928
960
|
return this._data;
|
|
929
961
|
}
|
|
930
|
-
/* whargarbl todo major
|
|
931
|
-
when we reimplement this, reintroduce this change to the is_final call
|
|
932
|
-
|
|
933
|
-
is_changing(): boolean {
|
|
934
|
-
return true; // todo whargarbl
|
|
935
|
-
}
|
|
936
|
-
*/
|
|
937
962
|
// NEEDS_DOCS
|
|
938
963
|
/*********
|
|
939
964
|
*
|
|
@@ -1273,8 +1298,8 @@ class Machine {
|
|
|
1273
1298
|
* ```typescript
|
|
1274
1299
|
* import * as jssm from 'jssm';
|
|
1275
1300
|
*
|
|
1276
|
-
* const
|
|
1277
|
-
* console.log(
|
|
1301
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
1302
|
+
* console.log( lswitch.states() ); // ['on', 'off']
|
|
1278
1303
|
* ```
|
|
1279
1304
|
*
|
|
1280
1305
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -1299,10 +1324,10 @@ class Machine {
|
|
|
1299
1324
|
* ```typescript
|
|
1300
1325
|
* import * as jssm from 'jssm';
|
|
1301
1326
|
*
|
|
1302
|
-
* const
|
|
1327
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
1303
1328
|
*
|
|
1304
|
-
* console.log(
|
|
1305
|
-
* console.log(
|
|
1329
|
+
* console.log( lswitch.has_state('off') ); // true
|
|
1330
|
+
* console.log( lswitch.has_state('dance') ); // false
|
|
1306
1331
|
* ```
|
|
1307
1332
|
*
|
|
1308
1333
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -2543,7 +2568,7 @@ class Machine {
|
|
|
2543
2568
|
* ```typescript
|
|
2544
2569
|
* import * as jssm from 'jssm';
|
|
2545
2570
|
*
|
|
2546
|
-
* const
|
|
2571
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
2547
2572
|
* ```
|
|
2548
2573
|
*
|
|
2549
2574
|
* @typeparam mDT The type of the machine data member; usually omitted
|
|
@@ -2578,7 +2603,7 @@ function sm(template_strings, ...remainder /* , arguments */) {
|
|
|
2578
2603
|
* ```typescript
|
|
2579
2604
|
* import * as jssm from 'jssm';
|
|
2580
2605
|
*
|
|
2581
|
-
* const
|
|
2606
|
+
* const lswitch = jssm.from('on <=> off;');
|
|
2582
2607
|
* ```
|
|
2583
2608
|
*
|
|
2584
2609
|
* @typeparam mDT The type of the machine data member; usually omitted
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ declare type JssmStateDeclaration = {
|
|
|
106
106
|
color?: JssmColor;
|
|
107
107
|
corners?: JssmCorner;
|
|
108
108
|
lineStyle?: JssmLineStyle;
|
|
109
|
+
stateLabel?: string;
|
|
109
110
|
textColor?: JssmColor;
|
|
110
111
|
backgroundColor?: JssmColor;
|
|
111
112
|
borderColor?: JssmColor;
|
|
@@ -136,6 +137,10 @@ declare type JssmStateStyleLineStyle = {
|
|
|
136
137
|
key: 'line-style';
|
|
137
138
|
value: JssmLineStyle;
|
|
138
139
|
};
|
|
140
|
+
declare type JssmStateStyleStateLabel = {
|
|
141
|
+
key: 'state-label';
|
|
142
|
+
value: string;
|
|
143
|
+
};
|
|
139
144
|
declare type JssmStateStyleBackgroundColor = {
|
|
140
145
|
key: 'background-color';
|
|
141
146
|
value: JssmColor;
|
|
@@ -144,7 +149,7 @@ declare type JssmStateStyleBorderColor = {
|
|
|
144
149
|
key: 'border-color';
|
|
145
150
|
value: JssmColor;
|
|
146
151
|
};
|
|
147
|
-
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleBorderColor;
|
|
152
|
+
declare type JssmStateStyleKey = JssmStateStyleShape | JssmStateStyleColor | JssmStateStyleTextColor | JssmStateStyleCorners | JssmStateStyleLineStyle | JssmStateStyleBackgroundColor | JssmStateStyleStateLabel | JssmStateStyleBorderColor;
|
|
148
153
|
declare type JssmStateStyleKeyList = JssmStateStyleKey[];
|
|
149
154
|
declare type JssmGenericConfig<DataType> = {
|
|
150
155
|
graph_layout?: JssmLayout;
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.81.0";
|
|
2
2
|
export { version };
|