fix: generator type errors that caused preview event error

This commit is contained in:
helloqian12138 2021-12-14 17:47:57 +08:00
parent 2ad317f623
commit 91df163d16
5 changed files with 24 additions and 14 deletions

View File

@ -29,6 +29,7 @@
"babel-eslint": "^10.1.0",
"babel-plugin-import": "^1.13.3",
"drip-table": "link:packages/drip-table",
"drip-table-generator": "link:packages/drip-table-generator",
"dumi": "^1.1.35",
"eslint-config-lvmcn": "0.0.30",
"eslint-formatter-pretty": "4.0.0",

View File

@ -4,22 +4,13 @@ import { ColumnConfig, DripTableRecordTypeBase, DripTableSchema } from 'drip-tab
import zhCN from 'antd/lib/locale/zh_CN';
import { Ctx } from '@/context';
import { DripTableGeneratorProps } from '@/typing';
import { defaultState, DripTableGeneratorState, GlobalStore } from '@/store';
import { DripTableGeneratorProps, DripTableGeneratorHandler } from '@/typing';
import { defaultState, GlobalStore } from '@/store';
import Wrapper from './wrapper';
import 'antd/dist/antd.less';
export interface DripTableGeneratorHandle extends DripTableGeneratorState {
/**
*
*
* @returns { DripTableSchema } DripTableSchema配置
*/
getSchemaValue: () => DripTableSchema;
}
const useTableRoot = (props, store, wrapper) => {
const [state, setState] = store;
@ -54,7 +45,7 @@ const useTableRoot = (props, store, wrapper) => {
return context;
};
const Container = <RecordType extends DripTableRecordTypeBase>(props: DripTableGeneratorProps<RecordType>, ref: React.ForwardedRef<DripTableGeneratorHandle>) => {
const Container = <RecordType extends DripTableRecordTypeBase>(props: DripTableGeneratorProps<RecordType>, ref: React.ForwardedRef<DripTableGeneratorHandler>) => {
const wrapper = useRef({});
const initialState = defaultState();
const store = useState(initialState);

View File

@ -57,7 +57,7 @@ const ToolLayout = (props: { store: GlobalStore }) => {
<Button
style={{ margin: '0 12px' }}
size="small"
onClick={() => { globalActions.toogleEditMode(store); }}
onClick={() => { globalActions.toggleEditMode(store); }}
>
{ state.isEdit ? '预览模式' : '编辑模式' }
</Button>

View File

@ -47,7 +47,15 @@ export type GlobalStoreObject = {
setState: React.Dispatch<React.SetStateAction<DripTableGeneratorState>>;
};
export const globalActions: Record<string, (store?: GlobalStoreObject) => void> = {
export type GlobalActions = {
toggleEditMode: (store?: GlobalStoreObject) => void;
editColumns: (store?: GlobalStoreObject) => void;
checkColumn: (store?: GlobalStoreObject) => void;
updateDataSource: (store?: GlobalStoreObject) => void;
updateGlobalConfig: (store?: GlobalStoreObject) => void;
}
export const globalActions: GlobalActions = {
toggleEditMode(store) {
store?.setState({ ...store.state, isEdit: !store.state.isEdit });
},

View File

@ -1,5 +1,6 @@
import { CSSProperties } from 'react';
import { DataSchema, DripTableSchema, EventLike, DripTableProps, DripTableDriver, DripTableRecordTypeBase } from 'drip-table';
import { DripTableGeneratorState } from './store';
/** 组件属性的表单配置项 */
export type DTGComponentPropertySchema = DataSchema & {
@ -40,6 +41,15 @@ export interface DripTableComponentConfig {
icon?: string;
}
export interface DripTableGeneratorHandler extends DripTableGeneratorState {
/**
*
*
* @returns { DripTableSchema } DripTableSchema配置
*/
getSchemaValue: () => DripTableSchema;
}
export interface DripTableGeneratorProps<RecordType extends DripTableRecordTypeBase, CustomComponentEvent extends EventLike = never, Ext = unknown> {
style?: CSSProperties;
driver?: DripTableDriver<RecordType>;