namespace formgen { /** */ let _input : (null | formgen.ioc.interface_ioc) = null; /** */ async function render( kind : string, content : string, element_target : Element ) : Promise { element_target.innerHTML = ""; try { let input : formgen.ioc.interface_ioc; const variant : string = "description"; switch (kind) { case "manual": { const ioc_input = new formgen.ioc.class_ioc_group( [ { "name": "left", "ioc": new formgen.ioc.class_ioc_number( { "label": "Eingabe | links", } ), "marked": true, }, { "name": "right", "ioc": new formgen.ioc.class_ioc_number( { "label": "Eingabe | rechts", } ), "marked": true, }, ] ); const ioc_output = new formgen.ioc.class_ioc_number( { "label": "Ausgabe", } ); input = new formgen.ioc.class_ioc_group( [ { "name": "input", "ioc": ioc_input, "marked": true, }, { "name": "output", "ioc": ioc_output, "marked": false, }, ], { // "label": "Eingabe", } ); break; } case "raw_description": { const description : formgen.ioc.type_description = (formgen.helpers.json.decode(content) as formgen.ioc.type_description); input = formgen.ioc.from_raw( description ); break; } case "json_schema": { const json_schema : formgen.helpers.json_schema.type_root = (formgen.helpers.json.decode(content) as formgen.helpers.json_schema.type_root); input = formgen.ioc.from_json_schema( json_schema, { // "map_unhandled_refs_to_empty": true, } ); break; } } await input.setup(element_target); /* ioc_input.listen( value => { if ((value.left === null) || (value.right === null)) { ioc_output.write(null); } else { ioc_output.write(value.left * value.right); } } ); */ _input = input; } catch (error) { console.error(error); } } /** */ async function main( ) : Promise { // init:conf { await formgen.conf.initialize("conf.json"); } // init:zerez { await formgen.helpers.zerez.initialize( formgen.conf.get().zerez, { "fake": formgen.conf.get().zerez.fake, } ); } // exec { document.querySelector("#render").addEventListener( "click", () => { document.querySelector("#value").textContent = ""; render( (document.querySelector("#description_kind") as HTMLInputElement).value, (document.querySelector("#description_content") as HTMLInputElement).value, document.querySelector("#form") ); } ); document.querySelector("#read").addEventListener( "click", async () => { if (_input === null) { console.warn("no input present"); } else { const value = await _input.read(); document.querySelector("#value").textContent = JSON.stringify(value, undefined, " "); } } ); } } /** */ export function entry( ) : void { document.addEventListener( "DOMContentLoaded", () => { ( main() .then(() => {}) .catch(console.error) ); } ); } }