Skip to content

Commit eb4bb32

Browse files
authored
0.11.2. (#28)
1 parent ee9035f commit eb4bb32

File tree

9 files changed

+39
-21
lines changed

9 files changed

+39
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.11.2
2+
3+
This version adds a generic type to the `ChoiceValueModel` interface.
4+
15
## 0.11.1
26

37
This version improves support for UMD bundles.

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.2.0",
1919
"sequential-workflow-designer": "^0.17.0",
2020
"sequential-workflow-machine": "^0.4.0",
21-
"sequential-workflow-editor-model": "^0.11.1",
22-
"sequential-workflow-editor": "^0.11.1"
21+
"sequential-workflow-editor-model": "^0.11.2",
22+
"sequential-workflow-editor": "^0.11.2"
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/editors/model/choice-step-model.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ export interface ChoiceStepModel extends Step {
66
componentType: 'task';
77
properties: {
88
minimalConfig: string;
9-
defaultValueGreen: string;
9+
defaultValueAllow: 'allow' | 'ignore' | 'deny';
1010
};
1111
}
1212

1313
export const choiceStepModel = createStepModel<ChoiceStepModel>('choice', 'task', step => {
14-
const choices = ['red', 'blue', 'green'];
14+
step.property('minimalConfig').value(createChoiceValueModel({ choices: ['red', 'blue', 'green'] }));
1515

16-
step.property('minimalConfig').value(createChoiceValueModel({ choices }));
17-
step.property('defaultValueGreen').value(createChoiceValueModel({ choices, defaultValue: 'green' }));
16+
step.property('defaultValueAllow').value(
17+
createChoiceValueModel({
18+
choices: ['allow', 'ignore'],
19+
defaultValue: 'ignore'
20+
})
21+
);
1822
});

editor/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
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.11.1",
49+
"sequential-workflow-editor-model": "^0.11.2",
5050
"sequential-workflow-model": "^0.2.0"
5151
},
5252
"peerDependencies": {
53-
"sequential-workflow-editor-model": "^0.11.1",
53+
"sequential-workflow-editor-model": "^0.11.2",
5454
"sequential-workflow-model": "^0.2.0"
5555
},
5656
"devDependencies": {
@@ -79,4 +79,4 @@
7979
"lowcode",
8080
"flow"
8181
]
82-
}
82+
}

model/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor-model",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"homepage": "https://nocode-js.com/",
55
"author": {
66
"name": "NoCode JS",
@@ -72,4 +72,4 @@
7272
"lowcode",
7373
"flow"
7474
]
75-
}
75+
}

model/src/context/scoped-property-context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Properties } from 'sequential-workflow-model';
22
import { ContextVariable } from '../model';
33
import { ParentsProvider } from './variables-provider';
44
import { PropertyContext } from './property-context';
5+
import { ValueType } from '../types';
56

67
export class ScopedPropertyContext<TProperties extends Properties> {
78
public static create<TProps extends Properties>(
@@ -32,6 +33,11 @@ export class ScopedPropertyContext<TProperties extends Properties> {
3233
return this.getVariables().filter(v => v.name === variableName).length > 1;
3334
};
3435

36+
public readonly tryGetVariableType = (variableName: string): ValueType | null => {
37+
const variable = this.getVariables().find(v => v.name === variableName);
38+
return variable ? variable.type : null;
39+
};
40+
3541
public readonly getVariables = (): ContextVariable[] => {
3642
return this.parentsProvider.getVariables();
3743
};

model/src/context/value-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class ValueContext<TValueModel extends ValueModel = ValueModel, TProperti
2828
public readonly hasVariable = this.scopedPropertyContext.hasVariable;
2929
public readonly findFirstUndefinedVariable = this.scopedPropertyContext.findFirstUndefinedVariable;
3030
public readonly isVariableDuplicated = this.scopedPropertyContext.isVariableDuplicated;
31+
public readonly tryGetVariableType = this.scopedPropertyContext.tryGetVariableType;
3132
public readonly getVariables = this.scopedPropertyContext.getVariables;
3233

3334
public readonly getValue = (): ReturnType<TValueModel['getDefaultValue']> => {

model/src/validator/property-validator-context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class PropertyValidatorContext<TValue extends PropertyValue = PropertyVal
1616
public readonly hasVariable = this.valueContext.hasVariable;
1717
public readonly findFirstUndefinedVariable = this.valueContext.findFirstUndefinedVariable;
1818
public readonly isVariableDuplicated = this.valueContext.isVariableDuplicated;
19+
public readonly tryGetVariableType = this.valueContext.tryGetVariableType;
1920
public readonly getVariables = this.valueContext.getVariables;
2021

2122
public getValue(): TValue {

model/src/value-models/choice/choice-value-model.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
import { ValueModel, ValueModelFactoryFromModel, ValidationResult, createValidationSingleError } from '../../model';
1+
import { ValueModel, ValidationResult, createValidationSingleError, ValueModelFactory } from '../../model';
22
import { Path } from '../../core/path';
33
import { ValueContext } from '../../context';
44

5-
export interface ChoiceValueModelConfiguration {
6-
choices: string[];
7-
defaultValue?: string;
5+
export interface ChoiceValueModelConfiguration<TValue extends string = string> {
6+
choices: TValue[];
7+
defaultValue?: TValue;
88
}
99

10-
export type ChoiceValueModel = ValueModel<string, ChoiceValueModelConfiguration>;
10+
export type ChoiceValueModel<TValue extends string = string> = ValueModel<TValue, ChoiceValueModelConfiguration<TValue>>;
1111

1212
export const choiceValueModelId = 'choice';
1313

14-
export function createChoiceValueModel(configuration: ChoiceValueModelConfiguration): ValueModelFactoryFromModel<ChoiceValueModel> {
14+
export function createChoiceValueModel<TValue extends string>(
15+
configuration: ChoiceValueModelConfiguration<TValue>
16+
): ValueModelFactory<TValue, ChoiceValueModelConfiguration<TValue>> {
1517
if (configuration.choices.length < 1) {
1618
throw new Error('At least one choice must be provided.');
1719
}
@@ -25,14 +27,14 @@ export function createChoiceValueModel(configuration: ChoiceValueModelConfigurat
2527
getDefaultValue() {
2628
if (configuration.defaultValue) {
2729
if (!configuration.choices.includes(configuration.defaultValue)) {
28-
throw new Error('Default value does not match any of the choices.');
30+
throw new Error(`Default value "${configuration.defaultValue}" does not match any of the choices.`);
2931
}
3032
return configuration.defaultValue;
3133
}
3234
return configuration.choices[0];
3335
},
3436
getVariableDefinitions: () => null,
35-
validate(context: ValueContext<ChoiceValueModel>): ValidationResult {
37+
validate(context: ValueContext<ChoiceValueModel<TValue>>): ValidationResult {
3638
const value = context.getValue();
3739
if (!configuration.choices.includes(value)) {
3840
return createValidationSingleError('Choice is not supported.');

0 commit comments

Comments
 (0)