Skip to content

Commit dfef511

Browse files
authoredJun 12, 2023
0.3.1. (#7)
1 parent a0697d6 commit dfef511

20 files changed

+180
-32
lines changed
 

Diff for: ‎CHANGELOG.md

+4
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.

Diff for: ‎demos/webpack-app/package.json

+3-3
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+
}

Diff for: ‎demos/webpack-app/src/playground/default-state.ts

+2-2
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: {

Diff for: ‎demos/webpack-app/src/playground/machine/activities/if-activity.ts

+9-4
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;

Diff for: ‎demos/webpack-app/src/playground/machine/activities/log-activity.ts

+1-1
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>';

Diff for: ‎demos/webpack-app/src/playground/machine/services/dynamics-service.ts

+9-4
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 {

Diff for: ‎demos/webpack-app/src/playground/model/if-step-model.ts

+14-12
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({

Diff for: ‎demos/webpack-app/src/playground/storage.ts

+1-1
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

Diff for: ‎editor/package.json

+3-3
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": {
+38
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+
}

Diff for: ‎editor/src/value-editors/value-editor-factory-resolver.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import { dynamicValueEditor, dynamicValueEditorId } from './dynamic/dynamic-valu
1212
import { choiceValueEditor, choiceValueEditorId } from './choice/choice-value-editor';
1313
import { branchesValueModelId, sequenceValueModelId } from 'sequential-workflow-editor-model';
1414
import { nullableAnyVariableValueEditor, nullableAnyVariableValueEditorId } from './nullable-any-variable/nullable-any-variable-editor';
15+
import { booleanValueEditor, booleanValueEditorId } from './boolean/boolean-value-editor';
1516

1617
const editors: { id: string; factory: ValueEditorFactory | null }[] = [
1718
{ id: anyVariablesValueEditorId, factory: anyVariablesValueEditor as ValueEditorFactory },
19+
{ id: booleanValueEditorId, factory: booleanValueEditor as ValueEditorFactory },
1820
{ id: choiceValueEditorId, factory: choiceValueEditor as ValueEditorFactory },
1921
{ id: nullableAnyVariableValueEditorId, factory: nullableAnyVariableValueEditor as ValueEditorFactory },
2022
{ id: dynamicValueEditorId, factory: dynamicValueEditor as ValueEditorFactory },

Diff for: ‎model/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor-model",
3-
"version": "0.3.0",
3+
"version": "0.3.1",
44
"homepage": "https://nocode-js.com/",
55
"author": {
66
"name": "NoCode JS",

Diff for: ‎model/src/test-tools/definition-model-stub.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Path } from '../core';
2+
import { DefinitionModel } from '../model';
3+
4+
export function createDefinitionModelStub(): DefinitionModel {
5+
return {
6+
root: {
7+
properties: [],
8+
sequence: {
9+
dependencies: [],
10+
name: 'stub',
11+
label: 'Stub sequence',
12+
value: {
13+
id: 'stub',
14+
label: 'Stub',
15+
path: Path.create(['sequence']),
16+
configuration: {},
17+
getDefaultValue: () => [],
18+
getVariableDefinitions: () => null,
19+
validate: () => null
20+
}
21+
}
22+
},
23+
steps: {},
24+
valueTypes: []
25+
};
26+
}

Diff for: ‎model/src/test-tools/model-activator-stub.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { ModelActivator } from '../activator';
2+
import { createDefinitionModelStub } from './definition-model-stub';
3+
4+
export function createModelActivatorStub(): ModelActivator {
5+
let index = 0;
6+
return ModelActivator.create(createDefinitionModelStub(), () => `0x${index++}`);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface BooleanValueModelConfiguration {
2+
defaultValue?: boolean;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Path } from '../../core';
2+
import { createModelActivatorStub } from '../../test-tools/model-activator-stub';
3+
import { booleanValueModel } from './boolean-value-model';
4+
import { BooleanValueModelConfiguration } from './boolean-value-model-configuration';
5+
6+
describe('booleanValueModel', () => {
7+
const modelActivator = createModelActivatorStub();
8+
9+
function getModel(configuration: BooleanValueModelConfiguration) {
10+
return booleanValueModel(configuration)(Path.create('test'));
11+
}
12+
13+
describe('getDefaultValue()', () => {
14+
it('returns false as default', () => {
15+
const value = getModel({}).getDefaultValue(modelActivator);
16+
17+
expect(value).toBe(false);
18+
});
19+
20+
it('returns the configured default value', () => {
21+
const valueTrue = getModel({ defaultValue: true }).getDefaultValue(modelActivator);
22+
expect(valueTrue).toBe(true);
23+
24+
const valueFalse = getModel({ defaultValue: false }).getDefaultValue(modelActivator);
25+
expect(valueFalse).toBe(false);
26+
});
27+
});
28+
});
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { ValueModel, ValueModelFactory } from '../../model';
2+
import { Path } from '../../core/path';
3+
import { BooleanValueModelConfiguration } from './boolean-value-model-configuration';
4+
5+
export type BooleanValueModel = ValueModel<boolean, BooleanValueModelConfiguration>;
6+
7+
export const booleanValueModelId = 'boolean';
8+
9+
export function booleanValueModel(configuration: BooleanValueModelConfiguration): ValueModelFactory<BooleanValueModel> {
10+
return (path: Path) => ({
11+
id: booleanValueModelId,
12+
label: 'Boolean',
13+
path,
14+
configuration,
15+
getDefaultValue() {
16+
if (configuration.defaultValue !== undefined) {
17+
return configuration.defaultValue;
18+
}
19+
return false;
20+
},
21+
getVariableDefinitions: () => null,
22+
validate: () => null
23+
});
24+
}

Diff for: ‎model/src/value-models/boolean/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './boolean-value-model-configuration';
2+
export * from './boolean-value-model';

Diff for: ‎model/src/value-models/dynamic/dynamic-value-model.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export function dynamicValueModel<TValueModelFactory extends ValueModelFactory[]
4949
const value = context.getValue();
5050
const model = subModels.find(m => m.id === value.modelId);
5151
if (!model) {
52-
throw new Error(`Cannot find model id: ${value.modelId}`);
52+
const availableModels = subModels.map(m => m.id).join(', ');
53+
throw new Error(`Cannot find sub model id: ${value.modelId} (available: ${availableModels})`);
5354
}
5455
const childContext = context.createChildContext(model);
5556
return model.validate(childContext);

Diff for: ‎model/src/value-models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './any-variables';
2+
export * from './boolean';
23
export * from './branches';
34
export * from './choice';
45
export * from './dynamic';

0 commit comments

Comments
 (0)
Please sign in to comment.