Skip to content

Commit

Permalink
feat: expose function components
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-gorules committed Feb 7, 2025
1 parent 6d21b2f commit bff0cec
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const GraphPanel: React.FC = () => {
<Resizable
className={'grl-dg__panel'}
defaultSize={{ height: defaultHeight }}
handleClasses={{ top: 'grl-dg__resizeHandle grl-dg__resizeHandle__vertical' }}
handleStyles={{
bottom: { display: 'none' },
left: { display: 'none' },
Expand Down
47 changes: 4 additions & 43 deletions packages/jdm-editor/src/components/function/function-debugger.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ExportOutlined, FormatPainterOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Tabs, Tooltip, Typography } from 'antd';
import { FormatPainterOutlined } from '@ant-design/icons';
import { Button, Tabs, Tooltip } from 'antd';
import type { editor } from 'monaco-editor';
import React, { useMemo, useState } from 'react';
import React, { useState } from 'react';
import { match } from 'ts-pattern';

import typeScriptIcon from '../../assets/typescript.svg?inline';
import type { SimulationTrace, SimulationTraceDataFunction } from '../decision-graph/simulator/simulation.types';
import { FunctionDebuggerLog } from './function-debugger-log';
import { FunctionLibraryItem } from './function-library-item';
import { type FunctionLibrary } from './helpers/libs';

enum TabKey {
Expand Down Expand Up @@ -91,42 +91,3 @@ export const FunctionDebugger: React.FC<FunctionDebuggerProps> = ({ trace, edito
</div>
);
};

const FunctionLibraryItem: React.FC<{ lib: FunctionLibrary; onImport?: () => void; editorValue?: string }> = ({
lib,
onImport,
editorValue,
}) => {
const canImport = useMemo(() => {
if (!editorValue) {
return true;
}

return !editorValue.includes(`from "${lib.name}"`) && !editorValue.includes(`from '${lib.name}'`);
}, [lib.name, editorValue]);

return (
<div key={lib.name} className='grl-function__libraries__item'>
<img alt='TypeScript Library' src={typeScriptIcon} height={18} />
<Typography.Text strong>{lib.name}</Typography.Text>
<Typography.Text type='secondary' style={{ fontSize: 12, marginTop: 1.5 }}>
{lib.tagline}
</Typography.Text>
<div className='grl-function__libraries__item__actions'>
<Tooltip title='Import library' placement='bottomLeft'>
<Button type='text' size='small' icon={<PlusOutlined />} disabled={!canImport} onClick={onImport} />
</Tooltip>
<Tooltip title='Go to documentation' placement='bottomLeft'>
<Button
type='text'
size='small'
icon={<ExportOutlined />}
href={lib.documentationUrl}
target='_blank'
disabled={!lib.documentationUrl}
/>
</Tooltip>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ExportOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Tooltip, Typography } from 'antd';
import React, { useMemo } from 'react';

import typeScriptIcon from '../../assets/typescript.svg?inline';
import type { FunctionLibrary } from './helpers/libs';

type FunctionLibraryItemProps = {
lib: FunctionLibrary;
onImport?: () => void;
editorValue?: string;
};

export const FunctionLibraryItem: React.FC<FunctionLibraryItemProps> = ({ lib, onImport, editorValue }) => {
const canImport = useMemo(() => {
if (!editorValue) {
return true;
}

return !editorValue.includes(`from "${lib.name}"`) && !editorValue.includes(`from '${lib.name}'`);
}, [lib.name, editorValue]);

return (
<div key={lib.name} className='grl-function__libraries__item'>
<img alt='TypeScript Library' src={typeScriptIcon} height={18} />
<Typography.Text strong>{lib.name}</Typography.Text>
<Typography.Text type='secondary' style={{ fontSize: 12, marginTop: 1.5 }}>
{lib.tagline}
</Typography.Text>
<div className='grl-function__libraries__item__actions'>
<Tooltip title='Import library' placement='bottomLeft'>
<Button type='text' size='small' icon={<PlusOutlined />} disabled={!canImport} onClick={onImport} />
</Tooltip>
<Tooltip title='Go to documentation' placement='bottomLeft'>
<Button
type='text'
size='small'
icon={<ExportOutlined />}
href={lib.documentationUrl}
target='_blank'
disabled={!lib.documentationUrl}
/>
</Tooltip>
</div>
</div>
);
};
1 change: 1 addition & 0 deletions packages/jdm-editor/src/components/function/function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export const Function: React.FC<FunctionProps> = ({
const monacoOptions: editor.IStandaloneEditorConstructionOptions = {
automaticLayout: true,
contextmenu: false,
fixedOverflowWidgets: true,
fontSize: 13,
fontFamily: 'var(--mono-font-family)',
tabSize: 2,
Expand Down
4 changes: 2 additions & 2 deletions packages/jdm-editor/src/components/function/helpers/libs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const functionLibraries: FunctionLibrary[] = [
name: 'big.js',
tagline: 'Arbitrary-precision decimal arithmetic',
importName: 'Big',
typeDef: bigJs,
documentationUrl: 'https://mikemcl.github.io/big.js/',
typeDef: bigJs,
},
{
name: 'dayjs',
Expand All @@ -52,7 +52,7 @@ export const functionLibraries: FunctionLibrary[] = [
{
name: 'zod',
tagline: 'Schema validation',
importName: 'z',
importName: '{ z }',
typeDef: zod,
documentationUrl: 'https://zod.dev/',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/jdm-editor/src/components/function/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './function';
export { FunctionDebuggerLog } from './function-debugger-log';
export { FunctionLibraryItem } from './function-library-item';
60 changes: 60 additions & 0 deletions packages/jdm-editor/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,63 @@
margin: 0 !important;
}
}

[data-resize-handle] {
&::after {
content: '';
position: absolute;
display: block;
transition: .1s ease;
z-index: 999;
}

&[data-panel-group-direction="horizontal"]::after {
height: 100%;
width: 2px;
transform: translateX(-1px);
}

&[data-panel-group-direction="vertical"]::after {
height: 2px;
width: 100%;
transform: translateY(-1px);
}

&[data-resize-handle-state="hover"], &[data-resize-handle-state="drag"] {
&::after {
background: var(--grl-color-primary-hover);
}
}
}

.grl-dg__resizeHandle {
&__vertical {
&::after {
height: 2px;
width: 100%;
transform: translateY(-1px);
top: 50%;
}
}

&__horizontal {
&::after {
height: 100%;
width: 2px;
transform: translateX(-1px);
left: 50%;
}
}

&::after {
content: '';
position: absolute;
display: block;
transition: .1s ease;
z-index: 999;
}

&:hover::after {
background: var(--grl-color-primary-hover);
}
}
3 changes: 2 additions & 1 deletion packages/jdm-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"compilerOptions": {
"rootDir": "src",
"baseUrl": "..",
"allowJs": true
"allowJs": true,
"types": ["vite/client"]
},
"include": ["src", ".storybook"]
}
7 changes: 6 additions & 1 deletion packages/jdm-editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export default defineConfig({
formats: ['es'],
},
rollupOptions: {
external: ['react/jsx-runtime', 'react', 'react-dom', ...Object.keys(packageJson.dependencies)],
external: [
'react/jsx-runtime',
'react',
'react-dom',
...Object.keys(packageJson.dependencies).filter((s) => s !== 'antd`'),
],
output: {
globals: {
'react-dom': 'ReactDOM',
Expand Down

0 comments on commit bff0cec

Please sign in to comment.