Configure RunJavaScript to use javascript language for Monaco editor
This commit is contained in:
parent
d5d9c63548
commit
e4647affe1
|
|
@ -5,6 +5,7 @@ import {getInputPropertyValue} from "../../utils";
|
|||
import {MonacoValueChangedArgs} from "../shared/monaco-editor/monaco-editor";
|
||||
import {ExpressionChangedArs} from "../designer/input-control-switch/input-control-switch";
|
||||
import descriptorsStore from "../../data/descriptors-store";
|
||||
import {FormEntry} from "../shared/forms/form-entry";
|
||||
|
||||
interface CodeEditorOptions {
|
||||
editorHeight?: EditorHeight;
|
||||
|
|
@ -22,20 +23,20 @@ export class CodeEditorInput {
|
|||
public render() {
|
||||
const inputContext = this.inputContext;
|
||||
const inputDescriptor = inputContext.inputDescriptor;
|
||||
const fieldId = inputDescriptor.name;
|
||||
const displayName = inputDescriptor.displayName;
|
||||
const hint = inputDescriptor.description;
|
||||
const options: CodeEditorOptions = inputDescriptor.options || {};
|
||||
const input = getInputPropertyValue(inputContext);
|
||||
const syntax = input?.expression?.type ?? inputDescriptor.defaultSyntax;
|
||||
let value = (input?.expression as LiteralExpression)?.value;
|
||||
|
||||
if (value == undefined)
|
||||
value = inputDescriptor.defaultValue;
|
||||
|
||||
return (
|
||||
<elsa-input-control-switch label={displayName} hint={hint} syntax={syntax} expression={value} onExpressionChanged={this.onExpressionChanged}>
|
||||
<elsa-monaco-editor value={value} {...options} onValueChanged={this.onChange}/>
|
||||
</elsa-input-control-switch>
|
||||
<FormEntry label={displayName} fieldId={fieldId} hint={hint}>
|
||||
<elsa-monaco-editor value={value} {...options} onValueChanged={this.onChange}/>
|
||||
</FormEntry>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -44,7 +45,4 @@ export class CodeEditorInput {
|
|||
this.inputContext.inputChanged(value, SyntaxNames.Literal);
|
||||
}
|
||||
|
||||
private onExpressionChanged = (e: CustomEvent<ExpressionChangedArs>) => {
|
||||
this.inputContext.inputChanged(e.detail.expression, e.detail.syntax);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Text.Json.Serialization;
|
||||
using Elsa.Workflows.Core.Attributes;
|
||||
using Elsa.Workflows.Core.Models;
|
||||
using Elsa.Workflows.Management.Models;
|
||||
using IJavaScriptEvaluator = Elsa.JavaScript.Services.IJavaScriptEvaluator;
|
||||
|
||||
namespace Elsa.JavaScript.Activities;
|
||||
|
|
@ -17,7 +18,8 @@ public class RunJavaScript : Activity<object?>
|
|||
{
|
||||
Script = new Input<string>(script);
|
||||
}
|
||||
|
||||
|
||||
[Input(UIHint = InputUIHints.CodeEditor, OptionsProvider = typeof(RunJavaScriptOptionsProvider))]
|
||||
public Input<string> Script { get; set; } = new("");
|
||||
|
||||
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
|
||||
|
|
@ -30,7 +32,7 @@ public class RunJavaScript : Activity<object?>
|
|||
|
||||
// Get a JavaScript evaluator.
|
||||
var javaScriptEvaluator = context.GetRequiredService<IJavaScriptEvaluator>();
|
||||
|
||||
|
||||
// Run the script.
|
||||
var result = await javaScriptEvaluator.EvaluateAsync(script, typeof(object), context.ExpressionExecutionContext, cancellationToken: context.CancellationToken);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
using System.Reflection;
|
||||
using Elsa.Workflows.Management.ActivityInputOptions;
|
||||
using Elsa.Workflows.Management.Implementations;
|
||||
|
||||
namespace Elsa.JavaScript.Activities;
|
||||
|
||||
internal class RunJavaScriptOptionsProvider : IActivityPropertyOptionsProvider
|
||||
{
|
||||
public object? GetOptions(PropertyInfo property)
|
||||
{
|
||||
return new CodeEditorOptions
|
||||
{
|
||||
Language = "javascript"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
<ProjectReference Include="..\Elsa.Expressions\Elsa.Expressions.csproj" />
|
||||
<ProjectReference Include="..\Elsa.Mediator\Elsa.Mediator.csproj" />
|
||||
<ProjectReference Include="..\Elsa.Workflows.Core\Elsa.Workflows.Core.csproj" />
|
||||
<ProjectReference Include="..\Elsa.Workflows.Management\Elsa.Workflows.Management.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using Elsa.Expressions.Services;
|
|||
using Elsa.Features.Abstractions;
|
||||
using Elsa.Features.Attributes;
|
||||
using Elsa.Features.Services;
|
||||
using Elsa.JavaScript.Activities;
|
||||
using Elsa.JavaScript.Expressions;
|
||||
using Elsa.JavaScript.Handlers;
|
||||
using Elsa.JavaScript.Implementations;
|
||||
|
|
@ -11,6 +12,7 @@ using Elsa.JavaScript.Providers;
|
|||
using Elsa.JavaScript.Services;
|
||||
using Elsa.Mediator.Extensions;
|
||||
using Elsa.Mediator.Features;
|
||||
using Elsa.Workflows.Management.Implementations;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.JavaScript.Features;
|
||||
|
|
@ -28,6 +30,7 @@ public class JavaScriptFeature : FeatureBase
|
|||
Services
|
||||
.AddSingleton<IExpressionSyntaxProvider, JavaScriptExpressionSyntaxProvider>()
|
||||
.AddSingleton<IJavaScriptEvaluator, JintJavaScriptEvaluator>()
|
||||
.AddSingleton<IActivityPropertyOptionsProvider, RunJavaScriptOptionsProvider>()
|
||||
.AddNotificationHandlersFrom<ConfigureJavaScriptEngineWithActivityOutput>()
|
||||
.AddExpressionHandler<JavaScriptExpressionHandler, JavaScriptExpression>();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue