From 2503075179bbb4a15e1fdecabe517636c81c8b41 Mon Sep 17 00:00:00 2001 From: Bart Tadych Date: Sun, 6 Oct 2024 11:54:29 +0200 Subject: [PATCH] 0.14.1. (#43) --- CHANGELOG.md | 4 +++ demos/webpack-app/package.json | 4 +-- editor/package.json | 6 ++--- model/package.json | 2 +- model/src/context/default-value-context.ts | 1 + model/src/context/property-context.ts | 26 +++++++++++++++++++ model/src/context/scoped-property-context.ts | 1 + model/src/context/value-context.ts | 1 + .../generated-string-context.ts | 12 +-------- 9 files changed, 40 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4807dd4..7a1b862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.14.1 + +This version adds the `formatPropertyValue` method to: `PropertyContext`, `DefaultValueContext`, `ScopedPropertyContext` and `ValueContext` classes. + ## 0.14.0 From now, the nullable any variable editor and the nullable variable editor display the expected variable types to select. This version also allows changes to the labels in the dropdown menu of the dynamic value editor. diff --git a/demos/webpack-app/package.json b/demos/webpack-app/package.json index 241681b..a330110 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.21.2", "sequential-workflow-machine": "^0.4.0", - "sequential-workflow-editor-model": "^0.14.0", - "sequential-workflow-editor": "^0.14.0" + "sequential-workflow-editor-model": "^0.14.1", + "sequential-workflow-editor": "^0.14.1" }, "devDependencies": { "ts-loader": "^9.4.2", diff --git a/editor/package.json b/editor/package.json index 3425a97..757abff 100644 --- a/editor/package.json +++ b/editor/package.json @@ -1,6 +1,6 @@ { "name": "sequential-workflow-editor", - "version": "0.14.0", + "version": "0.14.1", "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.14.0", + "sequential-workflow-editor-model": "^0.14.1", "sequential-workflow-model": "^0.2.0" }, "peerDependencies": { - "sequential-workflow-editor-model": "^0.14.0", + "sequential-workflow-editor-model": "^0.14.1", "sequential-workflow-model": "^0.2.0" }, "devDependencies": { diff --git a/model/package.json b/model/package.json index 0e05a83..fdf7842 100644 --- a/model/package.json +++ b/model/package.json @@ -1,6 +1,6 @@ { "name": "sequential-workflow-editor-model", - "version": "0.14.0", + "version": "0.14.1", "homepage": "https://nocode-js.com/", "author": { "name": "NoCode JS", diff --git a/model/src/context/default-value-context.ts b/model/src/context/default-value-context.ts index 8a4eac6..8ae6c5d 100644 --- a/model/src/context/default-value-context.ts +++ b/model/src/context/default-value-context.ts @@ -16,5 +16,6 @@ export class DefaultValueContext { ) {} public readonly getPropertyValue = this.propertyContext.getPropertyValue; + public readonly formatPropertyValue = this.propertyContext.formatPropertyValue; public readonly activateStep = this.activator.activateStep; } diff --git a/model/src/context/property-context.ts b/model/src/context/property-context.ts index a2db199..1174f1e 100644 --- a/model/src/context/property-context.ts +++ b/model/src/context/property-context.ts @@ -18,11 +18,37 @@ export class PropertyContext { private readonly definitionModel: DefinitionModel ) {} + /** + * Get the value of a property by name. + * @param name The name of the property. + * @returns The value of the property. + */ public readonly getPropertyValue = (name: Key): TProperties[Key] => { return readPropertyValue(name, this.propertyModel, this.object); }; + /** + * @returns The supported value types for variables. + */ public readonly getValueTypes = (): ValueType[] => { return this.definitionModel.valueTypes; }; + + /** + * Format a property value using a formatter function. + * @param name The name of the property. + * @param formatter The formatter function. + * @param undefinedValue The value to return if the property value is `null` or `undefined`. + */ + public readonly formatPropertyValue = ( + name: Key, + formatter: (value: NonNullable) => string, + undefinedValue?: string + ): string => { + const value = this.getPropertyValue(name); + if (value === undefined || value === null) { + return undefinedValue || '?'; + } + return formatter(value); + }; } diff --git a/model/src/context/scoped-property-context.ts b/model/src/context/scoped-property-context.ts index 2ccf67d..66ec37d 100644 --- a/model/src/context/scoped-property-context.ts +++ b/model/src/context/scoped-property-context.ts @@ -21,6 +21,7 @@ export class ScopedPropertyContext { ) {} public readonly getPropertyValue = this.propertyContext.getPropertyValue; + public readonly formatPropertyValue = this.propertyContext.formatPropertyValue; public readonly getValueTypes = this.propertyContext.getValueTypes; public readonly hasVariable = (variableName: string, valueType: string | null): boolean => { diff --git a/model/src/context/value-context.ts b/model/src/context/value-context.ts index e930337..04f8a74 100644 --- a/model/src/context/value-context.ts +++ b/model/src/context/value-context.ts @@ -26,6 +26,7 @@ export class ValueContext ) {} public readonly getPropertyValue = this.context.getPropertyValue; - - public formatPropertyValue( - name: Key, - formatter: (value: NonNullable) => string - ): string { - const value = this.getPropertyValue(name); - if (value === undefined || value === null) { - return '?'; - } - return formatter(value); - } + public readonly formatPropertyValue = this.context.formatPropertyValue; }