-
-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1558d4
commit 1b94a2c
Showing
12 changed files
with
275 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
export const initEditor = (monaco) => { | ||
monaco.languages.register({ id: 'mermaid' }); | ||
|
||
// Register a tokens provider for the language | ||
monaco.languages.setMonarchTokensProvider('mermaid', { | ||
typeKeywords: [ | ||
'graph', | ||
'stateDiagram', | ||
'sequenceDiagram', | ||
'classDiagram', | ||
'pie', | ||
'flowchart', | ||
'gantt' | ||
], | ||
keywords: ['patricipant', 'as'], | ||
arrows: ['---', '===', '-->', '==>'], | ||
|
||
tokenizer: { | ||
root: [ | ||
[/[{}]/, 'delimiter.bracket'], | ||
[/[a-z_$][\w$]*/, { cases: { '@typeKeywords': 'keyword', '@keywords': 'keyword' } }], | ||
[/[-=>ox]+/, { cases: { '@arrows': 'transition' } }], | ||
[/[\[\{\(}]+.+?[\)\]\}]+/, 'string'], | ||
[/\".*\"/, 'string'] | ||
] | ||
}, | ||
whitespace: [ | ||
[/[ \t\r\n]+/, 'white'], | ||
[/\%\%.*$/, 'comment'] | ||
] | ||
}); | ||
|
||
monaco.editor.defineTheme('myCoolTheme', { | ||
base: 'vs', | ||
inherit: false, | ||
rules: [ | ||
{ token: 'keyword', foreground: '880000', fontStyle: 'bold' }, | ||
{ token: 'custom-error', foreground: 'ff0000', fontStyle: 'bold' }, | ||
{ token: 'string', foreground: 'AA8500' }, | ||
{ token: 'transition', foreground: '008800', fontStyle: 'bold' }, | ||
{ token: 'delimiter.bracket', foreground: '000000', fontStyle: 'bold' } | ||
] | ||
}); | ||
|
||
// Register a completion item provider for the new language | ||
monaco.languages.registerCompletionItemProvider('mermaid', { | ||
provideCompletionItems: () => { | ||
var suggestions = [ | ||
{ | ||
label: 'simpleText', | ||
kind: monaco.languages.CompletionItemKind.Text, | ||
insertText: 'simpleText' | ||
}, | ||
{ | ||
label: 'testing', | ||
kind: monaco.languages.CompletionItemKind.Keyword, | ||
insertText: 'testing(${1:condition})', | ||
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet | ||
}, | ||
{ | ||
label: 'ifelse', | ||
kind: monaco.languages.CompletionItemKind.Snippet, | ||
insertText: ['if (${1:condition}) {', '\t$0', '} else {', '\t', '}'].join('\n'), | ||
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, | ||
documentation: 'If-Else Statement' | ||
} | ||
]; | ||
return { suggestions: suggestions }; | ||
} | ||
}); | ||
}; | ||
|
||
export const getResizeHandler = (editor) => { | ||
return (node) => editor && editor.layout(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const errorStore = writable(undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Mermaid } from 'mermaid'; | ||
|
||
let mer: Mermaid; | ||
export const getMermaid = async (): Promise<Mermaid> => { | ||
if (!mer) { | ||
mer = await import('mermaid'); | ||
} | ||
return mer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { loadState } from './state'; | ||
|
||
export const loadStateFromURL = (): void => { | ||
debugger; | ||
loadState(window.location.hash); | ||
loadState(window.location.hash.slice(1)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts"> | ||
import { errorStore } from '$lib/Util/error'; | ||
import { getMermaid } from '$lib/Util/mermaid'; | ||
import { codeStore } from '$lib/Util/state'; | ||
import { onMount } from 'svelte'; | ||
let container; | ||
export let code = ''; | ||
export let errorClass = ''; | ||
onMount(async () => { | ||
const mermaid = await getMermaid(); | ||
codeStore.subscribe((state) => { | ||
try { | ||
if (container && state) { | ||
// Replacing special characters '<' and '>' with encoded '<' and '>' | ||
code = state.code; //.replace(/</g, '<').replace(/>/g, '>'); | ||
container.innerHTML = code; | ||
delete container.dataset.processed; | ||
mermaid.initialize(Object.assign({}, state.mermaid)); | ||
mermaid.init(undefined, container); | ||
mermaid.render('graph-div', code, insertSvg); | ||
} | ||
} catch (e) { | ||
console.log('view fail', e); | ||
errorClass = 'error'; | ||
} | ||
}); | ||
errorStore.subscribe((error) => { | ||
if (typeof error === 'undefined') { | ||
errorClass = ''; | ||
} else { | ||
errorClass = 'error'; | ||
console.log('Error: ', error); | ||
} | ||
}); | ||
}); | ||
let insertSvg = function (svgCode, bindFunctions) {}; | ||
</script> | ||
|
||
<div id="view" class={`p-4 ${errorClass}`}> | ||
<div bind:this={container} class="flex-grow overflow-auto" /> | ||
</div> | ||
|
||
<style> | ||
#view { | ||
border: 1px solor darkred; | ||
flex: 1; | ||
} | ||
.error { | ||
opacity: 0.5; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.