2020-01-21 15:50:35 +01:00
|
|
|
<script>
|
2020-02-01 00:11:50 +01:00
|
|
|
import { store } from "../builderStore/store";
|
|
|
|
import UIkit from "uikit";
|
|
|
|
import Button from "../common/Button.svelte";
|
|
|
|
import ButtonGroup from "../common/ButtonGroup.svelte";
|
|
|
|
import CodeMirror from "codemirror";
|
|
|
|
import "codemirror/mode/javascript/javascript.js";
|
|
|
|
|
|
|
|
export let onCodeChanged;
|
|
|
|
export let code;
|
|
|
|
|
|
|
|
export const show = () => {
|
|
|
|
UIkit.modal(codeModal).show();
|
|
|
|
}
|
|
|
|
|
|
|
|
let codeModal;
|
|
|
|
let editor;
|
|
|
|
let cmInstance;
|
|
|
|
|
|
|
|
$: currentCode = code;
|
|
|
|
$: originalCode = code;
|
|
|
|
$: {
|
|
|
|
if(editor) {
|
|
|
|
if(!cmInstance) {
|
|
|
|
cmInstance = CodeMirror.fromTextArea(editor, {
|
|
|
|
mode: 'javascript',
|
|
|
|
lineNumbers: false,
|
|
|
|
lineWrapping: true,
|
|
|
|
smartIndent: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
readOnly: false
|
|
|
|
});
|
|
|
|
cmInstance.on("change", () => currentCode = cmInstance.getValue());
|
2020-01-21 15:50:35 +01:00
|
|
|
}
|
2020-02-01 00:11:50 +01:00
|
|
|
cmInstance.focus();
|
2020-02-01 00:29:49 +01:00
|
|
|
cmInstance.setValue(code || "");
|
2020-01-21 15:50:35 +01:00
|
|
|
}
|
2020-02-01 00:11:50 +01:00
|
|
|
}
|
2020-01-21 15:50:35 +01:00
|
|
|
|
2020-02-01 00:11:50 +01:00
|
|
|
const cancel = () => {
|
|
|
|
UIkit.modal(codeModal).hide();
|
|
|
|
currentCode = originalCode;
|
|
|
|
}
|
2020-01-21 15:50:35 +01:00
|
|
|
|
2020-02-01 00:11:50 +01:00
|
|
|
const save = () => {
|
|
|
|
originalCode = currentCode;
|
|
|
|
onCodeChanged(currentCode);
|
|
|
|
UIkit.modal(codeModal).hide();
|
|
|
|
}
|
2020-01-21 15:50:35 +01:00
|
|
|
|
2020-02-01 00:11:50 +01:00
|
|
|
</script>
|
2020-01-21 15:50:35 +01:00
|
|
|
|
|
|
|
|
2020-02-01 00:11:50 +01:00
|
|
|
<div bind:this={codeModal} uk-modal>
|
|
|
|
<div class="uk-modal-dialog" uk-overflow-auto>
|
|
|
|
|
|
|
|
<div class="uk-modal-header">
|
|
|
|
<h3>Code</h3>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="uk-modal-body uk-form-horizontal" >
|
|
|
|
|
|
|
|
<p>Use the code box below to control how this component is displayed, with javascript.</p>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class="editor-code-surround">function(render, context, store) {"{"}</div>
|
|
|
|
<div class="editor">
|
|
|
|
<textarea bind:this={editor}></textarea>
|
|
|
|
</div>
|
|
|
|
<div class="editor-code-surround">
|
|
|
|
{"}"}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<ButtonGroup style="float: right;">
|
|
|
|
<Button color="primary" grouped on:click={save}>Save</Button>
|
|
|
|
<Button color="tertiary" grouped on:click={cancel}>Close</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</div>
|
2020-01-21 15:50:35 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
h3 {
|
|
|
|
text-transform: uppercase;
|
2020-01-22 12:21:42 +01:00
|
|
|
font-size: 12px;
|
2020-01-21 15:50:35 +01:00
|
|
|
font-weight: 700;
|
|
|
|
color: #8997ab;
|
|
|
|
margin-bottom: 10px;
|
|
|
|
}
|
|
|
|
|
|
|
|
p {
|
|
|
|
font-size: 12px;
|
|
|
|
color: #333;
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.editor {
|
2020-02-01 00:11:50 +01:00
|
|
|
border-style: dotted;
|
|
|
|
border-width: 1px;
|
|
|
|
border-color: gainsboro;
|
|
|
|
padding: 10px 30px;
|
2020-01-21 15:50:35 +01:00
|
|
|
}
|
|
|
|
|
2020-02-01 00:11:50 +01:00
|
|
|
.editor-code-surround {
|
|
|
|
font-family: "Courier New", Courier, monospace;
|
2020-01-21 15:50:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|