Skip to content

Commit 2f11515

Browse files
authored
0.9.3. (#22)
1 parent bb2a228 commit 2f11515

File tree

10 files changed

+74
-14
lines changed

10 files changed

+74
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.9.3
2+
3+
Added `hasVariable` and `hasVariables` methods to the `PropertyValidatorContext` class.
4+
15
## 0.9.2
26

37
This version fixes a bug in the `ValueEditorFactoryResolver` class. Now, when an editor is not found, the resolver throws an error.

demos/webpack-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"dependencies": {
1717
"xstate": "^4.38.2",
1818
"sequential-workflow-model": "^0.2.0",
19-
"sequential-workflow-designer": "^0.16.0",
19+
"sequential-workflow-designer": "^0.16.1",
2020
"sequential-workflow-machine": "^0.4.0",
21-
"sequential-workflow-editor-model": "^0.9.2",
22-
"sequential-workflow-editor": "^0.9.2"
21+
"sequential-workflow-editor-model": "^0.9.3",
22+
"sequential-workflow-editor": "^0.9.3"
2323
},
2424
"devDependencies": {
2525
"ts-loader": "^9.4.2",
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createAtomActivity } from 'sequential-workflow-machine';
22
import { GlobalState } from '../global-state';
33
import { SetStringValueStep } from '../../model/set-string-value-step-model';
4+
import { TextVariableParser } from '../../utilities/text-variable-parser';
45

56
export const setStringValueActivity = createAtomActivity<SetStringValueStep, GlobalState>('setStringValue', {
67
init: () => ({}),
@@ -9,7 +10,12 @@ export const setStringValueActivity = createAtomActivity<SetStringValueStep, Glo
910
throw new Error('Variable is not set');
1011
}
1112

12-
const value = $dynamics.readString(step.properties.value);
13+
let value = $dynamics.readString(step.properties.value);
14+
15+
value = TextVariableParser.replace(value, variableName => {
16+
return String($variables.read(variableName));
17+
});
18+
1319
$variables.set(step.properties.variable.name, value);
1420
}
1521
});

demos/webpack-app/src/playground/model/set-string-value-step-model.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
createStringValueModel
99
} from 'sequential-workflow-editor-model';
1010
import { Step } from 'sequential-workflow-model';
11+
import { TextVariableParser } from '../utilities/text-variable-parser';
1112

1213
export interface SetStringValueStep extends Step {
1314
type: 'setStringValue';
@@ -43,5 +44,18 @@ export const setStringValueStepModel = createStepModel<SetStringValueStep>('setS
4344
]
4445
})
4546
)
46-
.label('Value');
47+
.label('Value')
48+
.validator({
49+
validate(context) {
50+
const value = context.getValue();
51+
if (value.modelId === 'string') {
52+
const variables = TextVariableParser.parse(value.value as string);
53+
const notFoundIndex = context.hasVariables(variables).findIndex(v => !v);
54+
if (notFoundIndex >= 0) {
55+
return `Variable $${variables[notFoundIndex]} is not defined`;
56+
}
57+
}
58+
return null;
59+
}
60+
});
4761
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const regexp = /\$[A-Za-z][a-zA-Z_0-9-]*/g;
2+
3+
export class TextVariableParser {
4+
public static parse(text: string): string[] {
5+
return (text.match(regexp) || []).map(v => v.substring(1));
6+
}
7+
8+
public static replace(text: string, valueProvider: (variableName: string) => string): string {
9+
return text.replace(regexp, v => {
10+
const variableName = v.substring(1);
11+
return valueProvider(variableName);
12+
});
13+
}
14+
}

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.9.2",
3+
"version": "0.9.3",
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.9.2",
49+
"sequential-workflow-editor-model": "^0.9.3",
5050
"sequential-workflow-model": "^0.2.0"
5151
},
5252
"peerDependencies": {
53-
"sequential-workflow-editor-model": "^0.9.2",
53+
"sequential-workflow-editor-model": "^0.9.3",
5454
"sequential-workflow-model": "^0.2.0"
5555
},
5656
"devDependencies": {

editor/src/property-editor/property-editor.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ export class PropertyEditor implements Component {
6969
view.appendChild(validationError.view);
7070
}
7171

72-
return new PropertyEditor(view, valueContext.onValueChanged, valueEditor, validationError);
72+
const editor = new PropertyEditor(view, valueContext.onValueChanged, valueEditor, validationError);
73+
if (propertyModel.validator) {
74+
valueContext.onValueChanged.subscribe(editor.onValueChangedHandler);
75+
}
76+
return editor;
7377
}
7478

7579
public constructor(
@@ -83,8 +87,16 @@ export class PropertyEditor implements Component {
8387
if (this.valueEditor.reloadDependencies) {
8488
this.valueEditor.reloadDependencies();
8589
}
90+
this.revalidate();
91+
}
92+
93+
private revalidate() {
8694
if (this.validationError) {
8795
this.validationError.validate();
8896
}
8997
}
98+
99+
private readonly onValueChangedHandler = () => {
100+
this.revalidate();
101+
};
90102
}

model/package.json

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ export class PropertyValidatorContext<TValue extends PropertyValue = PropertyVal
2020
public getPropertyValue<Key extends keyof TProperties>(name: Key): TProperties[Key] {
2121
return readPropertyValue(name, this.model, this.definitionContext.object);
2222
}
23+
24+
public hasVariable(name: string): boolean {
25+
return this.hasVariables([name])[0];
26+
}
27+
28+
public hasVariables(names: string[]): boolean[] {
29+
const variables = this.definitionContext.parentsProvider.getVariables();
30+
const variableNames = new Set(variables.map(v => v.name));
31+
return names.map(name => variableNames.has(name));
32+
}
2333
}
2434

2535
/**

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5163,10 +5163,10 @@ semver@^7.3.4, semver@^7.3.7, semver@^7.3.8:
51635163
dependencies:
51645164
lru-cache "^6.0.0"
51655165

5166-
sequential-workflow-designer@^0.16.0:
5167-
version "0.16.0"
5168-
resolved "https://registry.yarnpkg.com/sequential-workflow-designer/-/sequential-workflow-designer-0.16.0.tgz#9771cdb00063e6da395df3d9bc5a280460cf087c"
5169-
integrity sha512-9xWdA3C7dQ/z2O61BNA+8QORFR5WGWT4vX7mTAk5HwTE4YcJ+GI4XTjx+5bE8k2E+PL/QmuvbY8rQBFoV9wXvw==
5166+
sequential-workflow-designer@^0.16.1:
5167+
version "0.16.1"
5168+
resolved "https://registry.yarnpkg.com/sequential-workflow-designer/-/sequential-workflow-designer-0.16.1.tgz#9c70627dab95022f53702d86c4fecbc50cd99a90"
5169+
integrity sha512-YGp6FD9GJmVFWr+d3ztENE72pp5Glvi6CCEVyZtmlghDY8tA+2C0RcHDYAvUeZg4ZIJyN8Y9Dlkzc/5LnJsEdA==
51705170
dependencies:
51715171
sequential-workflow-model "^0.2.0"
51725172

0 commit comments

Comments
 (0)