82 lines
1.4 KiB
TypeScript
82 lines
1.4 KiB
TypeScript
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
|
|
{
|
|
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,
|
|
}
|
|
);
|
|
await input.setup(element_target);
|
|
_input = input;
|
|
}
|
|
catch (error)
|
|
{
|
|
console.error(error);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function main(
|
|
) : void
|
|
{
|
|
document.querySelector("#render").addEventListener(
|
|
"click",
|
|
() => {
|
|
document.querySelector("#value").textContent = "";
|
|
render(
|
|
(document.querySelector("#description") 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();
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|