From 75e01c352d528a74e8107a20ec292486a4a24572 Mon Sep 17 00:00:00 2001 From: Tyler K Date: Fri, 9 Aug 2024 13:46:30 -0700 Subject: [PATCH 01/12] Creating support for array of strings in demo --- tool/src/demo_gen/terminus.rs | 2 +- tool/src/js/type_generation/converter.rs | 2 +- .../demo_gen/default_renderer/rendering.mjs | 18 ++++++++++++++++++ .../demo_gen/default_renderer/template.html | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tool/src/demo_gen/terminus.rs b/tool/src/demo_gen/terminus.rs index bd7882629..2a590ae36 100644 --- a/tool/src/demo_gen/terminus.rs +++ b/tool/src/demo_gen/terminus.rs @@ -260,7 +260,7 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> { ); } Type::Slice(hir::Slice::Strs(..)) => { - self.append_out_param(param_name, "Array".to_string(), node, attrs); + self.append_out_param(param_name, "Array".to_string(), node, attrs); } // Types we can't easily coerce into out parameters: Type::Opaque(o) => { diff --git a/tool/src/js/type_generation/converter.rs b/tool/src/js/type_generation/converter.rs index 9d6dea3f9..6bcf09ee0 100644 --- a/tool/src/js/type_generation/converter.rs +++ b/tool/src/js/type_generation/converter.rs @@ -85,7 +85,7 @@ impl<'jsctx, 'tcx> TyGenContext<'jsctx, 'tcx> { Type::Slice(hir::Slice::Primitive(_, p)) => { self.formatter.fmt_primitive_list_type(p).into() } - Type::Slice(hir::Slice::Strs(..)) => "Array".into(), + Type::Slice(hir::Slice::Strs(..)) => "Array".into(), _ => unreachable!("AST/HIR variant {:?} unknown", ty), } } diff --git a/tool/templates/demo_gen/default_renderer/rendering.mjs b/tool/templates/demo_gen/default_renderer/rendering.mjs index bb648cf56..1cd0d47b2 100644 --- a/tool/templates/demo_gen/default_renderer/rendering.mjs +++ b/tool/templates/demo_gen/default_renderer/rendering.mjs @@ -81,6 +81,20 @@ class StringTemplate extends ParameterTemplate { customElements.define("terminus-param-string", StringTemplate); +class StringArrayTemplate extends ParameterTemplate { + default = []; + static template; + constructor() { + super(StringArrayTemplate, "template#string-array"); + } + + getEventValue(event) { + return event.target.value.split(","); + } +} + +customElements.define("terminus-param-string-array", StringArrayTemplate); + class EnumOption extends HTMLElement { static template; constructor(optionText) { @@ -149,6 +163,10 @@ class TerminusParams extends HTMLElement { newChild = new NumberTemplate(); this.#params[i] = 0; break; + case "Array": + newChild = new StringArrayTemplate(); + this.#params[i] = []; + break; default: if (param.type in library && "values" in library[param.type]) { newChild = new EnumTemplate(library[param.type]); diff --git a/tool/templates/demo_gen/default_renderer/template.html b/tool/templates/demo_gen/default_renderer/template.html index 74a4647b7..69730615b 100644 --- a/tool/templates/demo_gen/default_renderer/template.html +++ b/tool/templates/demo_gen/default_renderer/template.html @@ -40,6 +40,10 @@

+ + + +