parent
ffbac88014
commit
888fa088a6
|
|
@ -1,6 +1,8 @@
|
|||
import {Component, Host, h, Prop, State, Listen, Method, Watch, Event, EventEmitter} from '@stencil/core';
|
||||
import {Component, Event, EventEmitter, h, Host, Method, Prop, Watch} from '@stencil/core';
|
||||
import {initializeMonacoWorker} from "./elsa-monaco-utils";
|
||||
import state from '../../../utils/store';
|
||||
import {languages} from "monaco-editor";
|
||||
import ScriptTarget = languages.typescript.ScriptTarget;
|
||||
|
||||
// Until I figure out why the ESM loader doesn't work properly, we need to include these scripts manually from index.html
|
||||
// import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
|
||||
|
|
@ -52,10 +54,20 @@ export class ElsaMonaco {
|
|||
async addJavaScriptLib(libSource: string, libUri: string) {
|
||||
const monaco = this.monaco;
|
||||
monaco.languages.typescript.javascriptDefaults.setExtraLibs([{
|
||||
content: "<reference lib=\"es5\" />",
|
||||
filePath: "lib.d.ts"
|
||||
}, {
|
||||
content: libSource,
|
||||
filePath: libUri
|
||||
}]);
|
||||
|
||||
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
||||
target: ScriptTarget.ES2020,
|
||||
allowJs: true,
|
||||
checkJs: true,
|
||||
|
||||
})
|
||||
|
||||
const oldModel = monaco.editor.getModel(libUri);
|
||||
|
||||
if (oldModel)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace Elsa.Scripting.JavaScript.Providers
|
|||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var typeScriptType = notification.GetTypeScriptType(propertyType);
|
||||
writer.AppendLine($"{propertyName}(): {typeScriptType}");
|
||||
writer.AppendLine($"{propertyName}(): {typeScriptType};");
|
||||
return new ValueTask();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,10 +159,8 @@ namespace Elsa.Scripting.JavaScript.Providers
|
|||
|
||||
var returnType = method.ReturnType;
|
||||
|
||||
if (returnType != typeof(void))
|
||||
{
|
||||
if (returnType != typeof(void))
|
||||
output.AppendFormat(":{0}", GetTypeScriptType(context, returnType, collectedTypes));
|
||||
}
|
||||
|
||||
output.AppendLine(";");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,29 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using Elsa.Scripting.JavaScript.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Elsa.Scripting.JavaScript.Typings
|
||||
{
|
||||
public class EnumerableTypeDefinitionProvider : TypeDefinitionProvider
|
||||
{
|
||||
public override bool SupportsType(TypeDefinitionContext context, Type type) => typeof(IEnumerable).IsAssignableFrom(type);
|
||||
public override string GetTypeDefinition(TypeDefinitionContext context, Type type) => "[]";
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public EnumerableTypeDefinitionProvider(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public override bool SupportsType(TypeDefinitionContext context, Type type) => typeof(string) != type && typeof(IEnumerable).IsAssignableFrom(type);
|
||||
|
||||
public override string GetTypeDefinition(TypeDefinitionContext context, Type type)
|
||||
{
|
||||
var providers = _serviceProvider.GetServices<ITypeDefinitionProvider>().Where(x => x is not EnumerableTypeDefinitionProvider).ToList();
|
||||
var elementType = type.IsArray ? type.GetElementType()! : type.GetGenericArguments().FirstOrDefault();
|
||||
var typeScriptType = elementType != null ? providers.FirstOrDefault(x => x.SupportsType(context, elementType))?.GetTypeDefinition(context, elementType) : null;
|
||||
|
||||
return typeScriptType == null ? "[]" : $"Array<{typeScriptType}>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue