formgen/source/logic/main.ts

82 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2026-04-22 07:47:23 +02:00
namespace formgen
{
/**
*/
let _input : (null | formgen.input.interface_input<unknown>) = null;
/**
*/
async function render(
raw : string,
element_target : Element
) : Promise<void>
{
element_target.innerHTML = "";
try
{
2026-04-22 22:24:32 +02:00
const json_schema : formgen.helpers.json_schema.type_root = (formgen.helpers.json.decode(raw) as formgen.helpers.json_schema.type_root);
const input : formgen.input.interface_input<unknown> = formgen.input.from_json_schema(
json_schema,
{
// "map_unhandled_refs_to_empty": true,
}
2026-04-22 07:47:23 +02:00
);
await input.setup(element_target);
_input = input;
}
catch (error)
{
console.error(error);
}
}
/**
*/
function main(
) : void
{
document.querySelector("#render").addEventListener(
"click",
() => {
2026-04-22 22:24:32 +02:00
document.querySelector("#value").textContent = "";
2026-04-22 07:47:23 +02:00
render(
2026-04-22 22:24:32 +02:00
(document.querySelector("#description") as HTMLInputElement).value,
document.querySelector("#form")
2026-04-22 07:47:23 +02:00
);
}
);
document.querySelector("#read").addEventListener(
"click",
async () => {
if (_input === null)
{
console.warn("no input present");
}
else
{
const value = await _input.read();
2026-04-22 22:24:32 +02:00
document.querySelector("#value").textContent = JSON.stringify(value, undefined, " ");
2026-04-22 07:47:23 +02:00
}
}
);
}
/**
*/
export function entry(
) : void
{
document.addEventListener(
"DOMContentLoaded",
() => {
main();
}
);
}
}