Compare commits
2 Commits
84278b2e91
...
378a6f2ae1
Author | SHA1 | Date | |
---|---|---|---|
378a6f2ae1 | |||
aae8912c08 |
|
@ -42,7 +42,7 @@ const ensureObjectLanguage = () => {
|
||||||
}
|
}
|
||||||
return window.Bergamot.ObjectLanguage;
|
return window.Bergamot.ObjectLanguage;
|
||||||
}
|
}
|
||||||
const parseString = (str) => {
|
const parseBergamotObjectLanguage = (str) => {
|
||||||
if (!(str in parsingPromiseResolvers)) {
|
if (!(str in parsingPromiseResolvers)) {
|
||||||
parsingPromiseResolvers[str] = [];
|
parsingPromiseResolvers[str] = [];
|
||||||
}
|
}
|
||||||
|
@ -54,20 +54,21 @@ const parseString = (str) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.Bergamot = {};
|
window.Bergamot = {};
|
||||||
window.Bergamot.run = (inputGroup, nodeId, inputPrompt, rules, renderPreset, input) => {
|
window.Bergamot.run = (inputGroup, nodeId, inputModes, 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 }) => {
|
||||||
let query = await parseString(input);
|
if (!(mode in window.Bergamot.inputModes)) {
|
||||||
|
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 } });
|
||||||
|
@ -80,7 +81,7 @@ window.Bergamot.run = (inputGroup, nodeId, inputPrompt, rules, renderPreset, inp
|
||||||
};
|
};
|
||||||
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.inputPrompt, preset.rules, preset.renderPreset, preset.query || "");
|
window.Bergamot.run(inputGroup, nodeId, preset.inputModes, 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;
|
||||||
|
@ -94,5 +95,8 @@ 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 = {};
|
||||||
|
|
6
layouts/partials/bergamotinputmode.html
Normal file
6
layouts/partials/bergamotinputmode.html
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<script>
|
||||||
|
window.addEventListener('load', function() {
|
||||||
|
window.Bergamot.inputModes['{{ .name }}'] = {{ .fn | safeJS }};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
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 }}'
|
||||||
|
|
|
@ -43,6 +43,12 @@
|
||||||
{{ 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>
|
||||||
|
@ -72,10 +78,15 @@
|
||||||
{{ 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 }}
|
{{ $info := dict "name" $name "prompt" $preset.prompt "query" $preset.query "file" $file.Content "renderPreset" $preset.render_preset "inputModes" $preset.input_modes }}
|
||||||
{{ 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 }}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user