Skip to content

Commit dfef511

Browse files
authored
0.3.1. (#7)
1 parent a0697d6 commit dfef511

20 files changed

+180
-32
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.3.1
2+
3+
Added new value model: boolean (`booleanValueModel({ ... })`).
4+
15
## 0.3.0
26

37
* Added new value model: nullable any variable (`nullableAnyVariableValueModel({ ... })`). This value model allows you to select any variable. Additionally, you can specify a variable type that can be selected by a user.

demos/webpack-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"sequential-workflow-model": "^0.1.3",
1919
"sequential-workflow-designer": "^0.13.2",
2020
"sequential-workflow-machine": "^0.2.0",
21-
"sequential-workflow-editor-model": "^0.3.0",
22-
"sequential-workflow-editor": "^0.3.0"
21+
"sequential-workflow-editor-model": "^0.3.1",
22+
"sequential-workflow-editor": "^0.3.1"
2323
},
2424
"devDependencies": {
2525
"ts-loader": "^9.4.2",
@@ -33,4 +33,4 @@
3333
"@typescript-eslint/parser": "^5.47.0",
3434
"eslint": "^8.30.0"
3535
}
36-
}
36+
}

demos/webpack-app/src/playground/default-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const definition: MyDefinition = {
4141
type: 'if',
4242
componentType: 'switch',
4343
properties: {
44-
a: { modelId: 'nullableVariable', value: { name: 'remainder' } },
45-
operator: '=',
44+
a: { modelId: 'nullableAnyVariable', value: { name: 'remainder', type: 'number' } },
45+
operator: '==',
4646
b: { modelId: 'number', value: 0 }
4747
},
4848
branches: {

demos/webpack-app/src/playground/machine/activities/if-activity.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { branchName, createForkActivity } from 'sequential-workflow-machine';
23
import { IfStep } from '../../model/if-step-model';
34
import { GlobalState } from '../global-state';
@@ -6,19 +7,23 @@ export const ifActivity = createForkActivity<IfStep, GlobalState>({
67
stepType: 'if',
78
init: () => ({}),
89
handler: async (step: IfStep, { $dynamics }: GlobalState) => {
9-
const a = $dynamics.readNumber(step.properties.a);
10-
const b = $dynamics.readNumber(step.properties.b);
10+
const a = $dynamics.readAny<any>(step.properties.a);
11+
const b = $dynamics.readAny<any>(step.properties.b);
1112

1213
const result = compare(a, b, step.properties.operator);
1314
return branchName(result ? 'true' : 'false');
1415
}
1516
});
1617

17-
function compare(a: number, b: number, operator: string): boolean {
18+
function compare(a: any, b: any, operator: string): boolean {
1819
switch (operator) {
19-
case '=':
20+
case '==':
21+
return a == b;
22+
case '===':
2023
return a === b;
2124
case '!=':
25+
return a != b;
26+
case '!==':
2227
return a !== b;
2328
case '>':
2429
return a > b;

demos/webpack-app/src/playground/machine/activities/log-activity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const logActivity = createAtomActivity<LogStep, GlobalState>({
77
init: () => ({}),
88
stepType: 'log',
99
handler: async (step: LogStep, { $variables, $dynamics, $logger }: GlobalState) => {
10-
let message = $dynamics.readAny(step.properties.message);
10+
let message = $dynamics.readString(step.properties.message);
1111

1212
for (const variable of step.properties.variables.variables) {
1313
const value = $variables.isSet(variable.name) ? $variables.read(variable.name) || '<empty>' : '<not set>';

demos/webpack-app/src/playground/machine/services/dynamics-service.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {
22
Dynamic,
3+
NullableAnyVariable,
34
NullableVariable,
5+
booleanValueModelId,
6+
nullableAnyVariableValueModelId,
47
nullableVariableValueModelId,
58
numberValueModelId,
69
stringValueModelId
@@ -10,20 +13,22 @@ import { VariablesService } from './variables-service';
1013
export class DynamicsService {
1114
public constructor(private readonly $variables: VariablesService) {}
1215

13-
public readAny<TValue>(dynamic: Dynamic<TValue | NullableVariable>): TValue {
16+
public readAny<TValue>(dynamic: Dynamic<unknown>): TValue {
1417
switch (dynamic.modelId) {
1518
case stringValueModelId:
1619
case numberValueModelId:
20+
case booleanValueModelId:
1721
return dynamic.value as TValue;
18-
case nullableVariableValueModelId: {
19-
const variable = dynamic.value as NullableVariable;
22+
case nullableVariableValueModelId:
23+
case nullableAnyVariableValueModelId: {
24+
const variable = dynamic.value as NullableVariable | NullableAnyVariable;
2025
if (!variable || !variable.name) {
2126
throw new Error('Variable is not set');
2227
}
2328
return this.$variables.read<TValue>(variable.name);
2429
}
2530
}
26-
throw new Error(`Model is not supported: ${dynamic.modelId}`);
31+
throw new Error(`Dynamic model is not supported: ${dynamic.modelId}`);
2732
}
2833

2934
public readString(dynamic: Dynamic<string | NullableVariable>): string {

demos/webpack-app/src/playground/model/if-step-model.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
11
import {
22
Dynamic,
33
NullableVariable,
4-
ValueKnownType,
4+
booleanValueModel,
55
branchesValueModel,
66
choiceValueModel,
77
createBranchedStepModel,
88
dynamicValueModel,
9-
nullableVariableValueModel,
10-
numberValueModel
9+
nullableAnyVariableValueModel,
10+
numberValueModel,
11+
stringValueModel
1112
} from 'sequential-workflow-editor-model';
1213
import { BranchedStep } from 'sequential-workflow-model';
1314

1415
export interface IfStep extends BranchedStep {
1516
type: 'if';
1617
componentType: 'switch';
1718
properties: {
18-
a: Dynamic<number | NullableVariable>;
19+
a: Dynamic<number | string | boolean | NullableVariable>;
1920
operator: string;
20-
b: Dynamic<number | NullableVariable>;
21+
b: Dynamic<number | string | boolean | NullableVariable>;
2122
};
2223
}
2324

2425
export const ifStepModel = createBranchedStepModel<IfStep>('if', 'switch', step => {
25-
const val = dynamicValueModel({
26+
const ab = dynamicValueModel({
2627
models: [
2728
numberValueModel({}),
28-
nullableVariableValueModel({
29-
isRequired: true,
30-
valueType: ValueKnownType.number
29+
stringValueModel({}),
30+
booleanValueModel({}),
31+
nullableAnyVariableValueModel({
32+
isRequired: true
3133
})
3234
]
3335
});
3436

35-
step.property('a').value(val).label('A');
37+
step.property('a').value(ab).label('A');
3638

3739
step.property('operator')
3840
.label('Operator')
3941
.value(
4042
choiceValueModel({
41-
choices: ['=', '!=', '>', '>=', '<', '<=']
43+
choices: ['==', '===', '!=', '!==', '>', '>=', '<', '<=']
4244
})
4345
);
4446

45-
step.property('b').value(val).label('B');
47+
step.property('b').value(ab).label('B');
4648

4749
step.branches().value(
4850
branchesValueModel({

demos/webpack-app/src/playground/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MyDefinition } from './model/definition-model';
22
import { RawInputData } from './playground';
33

4-
const version = 1;
4+
const version = 2;
55
const definitionKey = `definition_${version}`;
66
const inputDataKey = `inputData_${version}`;
77

editor/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"type": "module",
55
"main": "./lib/esm/index.js",
66
"types": "./lib/index.d.ts",
@@ -46,11 +46,11 @@
4646
"prettier:fix": "prettier --write ./src ./css"
4747
},
4848
"dependencies": {
49-
"sequential-workflow-editor-model": "^0.3.0",
49+
"sequential-workflow-editor-model": "^0.3.1",
5050
"sequential-workflow-model": "^0.1.3"
5151
},
5252
"peerDependencies": {
53-
"sequential-workflow-editor-model": "^0.3.0",
53+
"sequential-workflow-editor-model": "^0.3.1",
5454
"sequential-workflow-model": "^0.1.3"
5555
},
5656
"devDependencies": {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { BooleanValueModel, ValueModelContext } from 'sequential-workflow-editor-model';
2+
import { ValueEditor } from '../value-editor';
3+
import { validationErrorComponent } from '../../components/validation-error-component';
4+
import { valueEditorContainerComponent } from '../../components/value-editor-container-component';
5+
import { rowComponent } from '../../components/row-component';
6+
import { selectComponent } from '../../components/select-component';
7+
8+
export const booleanValueEditorId = 'boolean';
9+
10+
export function booleanValueEditor(context: ValueModelContext<BooleanValueModel>): ValueEditor<BooleanValueModel> {
11+
function validate() {
12+
validation.setDefaultError(context.validate());
13+
}
14+
15+
function onSelected(index: number) {
16+
context.setValue(index === 1);
17+
validate();
18+
}
19+
20+
const select = selectComponent({
21+
stretched: true
22+
});
23+
select.setValues(['False', 'True']);
24+
select.selectIndex(context.getValue() ? 1 : 0);
25+
select.onSelected.subscribe(onSelected);
26+
27+
const row = rowComponent([select.view]);
28+
29+
const validation = validationErrorComponent();
30+
const container = valueEditorContainerComponent([row.view, validation.view]);
31+
32+
validate();
33+
34+
return {
35+
view: container.view,
36+
validate
37+
};
38+
}

0 commit comments

Comments
 (0)