diff --git a/src/components/GridLayout/GridLayout.tsx b/src/components/GridLayout/GridLayout.tsx index 30b16cb..515ee73 100644 --- a/src/components/GridLayout/GridLayout.tsx +++ b/src/components/GridLayout/GridLayout.tsx @@ -31,6 +31,7 @@ import type { const hasPluginId = (value: PluginRef): value is {props: {id: string}} => { return ( + value !== null && 'props' in value && typeof value.props === 'object' && value.props !== null && diff --git a/src/components/Item/Item.js b/src/components/Item/Item.tsx similarity index 79% rename from src/components/Item/Item.js rename to src/components/Item/Item.tsx index 4fa6c7f..9112087 100644 --- a/src/components/Item/Item.js +++ b/src/components/Item/Item.tsx @@ -1,16 +1,28 @@ import React from 'react'; -import PropTypes from 'prop-types'; - import {prepareItem} from '../../hocs/prepareItem'; +import type {ConfigItem} from '../../shared/types'; +import type {PluginRef, PluginWidgetProps} from '../../typings'; import {cn} from '../../utils/cn'; +import type {RegisterManager} from '../../utils/register-manager'; import './Item.scss'; const b = cn('dashkit-item'); +type ItemProps = { + registerManager: RegisterManager; + rendererProps: Omit; + type: string; + isPlaceholder?: boolean; + forwardedPluginRef?: (pluginRef: PluginRef) => void; + onItemRender?: (item: ConfigItem) => void; + onItemMountChange?: (item: ConfigItem, meta: {isAsync: boolean; isMounted: boolean}) => void; + item: ConfigItem; +}; + // TODO: getDerivedStateFromError и заглушка с ошибкой -const Item = ({ +const Item: React.FC = ({ registerManager, rendererProps, type, @@ -50,6 +62,8 @@ const Item = ({ }); }; } + + return undefined; }, []); const onLoad = React.useCallback(() => { @@ -88,15 +102,4 @@ const Item = ({ ); }; -Item.propTypes = { - forwardedPluginRef: PropTypes.any, - rendererProps: PropTypes.object, - registerManager: PropTypes.object, - type: PropTypes.string, - isPlaceholder: PropTypes.bool, - onItemRender: PropTypes.func, - onItemMountChange: PropTypes.func, - item: PropTypes.object, -}; - export default prepareItem(Item); diff --git a/src/typings/plugin.ts b/src/typings/plugin.ts index 3d8e327..84d06e7 100644 --- a/src/typings/plugin.ts +++ b/src/typings/plugin.ts @@ -41,10 +41,16 @@ export interface PluginWidgetProps { export type PluginDefaultLayout = Partial>; -export type PluginRef = React.RefObject | Record; +export type PluginRef = object | null; export interface Plugin

= any, T = StringParams> extends PluginBase { defaultLayout?: PluginDefaultLayout; - renderer: (props: P, forwardedRef: React.RefObject) => React.ReactNode; - placeholderRenderer?: (props: P, forwardedRef: React.RefObject) => React.ReactNode; + renderer: ( + props: P, + forwardedRef: ((instance: PluginRef) => void) | undefined, + ) => React.ReactNode; + placeholderRenderer?: ( + props: P, + forwardedRef: ((instance: PluginRef) => void) | undefined, + ) => React.ReactNode; }