Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.11.2. #28

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.11.2

This version adds a generic type to the `ChoiceValueModel` interface.

## 0.11.1

This version improves support for UMD bundles.
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 @@ -18,8 +18,8 @@
"sequential-workflow-model": "^0.2.0",
"sequential-workflow-designer": "^0.17.0",
"sequential-workflow-machine": "^0.4.0",
"sequential-workflow-editor-model": "^0.11.1",
"sequential-workflow-editor": "^0.11.1"
"sequential-workflow-editor-model": "^0.11.2",
"sequential-workflow-editor": "^0.11.2"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand All @@ -33,4 +33,4 @@
"@typescript-eslint/parser": "^5.47.0",
"eslint": "^8.30.0"
}
}
}
12 changes: 8 additions & 4 deletions demos/webpack-app/src/editors/model/choice-step-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ export interface ChoiceStepModel extends Step {
componentType: 'task';
properties: {
minimalConfig: string;
defaultValueGreen: string;
defaultValueAllow: 'allow' | 'ignore' | 'deny';
};
}

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

step.property('minimalConfig').value(createChoiceValueModel({ choices }));
step.property('defaultValueGreen').value(createChoiceValueModel({ choices, defaultValue: 'green' }));
step.property('defaultValueAllow').value(
createChoiceValueModel({
choices: ['allow', 'ignore'],
defaultValue: 'ignore'
})
);
});
8 changes: 4 additions & 4 deletions editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor",
"version": "0.11.1",
"version": "0.11.2",
"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.11.1",
"sequential-workflow-editor-model": "^0.11.2",
"sequential-workflow-model": "^0.2.0"
},
"peerDependencies": {
"sequential-workflow-editor-model": "^0.11.1",
"sequential-workflow-editor-model": "^0.11.2",
"sequential-workflow-model": "^0.2.0"
},
"devDependencies": {
Expand Down Expand Up @@ -79,4 +79,4 @@
"lowcode",
"flow"
]
}
}
4 changes: 2 additions & 2 deletions model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor-model",
"version": "0.11.1",
"version": "0.11.2",
"homepage": "https://nocode-js.com/",
"author": {
"name": "NoCode JS",
Expand Down Expand Up @@ -72,4 +72,4 @@
"lowcode",
"flow"
]
}
}
6 changes: 6 additions & 0 deletions model/src/context/scoped-property-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Properties } from 'sequential-workflow-model';
import { ContextVariable } from '../model';
import { ParentsProvider } from './variables-provider';
import { PropertyContext } from './property-context';
import { ValueType } from '../types';

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

public readonly tryGetVariableType = (variableName: string): ValueType | null => {
const variable = this.getVariables().find(v => v.name === variableName);
return variable ? variable.type : null;
};

public readonly getVariables = (): ContextVariable[] => {
return this.parentsProvider.getVariables();
};
Expand Down
1 change: 1 addition & 0 deletions model/src/context/value-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class ValueContext<TValueModel extends ValueModel = ValueModel, TProperti
public readonly hasVariable = this.scopedPropertyContext.hasVariable;
public readonly findFirstUndefinedVariable = this.scopedPropertyContext.findFirstUndefinedVariable;
public readonly isVariableDuplicated = this.scopedPropertyContext.isVariableDuplicated;
public readonly tryGetVariableType = this.scopedPropertyContext.tryGetVariableType;
public readonly getVariables = this.scopedPropertyContext.getVariables;

public readonly getValue = (): ReturnType<TValueModel['getDefaultValue']> => {
Expand Down
1 change: 1 addition & 0 deletions model/src/validator/property-validator-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class PropertyValidatorContext<TValue extends PropertyValue = PropertyVal
public readonly hasVariable = this.valueContext.hasVariable;
public readonly findFirstUndefinedVariable = this.valueContext.findFirstUndefinedVariable;
public readonly isVariableDuplicated = this.valueContext.isVariableDuplicated;
public readonly tryGetVariableType = this.valueContext.tryGetVariableType;
public readonly getVariables = this.valueContext.getVariables;

public getValue(): TValue {
Expand Down
18 changes: 10 additions & 8 deletions model/src/value-models/choice/choice-value-model.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { ValueModel, ValueModelFactoryFromModel, ValidationResult, createValidationSingleError } from '../../model';
import { ValueModel, ValidationResult, createValidationSingleError, ValueModelFactory } from '../../model';
import { Path } from '../../core/path';
import { ValueContext } from '../../context';

export interface ChoiceValueModelConfiguration {
choices: string[];
defaultValue?: string;
export interface ChoiceValueModelConfiguration<TValue extends string = string> {
choices: TValue[];
defaultValue?: TValue;
}

export type ChoiceValueModel = ValueModel<string, ChoiceValueModelConfiguration>;
export type ChoiceValueModel<TValue extends string = string> = ValueModel<TValue, ChoiceValueModelConfiguration<TValue>>;

export const choiceValueModelId = 'choice';

export function createChoiceValueModel(configuration: ChoiceValueModelConfiguration): ValueModelFactoryFromModel<ChoiceValueModel> {
export function createChoiceValueModel<TValue extends string>(
configuration: ChoiceValueModelConfiguration<TValue>
): ValueModelFactory<TValue, ChoiceValueModelConfiguration<TValue>> {
if (configuration.choices.length < 1) {
throw new Error('At least one choice must be provided.');
}
Expand All @@ -25,14 +27,14 @@ export function createChoiceValueModel(configuration: ChoiceValueModelConfigurat
getDefaultValue() {
if (configuration.defaultValue) {
if (!configuration.choices.includes(configuration.defaultValue)) {
throw new Error('Default value does not match any of the choices.');
throw new Error(`Default value "${configuration.defaultValue}" does not match any of the choices.`);
}
return configuration.defaultValue;
}
return configuration.choices[0];
},
getVariableDefinitions: () => null,
validate(context: ValueContext<ChoiceValueModel>): ValidationResult {
validate(context: ValueContext<ChoiceValueModel<TValue>>): ValidationResult {
const value = context.getValue();
if (!configuration.choices.includes(value)) {
return createValidationSingleError('Choice is not supported.');
Expand Down
Loading