Skip to content

Commit

Permalink
0.9.3. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Sep 25, 2023
1 parent bb2a228 commit 2f11515
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.3

Added `hasVariable` and `hasVariables` methods to the `PropertyValidatorContext` class.

## 0.9.2

This version fixes a bug in the `ValueEditorFactoryResolver` class. Now, when an editor is not found, the resolver throws an error.
Expand Down
6 changes: 3 additions & 3 deletions demos/webpack-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"dependencies": {
"xstate": "^4.38.2",
"sequential-workflow-model": "^0.2.0",
"sequential-workflow-designer": "^0.16.0",
"sequential-workflow-designer": "^0.16.1",
"sequential-workflow-machine": "^0.4.0",
"sequential-workflow-editor-model": "^0.9.2",
"sequential-workflow-editor": "^0.9.2"
"sequential-workflow-editor-model": "^0.9.3",
"sequential-workflow-editor": "^0.9.3"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAtomActivity } from 'sequential-workflow-machine';
import { GlobalState } from '../global-state';
import { SetStringValueStep } from '../../model/set-string-value-step-model';
import { TextVariableParser } from '../../utilities/text-variable-parser';

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

const value = $dynamics.readString(step.properties.value);
let value = $dynamics.readString(step.properties.value);

value = TextVariableParser.replace(value, variableName => {
return String($variables.read(variableName));
});

$variables.set(step.properties.variable.name, value);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createStringValueModel
} from 'sequential-workflow-editor-model';
import { Step } from 'sequential-workflow-model';
import { TextVariableParser } from '../utilities/text-variable-parser';

export interface SetStringValueStep extends Step {
type: 'setStringValue';
Expand Down Expand Up @@ -43,5 +44,18 @@ export const setStringValueStepModel = createStepModel<SetStringValueStep>('setS
]
})
)
.label('Value');
.label('Value')
.validator({
validate(context) {
const value = context.getValue();
if (value.modelId === 'string') {
const variables = TextVariableParser.parse(value.value as string);
const notFoundIndex = context.hasVariables(variables).findIndex(v => !v);
if (notFoundIndex >= 0) {
return `Variable $${variables[notFoundIndex]} is not defined`;
}
}
return null;
}
});
});
14 changes: 14 additions & 0 deletions demos/webpack-app/src/playground/utilities/text-variable-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const regexp = /\$[A-Za-z][a-zA-Z_0-9-]*/g;

export class TextVariableParser {
public static parse(text: string): string[] {
return (text.match(regexp) || []).map(v => v.substring(1));
}

public static replace(text: string, valueProvider: (variableName: string) => string): string {
return text.replace(regexp, v => {
const variableName = v.substring(1);
return valueProvider(variableName);
});
}
}
6 changes: 3 additions & 3 deletions editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor",
"version": "0.9.2",
"version": "0.9.3",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -46,11 +46,11 @@
"prettier:fix": "prettier --write ./src ./css"
},
"dependencies": {
"sequential-workflow-editor-model": "^0.9.2",
"sequential-workflow-editor-model": "^0.9.3",
"sequential-workflow-model": "^0.2.0"
},
"peerDependencies": {
"sequential-workflow-editor-model": "^0.9.2",
"sequential-workflow-editor-model": "^0.9.3",
"sequential-workflow-model": "^0.2.0"
},
"devDependencies": {
Expand Down
14 changes: 13 additions & 1 deletion editor/src/property-editor/property-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export class PropertyEditor implements Component {
view.appendChild(validationError.view);
}

return new PropertyEditor(view, valueContext.onValueChanged, valueEditor, validationError);
const editor = new PropertyEditor(view, valueContext.onValueChanged, valueEditor, validationError);
if (propertyModel.validator) {
valueContext.onValueChanged.subscribe(editor.onValueChangedHandler);
}
return editor;
}

public constructor(
Expand All @@ -83,8 +87,16 @@ export class PropertyEditor implements Component {
if (this.valueEditor.reloadDependencies) {
this.valueEditor.reloadDependencies();
}
this.revalidate();
}

private revalidate() {
if (this.validationError) {
this.validationError.validate();
}
}

private readonly onValueChangedHandler = () => {
this.revalidate();
};
}
2 changes: 1 addition & 1 deletion model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor-model",
"version": "0.9.2",
"version": "0.9.3",
"homepage": "https://nocode-js.com/",
"author": {
"name": "NoCode JS",
Expand Down
10 changes: 10 additions & 0 deletions model/src/validator/property-validator-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export class PropertyValidatorContext<TValue extends PropertyValue = PropertyVal
public getPropertyValue<Key extends keyof TProperties>(name: Key): TProperties[Key] {
return readPropertyValue(name, this.model, this.definitionContext.object);
}

public hasVariable(name: string): boolean {
return this.hasVariables([name])[0];
}

public hasVariables(names: string[]): boolean[] {
const variables = this.definitionContext.parentsProvider.getVariables();
const variableNames = new Set(variables.map(v => v.name));
return names.map(name => variableNames.has(name));
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5163,10 +5163,10 @@ semver@^7.3.4, semver@^7.3.7, semver@^7.3.8:
dependencies:
lru-cache "^6.0.0"

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

Expand Down

0 comments on commit 2f11515

Please sign in to comment.