diff --git a/CHANGELOG.md b/CHANGELOG.md index cef41eb..8bd051c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/demos/webpack-app/package.json b/demos/webpack-app/package.json index 900610b..159ee81 100644 --- a/demos/webpack-app/package.json +++ b/demos/webpack-app/package.json @@ -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", @@ -33,4 +33,4 @@ "@typescript-eslint/parser": "^5.47.0", "eslint": "^8.30.0" } -} +} \ No newline at end of file diff --git a/demos/webpack-app/src/editors/model/choice-step-model.ts b/demos/webpack-app/src/editors/model/choice-step-model.ts index 4547ab5..6eaeb48 100644 --- a/demos/webpack-app/src/editors/model/choice-step-model.ts +++ b/demos/webpack-app/src/editors/model/choice-step-model.ts @@ -6,13 +6,17 @@ export interface ChoiceStepModel extends Step { componentType: 'task'; properties: { minimalConfig: string; - defaultValueGreen: string; + defaultValueAllow: 'allow' | 'ignore' | 'deny'; }; } export const choiceStepModel = createStepModel('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' + }) + ); }); diff --git a/editor/package.json b/editor/package.json index 3eb7c03..baed7f9 100644 --- a/editor/package.json +++ b/editor/package.json @@ -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", @@ -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": { @@ -79,4 +79,4 @@ "lowcode", "flow" ] -} +} \ No newline at end of file diff --git a/model/package.json b/model/package.json index 96a72ce..e322e1c 100644 --- a/model/package.json +++ b/model/package.json @@ -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", @@ -72,4 +72,4 @@ "lowcode", "flow" ] -} +} \ No newline at end of file diff --git a/model/src/context/scoped-property-context.ts b/model/src/context/scoped-property-context.ts index c290ea6..e1e3c07 100644 --- a/model/src/context/scoped-property-context.ts +++ b/model/src/context/scoped-property-context.ts @@ -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 { public static create( @@ -32,6 +33,11 @@ export class ScopedPropertyContext { 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(); }; diff --git a/model/src/context/value-context.ts b/model/src/context/value-context.ts index 71cadd5..db385d4 100644 --- a/model/src/context/value-context.ts +++ b/model/src/context/value-context.ts @@ -28,6 +28,7 @@ export class ValueContext => { diff --git a/model/src/validator/property-validator-context.ts b/model/src/validator/property-validator-context.ts index bea816e..6a8d378 100644 --- a/model/src/validator/property-validator-context.ts +++ b/model/src/validator/property-validator-context.ts @@ -16,6 +16,7 @@ export class PropertyValidatorContext { + choices: TValue[]; + defaultValue?: TValue; } -export type ChoiceValueModel = ValueModel; +export type ChoiceValueModel = ValueModel>; export const choiceValueModelId = 'choice'; -export function createChoiceValueModel(configuration: ChoiceValueModelConfiguration): ValueModelFactoryFromModel { +export function createChoiceValueModel( + configuration: ChoiceValueModelConfiguration +): ValueModelFactory> { if (configuration.choices.length < 1) { throw new Error('At least one choice must be provided.'); } @@ -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): ValidationResult { + validate(context: ValueContext>): ValidationResult { const value = context.getValue(); if (!configuration.choices.includes(value)) { return createValidationSingleError('Choice is not supported.');