Skip to content

Commit 2a1fac2

Browse files
committed
0.0.13
1 parent 9c742d5 commit 2a1fac2

File tree

7 files changed

+379
-101
lines changed

7 files changed

+379
-101
lines changed

imports/cyto.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

imports/editor.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { useColorMode } from '@chakra-ui/react';
2+
import dynamic from 'next/dynamic';
3+
import React from 'react';
4+
import _ from 'lodash';
5+
import { OnMount } from '@monaco-editor/react';
6+
7+
const MonacoEditor = dynamic(() => import('@monaco-editor/react').then(m => m.default), { ssr: false });
8+
9+
const monacoEditorOptions = {
10+
wordWrap: true,
11+
}
12+
13+
interface IEditor {
14+
refEditor?: any;
15+
value?: any;
16+
onChange?: (value: string) => void;
17+
onSave?: (value: string) => void;
18+
onClose?: () => void;
19+
onExit?: () => void;
20+
minimap?: boolean;
21+
lineNumbers?: string;
22+
defaultLanguage?: string;
23+
onMount?: (editor: any, monaco: any) => any;
24+
}
25+
26+
export const Editor = React.memo(({
27+
refEditor = { current: undefined },
28+
value = '',
29+
onChange,
30+
onSave,
31+
onClose,
32+
onExit,
33+
minimap = true,
34+
lineNumbers = 'on',
35+
defaultLanguage="javascript",
36+
onMount,
37+
}:IEditor) => {
38+
const refValue = React.useRef(value);
39+
refValue.current = value;
40+
41+
const { colorMode } = useColorMode();
42+
const handleEditorDidMount: OnMount = (editor, monaco) => {
43+
refEditor.current = { editor, monaco };
44+
editor.getModel().updateOptions({ tabSize: 2 });
45+
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, () => {
46+
onSave && onSave(refValue.current);
47+
});
48+
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyE, () => {
49+
onClose && onClose();
50+
});
51+
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Escape, () => {
52+
onExit && onExit();
53+
});
54+
onMount && onMount(editor, monaco);
55+
}
56+
57+
return (<MonacoEditor
58+
options={{
59+
...monacoEditorOptions,
60+
minimap: {
61+
enabled: minimap
62+
},
63+
// @ts-ignore
64+
lineNumbers: lineNumbers,
65+
}}
66+
height="100%"
67+
width="100%"
68+
theme={colorMode === 'light' ? 'light' : "vs-dark"}
69+
defaultLanguage={defaultLanguage}
70+
defaultValue={_.toString(value) || ''}
71+
onChange={onChange}
72+
onMount={handleEditorDidMount}
73+
/>)
74+
})

imports/link.tsx

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import {
22
Box,
3-
Button
3+
Button,
4+
Heading,
5+
Text,
46
} from '@chakra-ui/react';
7+
import { useDeep } from "@deep-foundation/deeplinks/imports/client";
58
import { Id } from '@deep-foundation/deeplinks/imports/minilinks';
69

710
export const LinkButton = ({
8-
id, name, type, icon, isActive, onClick,
11+
id, name: _name, type: _type, icon, isActive, onClick,
912
buttonRef,
1013
...props
1114
}: {
1215
id: Id;
1316
name?: string;
14-
type: string;
17+
type?: string;
1518
icon: string;
1619
isActive: boolean;
1720
onClick?: (id: Id) => void;
@@ -20,20 +23,40 @@ export const LinkButton = ({
2023

2124
[key: string]: any;
2225
}) => {
26+
const deep = useDeep();
27+
const link = deep?.minilinks?.byId[id];
28+
const name = _name || deep.nameLocal(id);
29+
const type = _type || deep.nameLocal(link?.type_id);
2330
return <Button
2431
ref={buttonRef}
25-
h='3em' variant={isActive ? 'active' : 'solid'}
32+
variant={isActive ? 'active' : 'solid'}
2633
onClick={(e) => {
2734
e.stopPropagation();
2835
e.preventDefault();
2936
onClick && onClick(id);
3037
}}
3138
justifyContent={'left'}
39+
h='auto' pt={2} pb={2}
3240
{...props}
3341
>
34-
{icon} <Box textAlign='left' pl='0.5em'>
42+
{icon} <Box textAlign='left' pl='0.5em' w='100%' overflow='hidden'>
3543
{!!((name) || (type)) && <Box fontSize="sm">{name || type}</Box>}
3644
<Box fontSize="xxs">{name ? type : ''} {id}</Box>
45+
{!!props?.children && props.children}
46+
{!!link?.value && <>
47+
<Text fontSize="xxs" opacity={0.5}>value:</Text>
48+
<Text fontSize="xs">
49+
{typeof(link?.value?.value) == 'string' && <>
50+
<Heading as='pre' fontSize='xs' noOfLines={1} w='100%'>{link?.value?.value}</Heading>
51+
</>}
52+
{typeof(link?.value?.value) == 'number' && <>
53+
<Heading as='pre' fontSize='xs' noOfLines={1} w='100%'>{link?.value?.value}</Heading>
54+
</>}
55+
{typeof(link?.value?.value) == 'object' && <>
56+
<Heading as='pre' fontSize='xs' noOfLines={1} w='100%'>{JSON.stringify(link?.value?.value)}</Heading>
57+
</>}
58+
</Text>
59+
</>}
3760
</Box>
3861
</Button>;
3962
};

0 commit comments

Comments
 (0)