Skip to content
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
1 change: 1 addition & 0 deletions src/components/GridLayout/GridLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
31 changes: 17 additions & 14 deletions src/components/Item/Item.js → src/components/Item/Item.tsx
Original file line number Diff line number Diff line change
@@ -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<PluginWidgetProps, 'onBeforeLoad'>;
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<ItemProps> = ({
registerManager,
rendererProps,
type,
Expand Down Expand Up @@ -50,6 +62,8 @@ const Item = ({
});
};
}

return undefined;
}, []);

const onLoad = React.useCallback(() => {
Expand Down Expand Up @@ -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);
12 changes: 9 additions & 3 deletions src/typings/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@ export interface PluginWidgetProps<T = StringParams> {

export type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;

export type PluginRef = React.RefObject<any> | Record<string, unknown>;
export type PluginRef = object | null;

export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
defaultLayout?: PluginDefaultLayout;
renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
renderer: (
props: P,
forwardedRef: ((instance: PluginRef) => void) | undefined,
) => React.ReactNode;
placeholderRenderer?: (
props: P,
forwardedRef: ((instance: PluginRef) => void) | undefined,
) => React.ReactNode;
}
Loading