-
-
-
+
\ No newline at end of file
diff --git a/Elements.Playground/Compiler.cs b/Elements.Playground/Compiler.cs
index da6ba3011..5dc00166e 100644
--- a/Elements.Playground/Compiler.cs
+++ b/Elements.Playground/Compiler.cs
@@ -12,6 +12,11 @@
namespace Elements.Playground
{
+ public class Globals
+ {
+ public string InputJson { get; set; }
+ }
+
public static class Compiler
{
class BlazorBoot
@@ -30,42 +35,39 @@ class Resources
public Dictionary pdb { get; set; }
public Dictionary runtime { get; set; }
}
-
- private static Task InitializationTask;
private static List References;
- public static void InitializeMetadataReferences(HttpClient client)
- {
- async Task InitializeInternal()
- {
- var model = new Model();
- Console.WriteLine("Initializing the code editor...");
+ private static bool _isInitialized = false;
- // TODO: This loads every assembly that is available. We should
- // see if we can limit this to just the ones that we need.
- var response = await client.GetFromJsonAsync("_framework/blazor.boot.json");
- var assemblies = await Task.WhenAll(response.resources.assembly.Keys.Select(x => client.GetAsync("_framework/" + x)));
- var references = new List(assemblies.Length);
- foreach (var asm in assemblies)
- {
- using var task = await asm.Content.ReadAsStreamAsync();
- references.Add(MetadataReference.CreateFromStream(task));
- }
- References = references;
- }
- InitializationTask = InitializeInternal();
+ public static bool IsReady()
+ {
+ return _isInitialized;
}
- public static Task WhenReady(Func action)
+ public static async Task InitializeMetadataReferences(HttpClient client)
{
- if (InitializationTask.Status != TaskStatus.RanToCompletion)
+ if (_isInitialized)
{
- return InitializationTask.ContinueWith(x => action());
+ return;
}
- else
+ var model = new Model();
+ Console.WriteLine("Loading metadata references...");
+ // TODO: Make this conditional on some build flag, so we can easily
+ // deploy to prod or dev, or allow others cloning the project to
+ // spec the URL where they'll be hosting it.
+ var rootUrl = "https://elements.hypar.io/";
+ // TODO: This loads every assembly that is available. We should
+ // see if we can limit this to just the ones that we need.
+ var response = await client.GetFromJsonAsync($"{rootUrl}blazor.boot.json");
+ var assemblies = await Task.WhenAll(response.resources.assembly.Keys.Select(x => client.GetAsync($"{rootUrl}{x}")));
+ var references = new List(assemblies.Length);
+ foreach (var asm in assemblies)
{
- return action();
+ using var task = await asm.Content.ReadAsStreamAsync();
+ references.Add(MetadataReference.CreateFromStream(task));
}
+ References = references;
+ _isInitialized = true;
}
public static (bool success, Assembly asm, Compilation compilation) LoadSource(string source)
@@ -83,11 +85,15 @@ public static (bool success, Assembly asm, Compilation compilation) LoadSource(s
"System.Collections.Generic",
"System.Console",
"System.Linq",
+"System.Text.Json",
+"System.Text.Json.Serialization",
"Elements",
"Elements.Geometry",
+"Elements.Geometry.Solids",
+"Elements.Spatial",
"Elements.Geometry.Profiles",
"Elements.Validators"
- }, concurrentBuild: false));
+ }, concurrentBuild: false), globalsType: typeof(Globals));
ImmutableArray diagnostics = compilation.GetDiagnostics();
diff --git a/Elements.Playground/Elements.Playground.csproj b/Elements.Playground/Elements.Playground.csproj
index 83a14308e..f2a6af55a 100644
--- a/Elements.Playground/Elements.Playground.csproj
+++ b/Elements.Playground/Elements.Playground.csproj
@@ -1,7 +1,7 @@
- net5.0
+ net6.0enfalsefalse
@@ -9,10 +9,8 @@
-
-
-
-
+
+
diff --git a/Elements.Playground/ElementsAPI.razor b/Elements.Playground/ElementsAPI.razor
new file mode 100644
index 000000000..dc84e6da0
--- /dev/null
+++ b/Elements.Playground/ElementsAPI.razor
@@ -0,0 +1,152 @@
+@page "/"
+
+@inject IJSRuntime JSRuntime
+
+
+
+@code {
+
+ public class Result
+ {
+ public bool Success { get; set; }
+
+ public string Output { get; set; }
+
+ public string ModelJson { get; set; }
+ }
+
+ // Why do we need a component to call Elements compile and
+ // run elements code from the browser?
+ // 1. We need an HttpClient passed in from the framework. We can't
+ // create it because this code runs sandboxed in wasm. It has to
+ // come from blazor and the only way to do that is by injecting it
+ // as a service.
+ // 2. We need the the IJSRuntime to call methods in javascript. This
+ // also needs to be injected as a service.
+
+ private static Globals globals = new Globals();
+ private static IJSRuntime runtime;
+ [Inject] private HttpClient Client { get; set; }
+ private static Func