Skip to content

Commit 6c316c7

Browse files
authored
0.11.0. (#26)
1 parent 0124d4e commit 6c316c7

23 files changed

+165
-130
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.11.0
2+
3+
This version normalizes names of functions in `ValueContext` and `PropertyValidatorContext` classes.
4+
5+
The `CustomValidatorContext` class is deleted now, please use the `PropertyValidatorContext` class instead.
6+
7+
The `PropertyModelBuilder` class has deleted the `customValidator` function, please use the `validator` function instead.
8+
19
## 0.10.0
210

311
This version deletes all deprecated `*ValueModel` functions. From now, use only `create*ValueModel` functions.

demos/webpack-app/package.json

Lines changed: 2 additions & 2 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.16.1",
2020
"sequential-workflow-machine": "^0.4.0",
21-
"sequential-workflow-editor-model": "^0.10.0",
22-
"sequential-workflow-editor": "^0.10.0"
21+
"sequential-workflow-editor-model": "^0.11.0",
22+
"sequential-workflow-editor": "^0.11.0"
2323
},
2424
"devDependencies": {
2525
"ts-loader": "^9.4.2",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export const setStringValueStepModel = createStepModel<SetStringValueStep>('setS
4949
validate(context) {
5050
const value = context.getValue();
5151
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`;
52+
const variableNames = TextVariableParser.parse(value.value as string);
53+
const undefinedVariableName = context.findFirstUndefinedVariable(variableNames);
54+
if (undefinedVariableName) {
55+
return `Variable $${undefinedVariableName} is not defined`;
5656
}
5757
}
5858
return null;

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

editor/src/components/dynamic-list-component.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { Html } from '../core/html';
33
import { Component } from './component';
44
import { validationErrorComponent } from './validation-error-component';
55

6-
export interface DynamicListComponent<TItem> extends Component {
6+
export interface DynamicListComponent<TItem, TItemComponent extends DynamicListItemComponent<TItem> = DynamicListItemComponent<TItem>>
7+
extends Component {
78
onChanged: SimpleEvent<TItem[]>;
89
add(item: TItem): void;
10+
forEach(callback: (component: TItemComponent) => void): void;
911
}
1012

1113
export interface DynamicListComponentConfiguration<TItem> {
@@ -19,12 +21,12 @@ export interface DynamicListItemComponent<TItem> extends Component {
1921
validate(error: string | null): void;
2022
}
2123

22-
export function dynamicListComponent<TItem>(
24+
export function dynamicListComponent<TItem, TItemComponent extends DynamicListItemComponent<TItem> = DynamicListItemComponent<TItem>>(
2325
initialItems: TItem[],
24-
itemComponentFactory: (item: TItem) => DynamicListItemComponent<TItem>,
26+
itemComponentFactory: (item: TItem) => TItemComponent,
2527
context: ValueContext,
2628
configuration?: DynamicListComponentConfiguration<TItem>
27-
): DynamicListComponent<TItem> {
29+
): DynamicListComponent<TItem, TItemComponent> {
2830
const onChanged = new SimpleEvent<TItem[]>();
2931
const items = [...initialItems];
3032

@@ -58,6 +60,10 @@ export function dynamicListComponent<TItem>(
5860
reloadList();
5961
}
6062

63+
function forEach(callback: (component: TItemComponent) => void) {
64+
components.forEach(callback);
65+
}
66+
6167
function reloadList() {
6268
if (emptyRow) {
6369
view.removeChild(emptyRow);
@@ -99,13 +105,14 @@ export function dynamicListComponent<TItem>(
99105
const validation = validationErrorComponent();
100106
view.appendChild(validation.view);
101107

102-
const components: DynamicListItemComponent<TItem>[] = [];
108+
const components: TItemComponent[] = [];
103109

104110
reloadList();
105111

106112
return {
107113
onChanged,
108114
view,
109-
add
115+
add,
116+
forEach
110117
};
111118
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class PropertyEditor implements Component {
1919
definitionContext: DefinitionContext,
2020
editorServices: EditorServices
2121
): PropertyEditor {
22-
const valueContext = ValueContext.create(propertyModel.value, propertyModel, definitionContext);
22+
const valueContext = ValueContext.createFromDefinitionContext(propertyModel.value, propertyModel, definitionContext);
2323
const valueEditorFactory = editorServices.valueEditorFactoryResolver.resolve(propertyModel.value.id, propertyModel.value.editorId);
2424
const valueEditor = valueEditorFactory(valueContext, editorServices);
2525
let hint: PropertyHintComponent | null = null;
@@ -64,7 +64,8 @@ export class PropertyEditor implements Component {
6464

6565
let validationError: PropertyValidationErrorComponent | null = null;
6666
if (propertyModel.validator) {
67-
const validatorContext = PropertyValidatorContext.create(propertyModel, definitionContext);
67+
const valueContext = ValueContext.createFromDefinitionContext(propertyModel.value, propertyModel, definitionContext);
68+
const validatorContext = PropertyValidatorContext.create(valueContext);
6869
validationError = propertyValidationErrorComponent(propertyModel.validator, validatorContext);
6970
view.appendChild(validationError.view);
7071
}

editor/src/value-editors/any-variables/any-variable-item-component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { formatVariableNameWithType } from '../../core/variable-name-formatter';
77
import { DynamicListItemComponent } from '../../components/dynamic-list-component';
88
import { Icons } from '../../core/icons';
99

10-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
11-
export interface AnyVariableItemComponent extends DynamicListItemComponent<AnyVariable> {}
10+
export type AnyVariableItemComponent = DynamicListItemComponent<AnyVariable>;
1211

1312
export function anyVariableItemComponent(variable: AnyVariable): AnyVariableItemComponent {
1413
function validate(error: string | null) {

editor/src/value-editors/dynamic/dynamic-value-editor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function dynamicValueEditor(context: ValueContext<DynamicValueModel>, ser
3636

3737
function onTypeChanged() {
3838
const newModel = subModels[subModelSelect.getSelectedIndex()];
39-
const defaultValueContext = DefaultValueContext.createFromValueContext(services.activator, context);
39+
const defaultValueContext = DefaultValueContext.create(services.activator, context.scopedPropertyContext.propertyContext);
4040
const defaultValue = {
4141
modelId: newModel.id,
4242
value: newModel.getDefaultValue(defaultValueContext)

editor/src/value-editors/string-dictionary/string-dictionary-item-component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { buttonComponent } from '../../components/button-component';
77
import { DynamicListItemComponent } from '../../components/dynamic-list-component';
88
import { Icons } from '../../core/icons';
99

10-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
11-
export interface StringDictionaryItemComponent extends DynamicListItemComponent<StringDictionaryItem> {}
10+
export type StringDictionaryItemComponent = DynamicListItemComponent<StringDictionaryItem>;
1211

1312
export function stringDictionaryItemComponent(item: StringDictionaryItem): StringDictionaryItemComponent {
1413
function validate(error: string | null) {

editor/src/value-editors/variable-definitions/variable-definition-item-component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { Icons } from '../../core/icons';
1010
import { prependedInputComponent } from '../../components/prepended-input-component';
1111
import { inputComponent } from '../../components/input-component';
1212

13-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
14-
export interface VariableDefinitionItemComponent extends DynamicListItemComponent<VariableDefinition> {}
13+
export type VariableDefinitionItemComponent = DynamicListItemComponent<VariableDefinition>;
1514

1615
export function variableDefinitionItemComponent(
1716
variable: VariableDefinition,

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.10.0",
3+
"version": "0.11.0",
44
"homepage": "https://nocode-js.com/",
55
"author": {
66
"name": "NoCode JS",

model/src/activator/model-activator.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Definition, Step } from 'sequential-workflow-model';
22
import { DefinitionModel, PropertyModel, PropertyModels } from '../model';
33
import { UidGenerator } from '../external-types';
44
import { DefaultValueContext } from '../context/default-value-context';
5+
import { PropertyContext } from '../context/property-context';
56

67
export class ModelActivator<TDefinition extends Definition = Definition> {
78
public static create<TDef extends Definition>(
@@ -19,8 +20,9 @@ export class ModelActivator<TDefinition extends Definition = Definition> {
1920
};
2021
this.activatePropertiesInOrder(definition, this.definitionModel.root.properties);
2122

22-
const sequenceValueContext = DefaultValueContext.create(this, definition, this.definitionModel.root.sequence);
23-
const sequence = this.definitionModel.root.sequence.value.getDefaultValue(sequenceValueContext);
23+
const propertyContext = PropertyContext.create(definition, this.definitionModel.root.sequence, this.definitionModel);
24+
const defaultValueContext = DefaultValueContext.create(this, propertyContext);
25+
const sequence = this.definitionModel.root.sequence.value.getDefaultValue(defaultValueContext);
2426
return {
2527
...definition,
2628
sequence
@@ -40,8 +42,9 @@ export class ModelActivator<TDefinition extends Definition = Definition> {
4042
};
4143
this.activatePropertiesInOrder(step, model.properties);
4244

43-
const nameValueContext = DefaultValueContext.create(this, step, model.name);
44-
const name = model.name.value.getDefaultValue(nameValueContext);
45+
const propertyContext = PropertyContext.create(step, model.name, this.definitionModel);
46+
const defaultValueContext = DefaultValueContext.create(this, propertyContext);
47+
const name = model.name.value.getDefaultValue(defaultValueContext);
4548
return {
4649
...step,
4750
name
@@ -65,7 +68,8 @@ export class ModelActivator<TDefinition extends Definition = Definition> {
6568
}
6669

6770
private activateProperty(object: object, model: PropertyModel) {
68-
const defaultValueContext = DefaultValueContext.create(this, object, model);
71+
const propertyContext = PropertyContext.create(object, model, this.definitionModel);
72+
const defaultValueContext = DefaultValueContext.create(this, propertyContext);
6973
const defaultValue = model.value.getDefaultValue(defaultValueContext);
7074
model.value.path.write(object, defaultValue);
7175
}

model/src/builders/property-model-builder.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ export class PropertyModelBuilder<TValue extends PropertyValue = PropertyValue,
8181
return this;
8282
}
8383

84-
/**
85-
* @deprecated Use `validator` instead.
86-
*/
87-
public readonly customValidator = this.validator.bind(this);
88-
8984
public build(): PropertyModel<TValue> {
9085
if (!this._value) {
9186
throw new Error(`Model is not set for ${this.path.toString()}`);
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
import { Properties } from 'sequential-workflow-model';
22
import { ModelActivator } from '../activator';
3-
import { PropertyModel, ValueModel } from '../model';
4-
import { ValueContext } from './value-context';
5-
import { readPropertyValue } from './read-property-value';
3+
import { PropertyContext } from './property-context';
64

75
export class DefaultValueContext<TProperties extends Properties = Properties> {
86
public static create<TProps extends Properties = Properties>(
97
activator: ModelActivator,
10-
object: object,
11-
model: PropertyModel
8+
propertyContext: PropertyContext<TProps>
129
): DefaultValueContext<TProps> {
13-
return new DefaultValueContext<TProps>(activator, name => readPropertyValue(name, model, object));
10+
return new DefaultValueContext<TProps>(activator, propertyContext);
1411
}
1512

16-
public static createFromValueContext<TProps extends Properties = Properties>(
17-
activator: ModelActivator,
18-
valueContext: ValueContext<ValueModel, TProps>
19-
): DefaultValueContext<TProps> {
20-
return new DefaultValueContext(activator, valueContext.getPropertyValue);
21-
}
22-
23-
private constructor(
24-
private readonly activator: ModelActivator,
25-
public readonly getPropertyValue: <Key extends keyof TProperties>(name: Key) => TProperties[Key]
26-
) {}
13+
private constructor(private readonly activator: ModelActivator, public readonly propertyContext: PropertyContext<TProperties>) {}
2714

15+
public readonly getPropertyValue = this.propertyContext.getPropertyValue;
2816
public readonly activateStep = this.activator.activateStep;
2917
}

model/src/context/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export * from './default-value-context';
2+
export * from './property-context';
3+
export * from './scoped-property-context';
24
export * from './value-context';
35
export * from './definition-context';

model/src/context/property-context.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Properties } from 'sequential-workflow-model';
2+
import { DefinitionModel, PropertyModel } from '../model';
3+
import { ValueType } from '../types';
4+
import { readPropertyValue } from './read-property-value';
5+
6+
export class PropertyContext<TProperties extends Properties = Properties> {
7+
public static create<TProps extends Properties = Properties>(
8+
object: object,
9+
propertyModel: PropertyModel,
10+
definitionModel: DefinitionModel
11+
): PropertyContext<TProps> {
12+
return new PropertyContext<TProps>(object, propertyModel, definitionModel);
13+
}
14+
15+
private constructor(
16+
public readonly object: object,
17+
private readonly propertyModel: PropertyModel,
18+
private readonly definitionModel: DefinitionModel
19+
) {}
20+
21+
public readonly getPropertyValue = <Key extends keyof TProperties>(name: Key): TProperties[Key] => {
22+
return readPropertyValue(name, this.propertyModel, this.object);
23+
};
24+
25+
public readonly getValueTypes = (): ValueType[] => {
26+
return this.definitionModel.valueTypes;
27+
};
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Properties } from 'sequential-workflow-model';
2+
import { ContextVariable } from '../model';
3+
import { ParentsProvider } from './variables-provider';
4+
import { PropertyContext } from './property-context';
5+
6+
export class ScopedPropertyContext<TProperties extends Properties> {
7+
public static create<TProps extends Properties>(
8+
propertyContext: PropertyContext<TProps>,
9+
parentsProvider: ParentsProvider
10+
): ScopedPropertyContext<TProps> {
11+
return new ScopedPropertyContext<TProps>(propertyContext, parentsProvider);
12+
}
13+
14+
private constructor(public readonly propertyContext: PropertyContext<TProperties>, private readonly parentsProvider: ParentsProvider) {}
15+
16+
public readonly getPropertyValue = this.propertyContext.getPropertyValue;
17+
public readonly getValueTypes = this.propertyContext.getValueTypes;
18+
19+
public readonly hasVariable = (variableName: string, valueType: string | null): boolean => {
20+
return this.getVariables().some(v => v.name === variableName && (valueType === null || v.type === valueType));
21+
};
22+
23+
public readonly findFirstUndefinedVariable = (variableNames: string[]): string | undefined => {
24+
const variables = new Set(this.getVariables().map(v => v.name));
25+
return variableNames.find(name => !variables.has(name));
26+
};
27+
28+
public readonly isVariableDuplicated = (variableName: string): boolean => {
29+
return this.getVariables().filter(v => v.name === variableName).length > 1;
30+
};
31+
32+
public readonly getVariables = (): ContextVariable[] => {
33+
return this.parentsProvider.getVariables();
34+
};
35+
}

0 commit comments

Comments
 (0)