chore: 解决递归依赖 (#11006)

This commit is contained in:
liaoxuezhi 2024-10-10 20:16:08 +08:00 committed by GitHub
parent de359199b8
commit fc0137ba3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import React from 'react';
import {autobind} from 'amis-core';
import {Icon} from '../icons';
import {SchemaEditorItemCommon} from './Common';
import {ITEMMAP, SchemaEditorItemCommon} from './Common';
import {SchemaEditorItem} from './Item';
import {Controller} from '../FormField';
@ -158,3 +158,5 @@ export class SchemaEditorItemArray extends SchemaEditorItemCommon {
);
}
}
ITEMMAP.array = SchemaEditorItemArray;

View File

@ -381,3 +381,7 @@ export class SchemaEditorItemCommon<
);
}
}
export const ITEMMAP: {
[propsName: string]: typeof SchemaEditorItemCommon;
} = {};

View File

@ -1,8 +1,10 @@
import React from 'react';
import {LocaleProps, ThemeProps} from 'amis-core';
import {SchemaEditorItemArray} from './Array';
import {SchemaEditorItemCommon, SchemaEditorItemCommonProps} from './Common';
import {SchemaEditorItemObject} from './Object';
import {
ITEMMAP,
SchemaEditorItemCommon,
SchemaEditorItemCommonProps
} from './Common';
export interface SchemaEditorItemProps
extends SchemaEditorItemCommonProps,
@ -14,16 +16,8 @@ export class SchemaEditorItem extends React.Component<SchemaEditorItemProps> {
const {value} = this.props;
// 动态Component要用大写开头的才会被识别
let Renderer = SchemaEditorItemCommon;
switch (value?.type) {
case 'object':
Renderer = SchemaEditorItemObject as any;
break;
case 'array':
Renderer = SchemaEditorItemArray as any;
break;
}
let Renderer =
(value?.type && ITEMMAP[value?.type as string]) || SchemaEditorItemCommon;
return (
<Renderer {...this.props} key={(value?.type as string) || 'string'} />

View File

@ -3,7 +3,7 @@ import {autobind, guid, JSONSchema} from 'amis-core';
import Button from '../Button';
import {Icon} from '../icons';
import InputBox from '../InputBox';
import {SchemaEditorItemCommon} from './Common';
import {ITEMMAP, SchemaEditorItemCommon} from './Common';
import {SchemaEditorItem} from './Item';
import type {SchemaEditorItemCommonProps} from './Common';
@ -531,3 +531,5 @@ export class SchemaEditorItemObject extends SchemaEditorItemCommon<
);
}
}
ITEMMAP.object = SchemaEditorItemObject;

View File

@ -16,6 +16,8 @@ import {SchemaEditorItem} from './Item';
import {schemaEditorItemPlaceholder} from './Common';
import type {JSONSchema7TypeName} from 'json-schema';
import type {SchemaEditorItemPlaceholder} from './Common';
import './Array';
import './Object';
export interface SchemaEditorProps extends LocaleProps, ThemeProps {
value?: JSONSchema;