budibase/packages/bbui/src/Markdown/SpectrumMDE.svelte

120 lines
3.8 KiB
Svelte
Raw Normal View History

2022-02-02 16:17:59 +01:00
<script>
import EasyMDE from "easymde"
import "easymde/dist/easymde.min.css"
import { onMount } from "svelte"
export let height = "300px"
export let scroll = true
2022-02-02 16:17:59 +01:00
export let easyMDEOptions = null
export let mde = null
export let id = null
2022-02-02 16:17:59 +01:00
let element
onMount(() => {
height = height || "300px"
mde = new EasyMDE({
element,
spellChecker: false,
status: false,
unorderedListStyle: "-",
maxHeight: scroll ? height : undefined,
minHeight: scroll ? undefined : height,
hideIcons: ["fullscreen", "side-by-side"],
2022-02-02 16:17:59 +01:00
...easyMDEOptions,
})
// Revert the editor when we unmount
return () => {
mde.toTextArea()
}
})
</script>
<textarea {id} bind:this={element} />
2022-02-02 16:17:59 +01:00
<style>
/* Toolbar container */
:global(.EasyMDEContainer .editor-toolbar) {
background: var(--spectrum-global-color-gray-50);
border-top: 1px solid var(--spectrum-alias-border-color);
border-left: 1px solid var(--spectrum-alias-border-color);
border-right: 1px solid var(--spectrum-alias-border-color);
2022-02-02 16:17:59 +01:00
}
/* Main code mirror instance and default color */
:global(.EasyMDEContainer .CodeMirror) {
border: 1px solid var(--spectrum-alias-border-color);
background: var(--spectrum-global-color-gray-50);
color: var(--spectrum-alias-text-color);
2022-02-02 16:17:59 +01:00
}
/* Toolbar button active state */
:global(.EasyMDEContainer .editor-toolbar button.active) {
background: var(--spectrum-global-color-gray-200);
border-color: var(--spectrum-global-color-gray-400);
}
/* Toolbar button hover state */
:global(.EasyMDEContainer .editor-toolbar button:hover) {
background: var(--spectrum-global-color-gray-200);
border-color: var(--spectrum-global-color-gray-400);
}
/* Toolbar button color */
:global(.EasyMDEContainer .editor-toolbar button i) {
color: var(--spectrum-global-color-gray-800);
}
/* Separator between toolbar buttons*/
:global(.EasyMDEContainer .editor-toolbar i.separator) {
border-color: var(--spectrum-global-color-gray-300);
}
/* Cursor */
:global(.EasyMDEContainer .CodeMirror-cursor) {
border-color: var(--spectrum-alias-text-color);
2022-02-02 16:17:59 +01:00
}
/* Text selections */
:global(.EasyMDEContainer .CodeMirror-selectedtext) {
background: var(--spectrum-global-color-gray-400) !important;
2022-02-02 16:17:59 +01:00
}
/* Background of lines containing selected text */
:global(.EasyMDEContainer .CodeMirror-selected) {
background: var(--spectrum-global-color-gray-400) !important;
}
/* Color of text for images and links */
:global(.EasyMDEContainer .cm-s-easymde .cm-link) {
color: var(--spectrum-global-color-gray-600);
}
/* Color of URL for images and links */
:global(.EasyMDEContainer .cm-s-easymde .cm-url) {
color: var(--spectrum-global-color-gray-500);
}
/* Full preview window */
:global(.EasyMDEContainer .editor-preview) {
background: var(--spectrum-global-color-gray-50);
2022-02-02 16:17:59 +01:00
}
/* Side by side preview window */
:global(.EasyMDEContainer .editor-preview) {
border: 1px solid var(--spectrum-alias-border-color);
2022-02-02 16:17:59 +01:00
}
/* Code blocks in editor */
:global(.EasyMDEContainer .cm-s-easymde .cm-comment) {
background: var(--spectrum-global-color-gray-100);
}
/* Code blocks in preview */
:global(.EasyMDEContainer .editor-preview pre) {
background: var(--spectrum-global-color-gray-100);
padding: 4px;
border-radius: 4px;
}
:global(.EasyMDEContainer .editor-preview code) {
color: #e83e8c;
}
:global(.EasyMDEContainer .editor-preview pre code) {
color: var(--spectrum-alias-text-color);
}
/* Block quotes */
:global(.EasyMDEContainer .editor-preview blockquote) {
border-left: 4px solid var(--spectrum-global-color-gray-400);
color: var(--spectrum-global-color-gray-700);
margin-left: 0;
padding-left: 20px;
}
2022-02-02 16:17:59 +01:00
</style>