bergamot-elm/index.html
Danila Fedorin bfc21c2928 Add support for custom modes
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
2024-09-07 21:43:02 -07:00

85 lines
2.3 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Main</title>
<script type="module" src="https://unpkg.com/@navsnpm/katex-expression/dist/katex-expression/katex-expression.esm.js"></script>
<script nomodule="" src="https://unpkg.com/@navsnpm/katex-expression/dist/katex-expression/katex-expression.js"></script>
<style>body { padding: 0; margin: 0; }</style>
<style>
textarea {
display: block;
width: 100%;
height: 10em;
resize: none;
}
input[type="text"] {
width: 100%;
}
.rule-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
}
.rule-list katex-expression {
margin-left: .5em;
margin-right: .5em;
flex-grow: 1;
flex-basis: 0;
}
.elm-root {
max-width: 800px;
margin: auto;
padding: 1em;
border: 1px solid #c3c3c3;
border-radius: 0.5em;
margin-top: 1em;
}
.elm-root h2 {
margin-bottom: 0.5em;
font-family: sans-serif;
font-weight: normal;
}
</style>
</head>
<body>
<div id="elm"></div>
<script src="index.js"></script>
<script>
(async () => {
var rulesResponse = await fetch("./demorules.bergamot");
var rules = await rulesResponse.text();
var renderRulesResponse = await fetch("./renderrules.bergamot");
var renderRules = await renderRulesResponse.text();
console.log(rules);
var app = Elm.Main.init({
node: document.getElementById('elm'),
flags: {
inputModes: {
"My Mode": { "custom": "mymode" },
"Query": "query",
"Language Term": "syntax",
},
inputRules: "PromptConverter @ prompt(type(empty, ?term, ?t)) <- input(?term);",
input: "type(empty, app(abs(x, number, var(x)), lit(1)), ?tau)",
renderRules: renderRules, rules: rules
}
});
app.ports.convertInput.subscribe(({ mode, input }) => {
console.log(input);
app.ports.receiveConverted.send({ input, query: `type(empty, lit(${input}), ?tau )` });
});
})();
</script>
</body>
</html>