Compare commits

..

No commits in common. "378a6f2ae10a0156ff6eee6df4f5078b7e184ac8" and "84278b2e91c9bcfcc08b34c08daa355e7c8f336a" have entirely different histories.

4 changed files with 9 additions and 31 deletions

View File

@ -42,7 +42,7 @@ const ensureObjectLanguage = () => {
} }
return window.Bergamot.ObjectLanguage; return window.Bergamot.ObjectLanguage;
} }
const parseBergamotObjectLanguage = (str) => { const parseString = (str) => {
if (!(str in parsingPromiseResolvers)) { if (!(str in parsingPromiseResolvers)) {
parsingPromiseResolvers[str] = []; parsingPromiseResolvers[str] = [];
} }
@ -54,21 +54,20 @@ const parseBergamotObjectLanguage = (str) => {
} }
window.Bergamot = {}; window.Bergamot = {};
window.Bergamot.run = (inputGroup, nodeId, inputModes, inputPrompt, rules, renderPreset, input) => { window.Bergamot.run = (inputGroup, nodeId, inputPrompt, rules, renderPreset, input) => {
var app = Elm.Main.init({ var app = Elm.Main.init({
node: document.getElementById(nodeId), node: document.getElementById(nodeId),
flags: { flags: {
inputModes, inputModes: {
"Languge Term": { "custom": "Language Term" },
"Query": "query"
},
renderRules: window.Bergamot.renderPresets[renderPreset], renderRules: window.Bergamot.renderPresets[renderPreset],
rules, input rules, input
} }
}); });
app.ports.convertInput.subscribe(async ({ mode, input }) => { app.ports.convertInput.subscribe(async ({ mode, input }) => {
if (!(mode in window.Bergamot.inputModes)) { let query = await parseString(input);
app.ports.receiveConverted.send({ input, result: { error: "Improperly configured desugaring function (this is the website developer's fault)" } });
}
let query = await (window.Bergamot.inputModes[mode])(input);
if (query !== null) { if (query !== null) {
query = inputPrompt.replace("TERM", query); query = inputPrompt.replace("TERM", query);
app.ports.receiveConverted.send({ input, result: { query } }); app.ports.receiveConverted.send({ input, result: { query } });
@ -81,7 +80,7 @@ window.Bergamot.run = (inputGroup, nodeId, inputModes, inputPrompt, rules, rende
}; };
window.Bergamot.runPreset = (inputGroup, nodeId, presetName) => { window.Bergamot.runPreset = (inputGroup, nodeId, presetName) => {
const preset = window.Bergamot.presets[presetName]; const preset = window.Bergamot.presets[presetName];
window.Bergamot.run(inputGroup, nodeId, preset.inputModes, preset.inputPrompt, preset.rules, preset.renderPreset, preset.query || ""); window.Bergamot.run(inputGroup, nodeId, preset.inputPrompt, preset.rules, preset.renderPreset, preset.query || "");
}; };
window.Bergamot.close = (inputGroup, nodeId) => { window.Bergamot.close = (inputGroup, nodeId) => {
if (!(nodeId in loadedWidgets)) return; if (!(nodeId in loadedWidgets)) return;
@ -95,8 +94,5 @@ window.Bergamot.close = (inputGroup, nodeId) => {
delete loadedWidgets[nodeId]; delete loadedWidgets[nodeId];
setRunning(inputGroup, false); setRunning(inputGroup, false);
} }
window.Bergamot.inputModes = {
"Bergamot Object Language": parseBergamotObjectLanguage
};
window.Bergamot.presets = {}; window.Bergamot.presets = {};
window.Bergamot.renderPresets = {}; window.Bergamot.renderPresets = {};

View File

@ -1,6 +0,0 @@
<script>
window.addEventListener('load', function() {
window.Bergamot.inputModes['{{ .name }}'] = {{ .fn | safeJS }};
});
</script>

View File

@ -2,7 +2,6 @@
window.addEventListener('load', function() { window.addEventListener('load', function() {
window.Bergamot.presets['{{ .name }}'] = { window.Bergamot.presets['{{ .name }}'] = {
rules: {{ .file }}, rules: {{ .file }},
inputModes: {{ partial "bergamotparseinputmodes.js" .modes | safeJS }},
inputPrompt: '{{ .prompt }}', inputPrompt: '{{ .prompt }}',
query: '{{ .query }}', query: '{{ .query }}',
renderPreset: '{{ default "default" .renderPreset }}' renderPreset: '{{ default "default" .renderPreset }}'

View File

@ -43,12 +43,6 @@
{{ end }} {{ end }}
<link rel="icon" type="image/png" href="{{ $icon.Permalink }}"> <link rel="icon" type="image/png" href="{{ $icon.Permalink }}">
{{ if .Params.custom_js }}
{{ range $customJs := .Params.custom_js }}
<script src="{{ page.Resources.Get $customJs }}"></script>
{{ end }}
{{ end }}
{{ if hugo.IsServer }} {{ if hugo.IsServer }}
<!-- KaTeX auto-rendering for when we don't have a post-processing step. --> <!-- KaTeX auto-rendering for when we don't have a post-processing step. -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js" integrity="sha384-X/XCfMm41VSsqRNQgDerQczD69XqmjOOOwYQvr/uuC+j4OPoNhVgjdGFwhvN02Ja" crossorigin="anonymous"></script> <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js" integrity="sha384-X/XCfMm41VSsqRNQgDerQczD69XqmjOOOwYQvr/uuC+j4OPoNhVgjdGFwhvN02Ja" crossorigin="anonymous"></script>
@ -78,15 +72,10 @@
{{ if .Params.bergamot.presets }} {{ if .Params.bergamot.presets }}
{{ range $name, $preset := .Params.bergamot.presets }} {{ range $name, $preset := .Params.bergamot.presets }}
{{ $file := default (resources.Get $preset.file) (page.Resources.Get $preset.file) }} {{ $file := default (resources.Get $preset.file) (page.Resources.Get $preset.file) }}
{{ $info := dict "name" $name "prompt" $preset.prompt "query" $preset.query "file" $file.Content "renderPreset" $preset.render_preset "inputModes" $preset.input_modes }} {{ $info := dict "name" $name "prompt" $preset.prompt "query" $preset.query "file" $file.Content "renderPreset" $preset.render_preset }}
{{ partial "bergamotpreset.html" $info }} {{ partial "bergamotpreset.html" $info }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ if .Params.bergamot.input_modes }}
{{ range $mode := .Params.bergamot.input_modes }}
{{ partial "bergamotinputmode.html" (dict "name" $mode.name "fn" $mode.fn) }}
{{ end }}
{{ end }}
{{ end }} {{ end }}
{{ with .Site.Params.plausibleAnalyticsDomain }} {{ with .Site.Params.plausibleAnalyticsDomain }}