fix: hide the event type in the API form's handlers

This commit is contained in:
MrWindlike 2022-03-18 10:54:38 +08:00
parent 1b1df68fc9
commit 16824e29f7
2 changed files with 8 additions and 6 deletions

View File

@ -1,7 +1,8 @@
import React from 'react';
import { EventWidget, mergeWidgetOptionsIntoSchema } from '@sunmao-ui/editor-sdk';
import { EventWidget } from '@sunmao-ui/editor-sdk';
import { Box, IconButton, VStack } from '@chakra-ui/react';
import { Static } from '@sinclair/typebox';
import { JSONSchema7 } from 'json-schema';
import { CloseIcon } from '@chakra-ui/icons';
import { EventHandlerSchema } from '@sunmao-ui/runtime';
import { ComponentSchema } from '@sunmao-ui/core';
@ -13,19 +14,19 @@ type Props = {
handler: Static<typeof EventHandlerSchema>;
onChange: (handler: Static<typeof EventHandlerSchema>) => void;
onRemove: () => void;
hideEventType?: boolean;
services: EditorServices;
schema?: JSONSchema7;
};
export const EventHandlerForm: React.FC<Props> = props => {
const { handler, component, onChange, onRemove, hideEventType, services } = props;
const { schema = EventHandlerSchema, handler, component, onChange, onRemove, services } = props;
return (
<Box position="relative" width="100%">
<VStack className={formWrapperCSS}>
<EventWidget
component={component}
schema={mergeWidgetOptionsIntoSchema(EventHandlerSchema, { hideEventType })}
schema={schema}
value={handler}
path={[]}
level={1}

View File

@ -19,8 +19,9 @@ import { EventHandlerForm } from '../../ComponentForm/EventTraitForm/EventHandle
import {
FetchTraitPropertiesSchema,
EventCallBackHandlerSchema,
BaseEventSchema
} from '@sunmao-ui/runtime';
import { Static } from '@sinclair/typebox';
import { Static, Type } from '@sinclair/typebox';
import { EditorServices } from '../../../types';
import { ComponentSchema } from '@sunmao-ui/core';
@ -94,7 +95,7 @@ export const Basic: React.FC<Props> = props => {
<EventHandlerForm
component={api}
handler={{ type: '', ...handler }}
hideEventType={true}
schema={Type.Object(BaseEventSchema)}
onChange={onChange}
onRemove={onRemove}
services={services}