start working on Quick Code, setting up adding the tab bar

pull/67/head
dperolio 3 years ago
parent 9380fc3f5e
commit 71b8e6eaaf
No known key found for this signature in database
GPG Key ID: 3E9BBAA710D3DDCE

@ -61,7 +61,7 @@ export default memo(props => {
return (
<Editor
wrapperClassName='vz-quick-code-wrapper'
wrapperClassName='vz-quick-code-editor-wrapper'
className='vz-quick-code-editor'
language='scss'
value={value}

@ -1,87 +0,0 @@
import React, { useEffect, useState, useRef } from 'react';
import { createElement } from '@vizality/util/dom';
const version = '0.21.2';
// Memo might cause issues with popouts, so not memoizing this
export default function MonacoEditor (props) {
const { height, width, wrapperClassName, className, language, value, theme, editorDidMount, loading, options, popout } = props;
const windowRef = useRef(popout ? null : window)
const containerRef = useRef()
const editorRef = useRef();
const [ isLoading, setLoading ] = useState(true)
const [ isMounted, setMounted ] = useState(false)
function setupMonaco () {
if (!containerRef.current) return
const win = windowRef.current
console.log(win)
if (!win.MonacoEnvironment?.getWorkerUrl) {
Object.defineProperty(win, "MonacoEnvironment", {
value: {
getWorkerUrl: function() {
return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
self.MonacoEnvironment = {
baseUrl: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${version}/min'
};
importScripts('https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${version}/min/vs/base/worker/workerMain.min.js');`
)}`;
}
}
});
}
const commonjsLoader = window.require;
// if (!win.document.getElementById('monaco-styles')) {
// const styles = createElement('link', {
// id: 'monaco-styles',
// rel: 'stylesheet',
// href: `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${version}/min/vs/editor/editor.main.min.css`
// })
// win.document.head.appendChild(styles)
// }
function loadMonaco (monaco) {
setLoading(false)
const editor = monaco.editor.create(containerRef.current, {
extraEditorClassName: className,
language,
value,
theme,
dimension: height && width && {height, width},
...options
})
editorDidMount(editor.getValue.bind(editor), editor, containerRef.current.childNodes[0])
}
if (!win.document.getElementById('monaco-script')) {
const script = createElement('script', {
id: 'monaco-script',
src: `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${version}/min/vs/loader.min.js`,
onload: () => {
const amdLoader = win.require; // Grab Monaco's amd loader
win.require = commonjsLoader; // Revert to commonjs
amdLoader.config({paths: {vs: `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${version}/min/vs`}});
amdLoader(["vs/editor/editor.main"], loadMonaco)
}
})
win.document.head.appendChild(script)
} else {
loadMonaco(win.monaco)
}
}
useEffect(() => () => editorRef.current?.dispose(), [])
return (
<div
className={wrapperClassName}
ref={(div) => {
if (!div || isMounted) return
if (popout) windowRef.current = div.ownerDocument.defaultView;
containerRef.current = div;
setMounted(true)
setupMonaco()
}}
>
{isLoading && loading}
</div>
);
};

@ -7,9 +7,10 @@ import Editor from './Editor';
const QuickCode = memo(props => {
return (
<>
<div className='vz-quick-code-wrapper'>
<div className='vz-quick-code-tab-bar'></div>
<Editor {...props} />
</>
</div>
);
});

@ -8,3 +8,21 @@
align-items: center;
justify-content: center;
}
.vz-quick-code-wrapper {
display: flex;
flex-direction: column;
flex: 1;
margin: 10px 0;
}
.vz-quick-code-tab-bar {
background: var(--background-secondary-alt);
width: 100%;
height: 50px;
border-radius: 8px 8px 0 0;
flex: 1 0 auto;
border-bottom: none;
box-sizing: border-box;
border-bottom: 1px solid var(--background-tertiary);
}

@ -1,13 +1,13 @@
@use '@vizality' as vz;
:root {
--vz-editor-background: var(--deprecated-card-bg);
--vz-editor-border-radius: 4px;
--vz-editor-background: var(--background-secondary);
--vz-editor-border-radius: 0 0 8px 8px;
--vz-editor-context-menu-box-shadow: var(--elevation-high);
--vz-editor-context-menu-background: var(--background-floating);
--vz-editor-context-menu-border-radius: 4px;
--vz-editor-context-menu-font-family: Whitney, 'Helvetica Neue', Helvetica, Arial, sans-serif;
--vz-editor-context-menu-font-family: var(--font-primary);
--vz-editor-context-menu-item-color: var(--interactive-normal);
--vz-editor-context-menu-item-padding: 8px 12px;
@ -25,21 +25,30 @@
--vz-editor-minimap-background: var(--vz-editor-background);
--vz-editor-current-line-indicator-border-color: var(--background-secondary);
--vz-editor-current-line-indicator-border-color: var(--background-secondary-alt);
--vz-editor-current-line-indicator-border-width: 2px;
--vz-editor-current-line-indicator-border-style: solid;
}
.vz-editor-wrapper {
height: 100%;
padding: 20px 0;
background: var(--vz-editor-background);
border-radius: var(--vz-editor-border-radius);
overflow: hidden;
}
.vz-popup-content-wrapper .vz-editor-wrapper {
height: 100%;
width: 100%;
@include vz.size(100%);
}
/**
* Editor code content area
*/
.monaco-scrollable-element.editor-scrollable {
margin-left: 20px;
> .monaco-editor-background {
margin-top: 20px;
}
}
.monaco-editor {
@ -51,7 +60,9 @@
.line-numbers {
color: var(--vz-editor-line-numbers-color) !important;
}
// Little color boxes
/**
* Little color boxes
*/
[class*='ced-colorBox'] {
vertical-align: middle;
&::before {
@ -60,16 +71,24 @@
box-shadow: var(--elevation-medium);
}
}
/**
* Line numbers gutter
*/
.margin {
padding: 20px 0 0;
background: var(--background-message-hover) !important;
border-right: 1px solid var(--background-secondary-alt);
}
&-background,
// Line numbers gutter
.margin,
.inputarea.ime-input {
background: none !important;
}
.scroll-decoration {
display: none;
}
// Current line indecator
/**
* Current line indecator
*/
.view-overlays .current-line {
border:
var(--vz-editor-current-line-indicator-border-width)
@ -85,7 +104,9 @@
}
}
// Overview ruler
/**
* Overview ruler
*/
.decorationsOverviewRuler {
opacity: .5 !important;
right: 4px !important;

Loading…
Cancel
Save