09c29219b4
* Refactor editor css, fix editor button highlight - Avoid using webview.css - Move more buttons css into button_mixins * Fix DropdownItem appearance * Fix the visuals of tags * Make dropdown font slightly smaller * Give SelectOption a background color * Move some css from deck-options-base to CardStateCustomizer * Avoid using core.scss for CardStats * Avoid using sass/core in congrats package * Inline core.scss into webview.scss * Include fusion-vars for base.scss * need to keep core.scss around for now (dae)
79 lines
2.2 KiB
Svelte
79 lines
2.2 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script context="module" lang="ts">
|
|
import { CodeMirror as CodeMirrorLib } from "./code-mirror";
|
|
|
|
export interface CodeMirrorAPI {
|
|
readonly editor: CodeMirrorLib.EditorFromTextArea;
|
|
}
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
import { createEventDispatcher, getContext } from "svelte";
|
|
import type { Writable } from "svelte/store";
|
|
import storeSubscribe from "../sveltelib/store-subscribe";
|
|
import { directionKey } from "../lib/context-keys";
|
|
|
|
export let configuration: CodeMirror.EditorConfiguration;
|
|
export let code: Writable<string>;
|
|
|
|
const direction = getContext<Writable<"ltr" | "rtl">>(directionKey);
|
|
const defaultConfiguration = {
|
|
direction: $direction,
|
|
rtlMoveVisually: true,
|
|
};
|
|
|
|
let codeMirror: CodeMirror.EditorFromTextArea;
|
|
$: codeMirror?.setOption("direction", $direction);
|
|
|
|
function setValue(content: string): void {
|
|
codeMirror.setValue(content);
|
|
}
|
|
|
|
const { subscribe, unsubscribe } = storeSubscribe(code, setValue, false);
|
|
const dispatch = createEventDispatcher();
|
|
|
|
function openCodeMirror(textarea: HTMLTextAreaElement): void {
|
|
codeMirror = CodeMirrorLib.fromTextArea(textarea, {
|
|
...defaultConfiguration,
|
|
...configuration,
|
|
});
|
|
|
|
// TODO passing in the tabindex option does not do anything: bug?
|
|
codeMirror.getInputField().tabIndex = 0;
|
|
|
|
codeMirror.on("change", () => dispatch("change", codeMirror.getValue()));
|
|
codeMirror.on("focus", () => {
|
|
unsubscribe();
|
|
dispatch("focus");
|
|
});
|
|
codeMirror.on("blur", () => {
|
|
subscribe();
|
|
dispatch("blur");
|
|
});
|
|
|
|
subscribe();
|
|
}
|
|
|
|
export const api = Object.create(
|
|
{},
|
|
{
|
|
editor: { get: () => codeMirror },
|
|
},
|
|
) as CodeMirrorAPI;
|
|
</script>
|
|
|
|
<div class="code-mirror">
|
|
<textarea tabindex="-1" hidden use:openCodeMirror />
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
.code-mirror :global(.CodeMirror) {
|
|
height: auto;
|
|
border-radius: 0 0 5px 5px;
|
|
padding: 6px 0;
|
|
}
|
|
</style>
|