Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): add convenient eval input #718

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,26 @@ export const ExpressionEditor = React.forwardRef<
},
}));

const evaledValueElement = (
<Box
width="100%"
padding="8px"
maxHeight="128px"
background={error ? '#fef1f0' : '#d4eadd'}
color={error ? '#c04035' : '#3b734f'}
borderColor={error ? '#f7d6d4' : '#72b98e'}
borderStyle="solid"
borderWidth="1px"
borderRadius="0 0 4px 4px"
whiteSpace="pre-wrap"
>
<Box fontWeight="bold" marginBottom="4px">
{error ? 'Error' : getTypeString(evaledValue?.value)}
</Box>
{error || JSON.stringify(evaledValue?.value, null, 2)}
</Box>
);

return (
<Box className={wrapperStyle}>
{/* Force re-render CodeMirror when editted in modal, since it's not reactive */}
Expand Down Expand Up @@ -404,25 +424,13 @@ export const ExpressionEditor = React.forwardRef<
{isFocus ? (
<Box
width="100%"
padding="8px"
maxHeight="128px"
overflow="auto"
position="absolute"
bottom="0"
zIndex={4}
transform="translateY(100%)"
background={error ? '#fef1f0' : '#d4eadd'}
color={error ? '#c04035' : '#3b734f'}
borderColor={error ? '#f7d6d4' : '#72b98e'}
borderStyle="solid"
borderWidth="1px"
borderRadius="0 0 4px 4px"
whiteSpace="pre-wrap"
>
<Box fontWeight="bold" marginBottom="4px">
{error ? 'Error' : getTypeString(evaledValue?.value)}
</Box>
{error || JSON.stringify(evaledValue?.value, null, 2)}
{evaledValueElement}
</Box>
) : null}
{showModal && (
Expand All @@ -445,6 +453,7 @@ export const ExpressionEditor = React.forwardRef<
isError={!!error}
/>
</Box>
{evaledValueElement}
</ModalBody>
<ModalFooter>
<Button size="sm" colorScheme="blue" onClick={onClose}>
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const Editor: React.FC<Props> = observer(
setIsDisplayLeftMenu={setIsDisplayLeftMenu}
setIsDisplayRightMenu={setIsDisplayRightMenu}
onCodeMode={() => setCodeMode(true)}
services={services}
/>
<Box display="flex" flex="1" overflow="auto">
{renderMain()}
Expand Down
28 changes: 26 additions & 2 deletions packages/editor/src/components/EditorHeader/EditorHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react';
import React, { useState } from 'react';
import { Flex, Button, Icon } from '@chakra-ui/react';
import { ExpressionWidget } from '@sunmao-ui/editor-sdk';
import { Type } from '@sinclair/typebox';
import { EditorServices } from '../../types';
const SideBarIcon: React.FC<{
transform?: string;
color?: string;
Expand All @@ -15,6 +18,13 @@ const SideBarIcon: React.FC<{
</Icon>
);

const MockComp = {
id: 'mock',
type: 'core/v1/dummy',
properties: {},
traits: [],
};

export const EditorHeader: React.FC<{
isDisplayLeftMenu: boolean;
isDisplayRightMenu: boolean;
Expand All @@ -23,6 +33,7 @@ export const EditorHeader: React.FC<{
onPreview: () => void;
onCodeMode: () => void;
onRefresh: () => void;
services: EditorServices;
}> = ({
onPreview,
onCodeMode,
Expand All @@ -31,10 +42,23 @@ export const EditorHeader: React.FC<{
setIsDisplayRightMenu,
isDisplayLeftMenu,
isDisplayRightMenu,
services,
}) => {
const [exp, setExp] = useState('');
return (
<Flex p={2} borderBottomWidth="2px" borderColor="gray.200" align="center">
<Flex flex="1" />
<Flex flex="1">
<ExpressionWidget
key={services.editorStore.selectedComponentId}
component={MockComp}
spec={Type.Any()}
services={services}
path={[]}
level={0}
value={exp}
onChange={v => setExp(v)}
/>
</Flex>
<Flex flex="1" align="center" justify="center">
<SideBarIcon
color={isDisplayLeftMenu ? '#000' : '#eee'}
Expand Down
Loading