@gravity-ui/dashkit 9.2.0 → 9.2.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/build/cjs/components/DashKit/DashKit.d.ts +1 -1
- package/build/cjs/components/GridLayout/GridLayout.d.ts +51 -65
- package/build/cjs/components/GridLayout/GridLayout.js +60 -17
- package/build/cjs/components/GridLayout/GridLayout.js.map +1 -1
- package/build/cjs/components/GridLayout/types.d.ts +60 -0
- package/build/cjs/components/GridLayout/types.js +3 -0
- package/build/cjs/components/GridLayout/types.js.map +1 -0
- package/build/cjs/components/MobileLayout/MobileLayout.d.ts +4 -4
- package/build/cjs/components/MobileLayout/MobileLayout.js.map +1 -1
- package/build/cjs/context/DashKitContext.d.ts +14 -6
- package/build/cjs/context/DashKitContext.js.map +1 -1
- package/build/cjs/typings/config.d.ts +2 -2
- package/build/cjs/typings/config.js.map +1 -1
- package/build/cjs/typings/plugin.d.ts +1 -0
- package/build/cjs/typings/plugin.js.map +1 -1
- package/build/esm/components/DashKit/DashKit.d.ts +1 -1
- package/build/esm/components/GridLayout/GridLayout.d.ts +51 -65
- package/build/esm/components/GridLayout/GridLayout.js +60 -17
- package/build/esm/components/GridLayout/GridLayout.js.map +1 -1
- package/build/esm/components/GridLayout/types.d.ts +60 -0
- package/build/esm/components/GridLayout/types.js +2 -0
- package/build/esm/components/GridLayout/types.js.map +1 -0
- package/build/esm/components/MobileLayout/MobileLayout.d.ts +4 -4
- package/build/esm/components/MobileLayout/MobileLayout.js.map +1 -1
- package/build/esm/context/DashKitContext.d.ts +14 -6
- package/build/esm/context/DashKitContext.js.map +1 -1
- package/build/esm/typings/config.d.ts +2 -2
- package/build/esm/typings/config.js.map +1 -1
- package/build/esm/typings/plugin.d.ts +1 -0
- package/build/esm/typings/plugin.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../../../../src","sources":["components/GridLayout/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {ReactGridLayoutProps} from 'src/typings';\n\nimport type {ConfigItem, ConfigLayout, ItemDragProps} from '../../shared';\n\nexport type GridLayoutProps = {\n ref?: React.ForwardedRef<unknown>;\n};\n\nexport type GridLayoutState = {\n isDragging: boolean;\n isDraggedOut: boolean;\n isPageHidden: boolean;\n currentDraggingElement: CurrentDraggingElement | null;\n draggedOverGroup: string | null;\n};\n\nexport type CurrentDraggingElement = {\n group: string;\n layoutItem: ConfigLayout;\n item: ConfigItem | ItemDragProps;\n cursorPosition: {\n offsetX: number;\n offsetY: number;\n };\n};\n\nexport type ReloadItemsOptions = {\n targetIds?: string[];\n force?: boolean;\n};\n\nexport type ManipulationCallbackArgs = {\n group: string;\n layout: ConfigLayout[];\n oldItem: ConfigLayout;\n newItem: ConfigLayout;\n placeholder: ConfigLayout;\n e: MouseEvent;\n element: HTMLElement;\n};\n\nexport type MemoGroupLayout = {\n key: string;\n layout: ConfigLayout[];\n};\n\ntype GroupCallback = (\n layout: ConfigLayout[],\n layoutItem: ConfigLayout,\n newItem: ConfigLayout,\n placeholder: ConfigLayout,\n event: MouseEvent,\n element: HTMLElement,\n) => void;\n\nexport type GroupCallbacks = {\n onDragStart: GroupCallback;\n onDrag: GroupCallback;\n onDragStop: GroupCallback;\n onResizeStart: GroupCallback;\n onResize: GroupCallback;\n onResizeStop: GroupCallback;\n onDrop: (layout: ConfigLayout[], item: ConfigLayout | undefined, e: MouseEvent) => void | false;\n onDropDragOver: (e: DragEvent | MouseEvent) => void | boolean;\n onDragTargetRestore: (group?: string) => void;\n};\n\nexport type AdjustWidgetLayoutParams = {\n widgetId: string;\n needSetDefault?: boolean;\n adjustedWidgetLayout?: ConfigLayout;\n};\n\nexport type LayoutAndPropsByGroup = {\n properties: Partial<ReactGridLayoutProps>;\n layout: ConfigLayout[];\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { PluginRef } from 'src/typings';
|
|
2
3
|
import { DashKitContext } from "../../context/index.js";
|
|
3
4
|
import { getSortedConfigItems } from "./helpers.js";
|
|
4
5
|
import "./MobileLayout.css";
|
|
@@ -6,21 +7,20 @@ type MobileLayoutProps = {};
|
|
|
6
7
|
type MobileLayoutState = {
|
|
7
8
|
itemsWithActiveAutoheight: Record<string, boolean>;
|
|
8
9
|
};
|
|
9
|
-
type PlugibRefObject = React.RefObject<any>;
|
|
10
10
|
export default class MobileLayout extends React.PureComponent<MobileLayoutProps, MobileLayoutState> {
|
|
11
11
|
static contextType: React.Context<import("../../context/index.js").DashKitCtxShape>;
|
|
12
12
|
context: React.ContextType<typeof DashKitContext>;
|
|
13
|
-
pluginsRefs:
|
|
13
|
+
pluginsRefs: PluginRef[];
|
|
14
14
|
sortedLayoutItems: Record<string, ReturnType<typeof getSortedConfigItems>> | null;
|
|
15
15
|
_memoLayout: import("../../index.js").ConfigLayout[];
|
|
16
|
-
_memoForwardedPluginRef: Array<(refObject:
|
|
16
|
+
_memoForwardedPluginRef: Array<(refObject: PluginRef) => void>;
|
|
17
17
|
_memoAdjustWidgetLayout: Record<string, (props: {
|
|
18
18
|
needSetDefault: boolean;
|
|
19
19
|
}) => void>;
|
|
20
20
|
state: MobileLayoutState;
|
|
21
21
|
render(): JSX.Element;
|
|
22
22
|
getSortedLayoutItems(): Record<string, (import("../../index.js").ConfigItem & import("../../index.js").ConfigLayout)[]>;
|
|
23
|
-
getMemoForwardRefCallback(refIndex: number): (refObject:
|
|
23
|
+
getMemoForwardRefCallback(refIndex: number): (refObject: PluginRef) => void;
|
|
24
24
|
adjustWidgetLayout(id: string, { needSetDefault }: {
|
|
25
25
|
needSetDefault: boolean;
|
|
26
26
|
}): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileLayout.js","sourceRoot":"../../../../src","sources":["components/MobileLayout/MobileLayout.tsx"],"names":[],"mappings":";;;AAAA,0DAA0B;AAE1B,wEAAq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CAAC,EAAE,IAAI;iBACb,CAAC;aACL,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,yBAAyB,CAAC,EAAU;QAChC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,EAAE,CAAC;YACpC,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;;AAlIM,wBAAW,GAAG,wBAAc,AAAjB,CAAkB;kBAJnB,YAAY","sourcesContent":["import React from 'react';\n\nimport groupBy from 'lodash/groupBy';\n\nimport type {PluginRef} from 'src/typings';\n\nimport {DEFAULT_GROUP} from '../../constants';\nimport {DashKitContext} from '../../context';\nimport {cn} from '../../utils/cn';\nimport Item from '../Item/Item';\n\nimport {getSortedConfigItems} from './helpers';\n\nimport './MobileLayout.scss';\n\nconst b = cn('dashkit-mobile-layout');\n\ntype MobileLayoutProps = {};\n\ntype MobileLayoutState = {\n itemsWithActiveAutoheight: Record<string, boolean>;\n};\n\nexport default class MobileLayout extends React.PureComponent<\n MobileLayoutProps,\n MobileLayoutState\n> {\n static contextType = DashKitContext;\n context!: React.ContextType<typeof DashKitContext>;\n\n pluginsRefs: PluginRef[] = [];\n sortedLayoutItems: Record<string, ReturnType<typeof getSortedConfigItems>> | null = null;\n\n _memoLayout = this.context.layout;\n _memoForwardedPluginRef: Array<(refObject: PluginRef) => void> = [];\n _memoAdjustWidgetLayout: Record<string, (props: {needSetDefault: boolean}) => void> = {};\n\n state: MobileLayoutState = {\n itemsWithActiveAutoheight: {},\n };\n\n render() {\n const {\n config,\n layout,\n groups = [{id: DEFAULT_GROUP}],\n context,\n editMode,\n configItems,\n } = this.context;\n\n this.pluginsRefs.length = configItems.length;\n\n const sortedItems = this.getSortedLayoutItems();\n let indexOffset = 0;\n\n return (\n <div className={b()}>\n {groups.map((group) => {\n const groupId = group.id || DEFAULT_GROUP;\n const items = sortedItems[groupId] || [];\n\n const children = items.map((item, index) => {\n const isItemWithActiveAutoheight =\n item.id in this.state.itemsWithActiveAutoheight;\n\n return (\n <div\n className={b('item', {autoheight: isItemWithActiveAutoheight})}\n key={item.id}\n >\n <Item\n id={item.id}\n item={item}\n layout={layout}\n shouldItemUpdate={false}\n adjustWidgetLayout={this.getMemoAdjustWidgetLayout(item.id)}\n forwardedPluginRef={this.getMemoForwardRefCallback(\n indexOffset + index,\n )}\n onItemMountChange={this.context.onItemMountChange}\n onItemRender={this.context.onItemRender}\n />\n </div>\n );\n });\n\n indexOffset += items.length;\n\n if (group.render) {\n return group.render(groupId, children, {\n isMobile: true,\n config,\n context,\n editMode,\n items,\n layout,\n });\n }\n\n return children;\n })}\n </div>\n );\n }\n\n getSortedLayoutItems() {\n if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {\n return this.sortedLayoutItems;\n }\n\n this._memoLayout = this.context.layout;\n\n const hasOrderId = Boolean(this.context.configItems.find((item) => item.orderId));\n\n this.sortedLayoutItems = groupBy(\n getSortedConfigItems(this.context.config, this.context.configItems, hasOrderId),\n (item) => item.parent || DEFAULT_GROUP,\n );\n\n return this.sortedLayoutItems;\n }\n\n getMemoForwardRefCallback(refIndex: number) {\n if (!this._memoForwardedPluginRef[refIndex]) {\n this._memoForwardedPluginRef[refIndex] = (pluginRef: PluginRef) => {\n this.pluginsRefs[refIndex] = pluginRef;\n };\n }\n\n return this._memoForwardedPluginRef[refIndex];\n }\n\n adjustWidgetLayout(id: string, {needSetDefault}: {needSetDefault: boolean}) {\n if (needSetDefault) {\n const indexesOfItemsWithActiveAutoheight = {\n ...this.state.itemsWithActiveAutoheight,\n };\n\n delete indexesOfItemsWithActiveAutoheight[id];\n\n this.setState({itemsWithActiveAutoheight: indexesOfItemsWithActiveAutoheight});\n } else {\n this.setState({\n itemsWithActiveAutoheight: Object.assign({}, this.state.itemsWithActiveAutoheight, {\n [id]: true,\n }),\n });\n }\n }\n\n getMemoAdjustWidgetLayout(id: string) {\n if (!this._memoAdjustWidgetLayout[id]) {\n this._memoAdjustWidgetLayout[id] = this.adjustWidgetLayout.bind(this, id);\n }\n\n return this._memoAdjustWidgetLayout[id];\n }\n}\n"]}
|
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { RegisterManager } from "../utils/index.js";
|
|
3
3
|
import type { DashKitProps } from "../components/DashKit/index.js";
|
|
4
|
-
import type { ConfigItem, ConfigLayout, ItemParams, ItemState, ItemStateAndParams, ItemStateAndParamsChangeOptions } from "../shared/index.js";
|
|
4
|
+
import type { ConfigItem, ConfigLayout, ItemDragProps, ItemParams, ItemState, ItemStateAndParams, ItemStateAndParamsChangeOptions } from "../shared/index.js";
|
|
5
|
+
import type { PluginRef, ReactGridLayoutProps } from "../typings/index.js";
|
|
5
6
|
type DashkitPropsPassedToCtx = Pick<DashKitProps, 'config' | 'groups' | 'context' | 'noOverlay' | 'focusable' | 'globalParams' | 'editMode' | 'settings' | 'onItemMountChange' | 'onItemRender' | 'draggableHandleClassName' | 'onDragStart' | 'onDrag' | 'onDragStop' | 'onResizeStart' | 'onResize' | 'onResizeStop'>;
|
|
6
7
|
type PluginType = string;
|
|
8
|
+
type TemporaryLayout = {
|
|
9
|
+
data: ConfigLayout[];
|
|
10
|
+
dragProps: ItemDragProps;
|
|
11
|
+
};
|
|
7
12
|
export type DashKitCtxShape = DashkitPropsPassedToCtx & {
|
|
8
13
|
registerManager: RegisterManager;
|
|
9
14
|
forwardedMetaRef: React.ForwardedRef<any>;
|
|
10
15
|
configItems: ConfigItem[];
|
|
11
16
|
layout: ConfigLayout[];
|
|
12
|
-
|
|
17
|
+
layoutChange: (layout: ConfigLayout[]) => void;
|
|
18
|
+
temporaryLayout: TemporaryLayout | null;
|
|
13
19
|
memorizeOriginalLayout: (widgetId: string, preAutoHeightLayout: ConfigLayout, postAutoHeightLayout: ConfigLayout) => void;
|
|
14
20
|
revertToOriginalLayout: (widgetId: string) => void;
|
|
15
21
|
itemsState?: Record<string, ItemState>;
|
|
16
22
|
itemsParams: Record<string, ItemParams>;
|
|
17
23
|
onItemStateAndParamsChange: (id: string, stateAndParams: ItemStateAndParams, options: ItemStateAndParamsChangeOptions) => void;
|
|
18
|
-
getItemsMeta: (pluginsRefs: Array<
|
|
19
|
-
reloadItems: (pluginsRefs: Array<
|
|
24
|
+
getItemsMeta: (pluginsRefs: Array<PluginRef>) => Array<Promise<any>>;
|
|
25
|
+
reloadItems: (pluginsRefs: Array<PluginRef>, data: {
|
|
20
26
|
silentLoading: boolean;
|
|
21
27
|
noVeil: boolean;
|
|
22
28
|
}) => void;
|
|
23
|
-
onDrop: (newLayout: ConfigLayout, item:
|
|
24
|
-
onDropDragOver: (e: DragEvent | MouseEvent, group: string | void, gridProps:
|
|
29
|
+
onDrop: (newLayout: ConfigLayout[], item: ConfigLayout, e?: MouseEvent) => void;
|
|
30
|
+
onDropDragOver: (e: DragEvent | MouseEvent, group: string | void, gridProps: ReactGridLayoutProps, groupLayout: ConfigLayout[], sharedItem: (Partial<ConfigLayout> & {
|
|
25
31
|
type: PluginType;
|
|
26
32
|
}) | void) => void | boolean;
|
|
33
|
+
onItemBlur: (item: ConfigItem) => void;
|
|
34
|
+
onItemFocus: (item: ConfigItem) => void;
|
|
27
35
|
outerDnDEnable: boolean;
|
|
28
36
|
dragOverPlugin: null | PluginType;
|
|
29
37
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DashKitContext.js","sourceRoot":"../../../src","sources":["context/DashKitContext.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;
|
|
1
|
+
{"version":3,"file":"DashKitContext.js","sourceRoot":"../../../src","sources":["context/DashKitContext.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAuF1B,MAAM,cAAc,GAAG,eAAK,CAAC,aAAa,CAAkB,EAAqB,CAAC,CAAC;AAE3E,wCAAc","sourcesContent":["import React from 'react';\n\nimport type {RegisterManager} from '..//utils';\nimport type {DashKitProps} from '../components/DashKit';\nimport type {\n ConfigItem,\n ConfigLayout,\n ItemDragProps,\n ItemParams,\n ItemState,\n ItemStateAndParams,\n ItemStateAndParamsChangeOptions,\n} from '../shared';\nimport type {PluginRef, ReactGridLayoutProps} from '../typings';\n\ntype DashkitPropsPassedToCtx = Pick<\n DashKitProps,\n | 'config'\n | 'groups'\n | 'context'\n | 'noOverlay'\n | 'focusable'\n | 'globalParams'\n | 'editMode'\n | 'settings'\n | 'onItemMountChange'\n | 'onItemRender'\n | 'draggableHandleClassName'\n // default handlers bypass\n | 'onDragStart'\n | 'onDrag'\n | 'onDragStop'\n | 'onResizeStart'\n | 'onResize'\n | 'onResizeStop'\n>;\n\ntype PluginType = string;\n\ntype TemporaryLayout = {\n data: ConfigLayout[];\n dragProps: ItemDragProps;\n};\n\nexport type DashKitCtxShape = DashkitPropsPassedToCtx & {\n registerManager: RegisterManager;\n forwardedMetaRef: React.ForwardedRef<any>;\n\n configItems: ConfigItem[];\n layout: ConfigLayout[];\n layoutChange: (layout: ConfigLayout[]) => void;\n temporaryLayout: TemporaryLayout | null;\n memorizeOriginalLayout: (\n widgetId: string,\n preAutoHeightLayout: ConfigLayout,\n postAutoHeightLayout: ConfigLayout,\n ) => void;\n revertToOriginalLayout: (widgetId: string) => void;\n\n itemsState?: Record<string, ItemState>;\n itemsParams: Record<string, ItemParams>;\n onItemStateAndParamsChange: (\n id: string,\n stateAndParams: ItemStateAndParams,\n options: ItemStateAndParamsChangeOptions,\n ) => void;\n\n getItemsMeta: (pluginsRefs: Array<PluginRef>) => Array<Promise<any>>;\n reloadItems: (\n pluginsRefs: Array<PluginRef>,\n data: {silentLoading: boolean; noVeil: boolean},\n ) => void;\n\n onDrop: (newLayout: ConfigLayout[], item: ConfigLayout, e?: MouseEvent) => void;\n onDropDragOver: (\n e: DragEvent | MouseEvent,\n group: string | void,\n gridProps: ReactGridLayoutProps,\n groupLayout: ConfigLayout[],\n sharedItem: (Partial<ConfigLayout> & {type: PluginType}) | void,\n ) => void | boolean;\n onItemBlur: (item: ConfigItem) => void;\n onItemFocus: (item: ConfigItem) => void;\n outerDnDEnable: boolean;\n dragOverPlugin: null | PluginType;\n};\n\nconst DashKitContext = React.createContext<DashKitCtxShape>({} as DashKitCtxShape);\n\nexport {DashKitContext};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Layout
|
|
1
|
+
import type { Layout } from 'react-grid-layout';
|
|
2
2
|
import type { Config, ConfigItem, ConfigLayout } from "../shared/index.js";
|
|
3
3
|
import { GridLayoutSettings } from "./common.js";
|
|
4
4
|
export interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {
|
|
@@ -42,7 +42,7 @@ export interface DashKitGroup {
|
|
|
42
42
|
gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;
|
|
43
43
|
}
|
|
44
44
|
export type ItemManipulationCallback = (eventData: {
|
|
45
|
-
layout:
|
|
45
|
+
layout: Layout[];
|
|
46
46
|
oldItem: Layout;
|
|
47
47
|
newItem: Layout;
|
|
48
48
|
placeholder: Layout;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"../../../src","sources":["typings/config.ts"],"names":[],"mappings":"","sourcesContent":["import type {Layout
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"../../../src","sources":["typings/config.ts"],"names":[],"mappings":"","sourcesContent":["import type {Layout} from 'react-grid-layout';\n\nimport type {Config, ConfigItem, ConfigLayout} from '../shared';\n\nimport {GridLayoutSettings} from './common';\n\nexport interface AddConfigItem extends Omit<ConfigItem, 'id' | 'namespace'> {\n id?: null;\n namespace?: string;\n layout?: Omit<ConfigLayout, 'i'>;\n}\nexport type SetConfigItem = ConfigItem | AddConfigItem;\n\nexport type SetItemOptions = {\n excludeIds?: string[];\n useGlobalItems?: boolean;\n};\n\nexport type GridReflowOptions = {\n cols: number;\n maxRows?: number;\n compactType?: CompactType;\n};\n\nexport type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';\n\nexport type ReflowLayoutOptions = {\n defaultProps: GridReflowOptions;\n groups?: Record<string, GridReflowOptions>;\n};\n\nexport type AddNewItemOptions = SetItemOptions & {\n updateLayout?: ConfigLayout[];\n reflowLayoutOptions?: ReflowLayoutOptions;\n};\n\nexport interface DashkitGroupRenderProps {\n config: Config;\n editMode: boolean;\n isMobile: boolean;\n items: ConfigItem[];\n layout: ConfigLayout[];\n context: any;\n}\n\nexport type ReactGridLayoutProps = Omit<\n GridLayoutSettings,\n | 'children'\n | 'compactType'\n | 'innerRef'\n | 'key'\n | 'layout'\n | 'onDragStart'\n | 'onDragStop'\n | 'onResizeStart'\n | 'onResizeStop'\n | 'draggableHandle'\n | 'isDroppable'\n | 'onDropDragOver'\n | 'onDrop'\n | 'draggableCancel'\n> & {\n compactType?: CompactType;\n};\n\nexport interface DashKitGroup {\n id?: string;\n render?: (\n id: string,\n children: React.ReactNode,\n props: DashkitGroupRenderProps,\n ) => React.ReactNode;\n gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;\n}\n\nexport type ItemManipulationCallback = (eventData: {\n layout: Layout[];\n oldItem: Layout;\n newItem: Layout;\n placeholder: Layout;\n e: MouseEvent;\n element: HTMLElement;\n}) => void;\n"]}
|
|
@@ -25,6 +25,7 @@ export interface PluginWidgetProps<T = StringParams> {
|
|
|
25
25
|
}) => void;
|
|
26
26
|
}
|
|
27
27
|
export type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;
|
|
28
|
+
export type PluginRef = React.RefObject<any> | Record<string, unknown>;
|
|
28
29
|
export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
|
|
29
30
|
defaultLayout?: PluginDefaultLayout;
|
|
30
31
|
renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"../../../src","sources":["typings/plugin.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\nimport ReactGridLayout from 'react-grid-layout';\n\nimport type {\n ConfigItem,\n ItemState,\n ItemStateAndParams,\n ItemStateAndParamsChangeOptions,\n PluginBase,\n StringParams,\n} from '../shared';\n\nimport type {ContextProps, SettingsProps, WidgetLayout} from './common';\n\nexport interface PluginWidgetProps<T = StringParams> {\n id: string;\n editMode: boolean;\n params: T;\n state: ItemState;\n onStateAndParamsChange: (\n stateAndParams: ItemStateAndParams,\n options?: ItemStateAndParamsChangeOptions,\n ) => void;\n onBeforeLoad: () => () => void;\n width: number;\n height: number;\n data: ConfigItem['data'];\n defaults: ConfigItem['defaults'];\n namespace: ConfigItem['namespace'];\n settings: SettingsProps;\n context: ContextProps;\n layout: WidgetLayout[];\n gridLayout: ReactGridLayout.ReactGridLayoutProps;\n adjustWidgetLayout: (data: {\n widgetId: string;\n needSetDefault?: boolean;\n adjustedWidgetLayout?: WidgetLayout;\n }) => void;\n}\n\nexport type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;\n\nexport interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {\n defaultLayout?: PluginDefaultLayout;\n renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"../../../src","sources":["typings/plugin.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\nimport ReactGridLayout from 'react-grid-layout';\n\nimport type {\n ConfigItem,\n ItemState,\n ItemStateAndParams,\n ItemStateAndParamsChangeOptions,\n PluginBase,\n StringParams,\n} from '../shared';\n\nimport type {ContextProps, SettingsProps, WidgetLayout} from './common';\n\nexport interface PluginWidgetProps<T = StringParams> {\n id: string;\n editMode: boolean;\n params: T;\n state: ItemState;\n onStateAndParamsChange: (\n stateAndParams: ItemStateAndParams,\n options?: ItemStateAndParamsChangeOptions,\n ) => void;\n onBeforeLoad: () => () => void;\n width: number;\n height: number;\n data: ConfigItem['data'];\n defaults: ConfigItem['defaults'];\n namespace: ConfigItem['namespace'];\n settings: SettingsProps;\n context: ContextProps;\n layout: WidgetLayout[];\n gridLayout: ReactGridLayout.ReactGridLayoutProps;\n adjustWidgetLayout: (data: {\n widgetId: string;\n needSetDefault?: boolean;\n adjustedWidgetLayout?: WidgetLayout;\n }) => void;\n}\n\nexport type PluginDefaultLayout = Partial<Omit<WidgetLayout, 'i'>>;\n\nexport type PluginRef = React.RefObject<any> | Record<string, unknown>;\n\nexport interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {\n defaultLayout?: PluginDefaultLayout;\n renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;\n}\n"]}
|
|
@@ -73,7 +73,7 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
|
|
|
73
73
|
}): ConfigLayout[];
|
|
74
74
|
metaRef: React.RefObject<GridLayout>;
|
|
75
75
|
render(): JSX.Element;
|
|
76
|
-
getItemsMeta(): any;
|
|
76
|
+
getItemsMeta(): Promise<any>[] | undefined;
|
|
77
77
|
reloadItems(options?: {
|
|
78
78
|
targetIds?: string[];
|
|
79
79
|
force?: boolean;
|
|
@@ -1,73 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PluginRef, ReactGridLayoutProps } from 'src/typings';
|
|
3
|
+
import type { DashKitCtxShape } from "../../context/index.js";
|
|
4
|
+
import type { ConfigItem, ConfigLayout } from "../../shared/index.js";
|
|
5
|
+
import type { AdjustWidgetLayoutParams, GridLayoutProps, GridLayoutState, GroupCallbacks, LayoutAndPropsByGroup, ManipulationCallbackArgs, MemoGroupLayout, ReloadItemsOptions } from "./types.js";
|
|
6
|
+
export default class GridLayout extends React.PureComponent<GridLayoutProps, GridLayoutState> {
|
|
7
|
+
static contextType: React.Context<DashKitCtxShape>;
|
|
8
|
+
context: DashKitCtxShape;
|
|
9
|
+
pluginsRefs: Array<PluginRef>;
|
|
10
|
+
private _memoForwardedPluginRef;
|
|
11
|
+
private _memoGroupsProps;
|
|
12
|
+
private _memoGroupsLayouts;
|
|
13
|
+
private _memoCallbacksForGroups;
|
|
14
|
+
private _timeout?;
|
|
15
|
+
private _lastReloadAt?;
|
|
16
|
+
private _parendDragNode;
|
|
17
|
+
constructor(props: GridLayoutProps, context: DashKitCtxShape);
|
|
12
18
|
componentDidMount(): void;
|
|
13
19
|
componentDidUpdate(): void;
|
|
14
20
|
componentWillUnmount(): void;
|
|
15
|
-
_memoCallbacksForGroups: {};
|
|
16
|
-
_memoGroupsProps: {};
|
|
17
|
-
_memoGroupsLayouts: {};
|
|
18
|
-
_memoForwardedPluginRef: any[];
|
|
19
|
-
_timeout: any;
|
|
20
|
-
_lastReloadAt: any;
|
|
21
21
|
onVisibilityChange: () => void;
|
|
22
|
-
adjustWidgetLayout: ({ widgetId, needSetDefault, adjustedWidgetLayout }:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getMemoGroupCallbacks(group: any): any;
|
|
31
|
-
getMemoGroupProps: (group: any, renderLayout: any, properties: any) => {
|
|
32
|
-
layout: any;
|
|
33
|
-
callbacks: any;
|
|
34
|
-
};
|
|
35
|
-
getLayoutAndPropsByGroup: (group: any) => {
|
|
36
|
-
properties: any;
|
|
37
|
-
layout: any;
|
|
22
|
+
adjustWidgetLayout: ({ widgetId, needSetDefault, adjustedWidgetLayout, }: AdjustWidgetLayoutParams) => void;
|
|
23
|
+
getItemsMeta: () => Promise<any>[];
|
|
24
|
+
getActiveLayout(): ConfigLayout[];
|
|
25
|
+
getMemoGroupLayout(group: string, layout: ConfigLayout[]): MemoGroupLayout;
|
|
26
|
+
getMemoGroupCallbacks(group: string): GroupCallbacks;
|
|
27
|
+
getMemoGroupProps: (group: string, renderLayout: ConfigLayout[], properties: Partial<ReactGridLayoutProps>) => {
|
|
28
|
+
layout: ConfigLayout[];
|
|
29
|
+
callbacks: GroupCallbacks;
|
|
38
30
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
updateDraggingElementState(group: any, layoutItem: any, e: any): void;
|
|
52
|
-
_initDragCoordinatesWatcher(element: any): void;
|
|
53
|
-
_parendDragNode: any;
|
|
54
|
-
_forceCursorCapture(parentElement: any, position: any, parentRect: any): void;
|
|
55
|
-
_updateDragCoordinates(e: any): void;
|
|
31
|
+
getLayoutAndPropsByGroup: (group: string) => LayoutAndPropsByGroup;
|
|
32
|
+
getMemoForwardRefCallback: (refIndex: number) => (pluginRef: PluginRef) => void;
|
|
33
|
+
mergeGroupsLayout(group: string, newLayout: ConfigLayout[], temporaryItem?: ConfigLayout): ConfigLayout[];
|
|
34
|
+
reloadItems(options?: ReloadItemsOptions): void;
|
|
35
|
+
prepareDefaultArguments(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): ManipulationCallbackArgs;
|
|
36
|
+
updateDraggingElementState(group: string, layoutItem: ConfigLayout, e: MouseEvent): void;
|
|
37
|
+
_initDragCoordinatesWatcher(element: HTMLElement): void;
|
|
38
|
+
_forceCursorCapture(parentElement: HTMLElement, position: {
|
|
39
|
+
top: number;
|
|
40
|
+
left: number;
|
|
41
|
+
}, parentRect: DOMRect): void;
|
|
42
|
+
_updateDragCoordinates(e: MouseEvent): void;
|
|
56
43
|
_resetDragWatcher(): void;
|
|
57
|
-
_onDragStart(group:
|
|
58
|
-
_onDrag(group:
|
|
59
|
-
_onDragStop(group:
|
|
60
|
-
_onResizeStart(group:
|
|
61
|
-
_onResize(group:
|
|
62
|
-
_onResizeStop(group:
|
|
44
|
+
_onDragStart(group: string, _newLayout: ConfigLayout[], layoutItem: ConfigLayout, _newItem: ConfigLayout, _placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
45
|
+
_onDrag(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
46
|
+
_onDragStop(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
47
|
+
_onResizeStart(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
48
|
+
_onResize(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
49
|
+
_onResizeStop(group: string, layout: ConfigLayout[], oldItem: ConfigLayout, newItem: ConfigLayout, placeholder: ConfigLayout, e: MouseEvent, element: HTMLElement): void;
|
|
63
50
|
_onTargetRestore(): void;
|
|
64
|
-
_onStop: (group:
|
|
65
|
-
_onSharedDrop: (targetGroup:
|
|
66
|
-
_onExternalDrop: (group:
|
|
67
|
-
_onDrop: (group:
|
|
68
|
-
_onDropDragOver: (group:
|
|
69
|
-
renderTemporaryPlaceholder(gridLayout:
|
|
70
|
-
renderGroup(group:
|
|
71
|
-
render():
|
|
51
|
+
_onStop: (group: string, newLayout: ConfigLayout[]) => void;
|
|
52
|
+
_onSharedDrop: (targetGroup: string, newLayout: ConfigLayout[], tempItem: ConfigLayout) => void;
|
|
53
|
+
_onExternalDrop: (group: string, newLayout: ConfigLayout[], item: ConfigLayout, e: MouseEvent) => void;
|
|
54
|
+
_onDrop: (group: string, newLayout: ConfigLayout[], item: ConfigLayout | undefined, e: MouseEvent) => void | false;
|
|
55
|
+
_onDropDragOver: (group: string, e: DragEvent | MouseEvent) => void | boolean;
|
|
56
|
+
renderTemporaryPlaceholder(gridLayout: Partial<ReactGridLayoutProps>): JSX.Element | null;
|
|
57
|
+
renderGroup(group: string, renderLayout: ConfigLayout[], renderItems: ConfigItem[], offset?: number, groupGridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps): JSX.Element;
|
|
58
|
+
render(): JSX.Element | (string | number | boolean | JSX.Element | React.ReactFragment | null | undefined)[];
|
|
72
59
|
}
|
|
73
|
-
import React from 'react';
|
|
@@ -4,6 +4,13 @@ import { DashKitContext } from "../../context/index.js";
|
|
|
4
4
|
import { resolveLayoutGroup } from "../../utils/index.js";
|
|
5
5
|
import GridItem from "../GridItem/GridItem.js";
|
|
6
6
|
import { Layout } from "./ReactGridLayout.js";
|
|
7
|
+
const hasPluginId = (value) => {
|
|
8
|
+
return ('props' in value &&
|
|
9
|
+
typeof value.props === 'object' &&
|
|
10
|
+
value.props !== null &&
|
|
11
|
+
'id' in value.props &&
|
|
12
|
+
typeof value.props.id === 'string');
|
|
13
|
+
};
|
|
7
14
|
class GridLayout extends React.PureComponent {
|
|
8
15
|
constructor(props, context) {
|
|
9
16
|
super(props, context);
|
|
@@ -11,12 +18,13 @@ class GridLayout extends React.PureComponent {
|
|
|
11
18
|
this._memoGroupsProps = {};
|
|
12
19
|
this._memoGroupsLayouts = {};
|
|
13
20
|
this._memoCallbacksForGroups = {};
|
|
21
|
+
this._parendDragNode = null;
|
|
14
22
|
this.onVisibilityChange = () => {
|
|
15
23
|
this.setState({
|
|
16
24
|
isPageHidden: document.hidden,
|
|
17
25
|
});
|
|
18
26
|
};
|
|
19
|
-
this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout }) => {
|
|
27
|
+
this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout, }) => {
|
|
20
28
|
const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
|
|
21
29
|
if (needSetDefault) {
|
|
22
30
|
revertToOriginalLayout(widgetId);
|
|
@@ -71,7 +79,10 @@ class GridLayout extends React.PureComponent {
|
|
|
71
79
|
draggedOverGroup: null,
|
|
72
80
|
});
|
|
73
81
|
if (temporaryLayout) {
|
|
74
|
-
|
|
82
|
+
const temporaryItem = groupedLayout.find(({ i }) => i === TEMPORARY_ITEM_ID);
|
|
83
|
+
if (onDrop && temporaryItem) {
|
|
84
|
+
onDrop(groupedLayout, temporaryItem);
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
else {
|
|
77
88
|
layoutChange(groupedLayout);
|
|
@@ -212,7 +223,7 @@ class GridLayout extends React.PureComponent {
|
|
|
212
223
|
const onResizeStop = this._onResizeStop.bind(this, group);
|
|
213
224
|
const onDrop = this._onDrop.bind(this, group);
|
|
214
225
|
const onDropDragOver = this._onDropDragOver.bind(this, group);
|
|
215
|
-
const onDragTargetRestore = this._onTargetRestore.bind(this
|
|
226
|
+
const onDragTargetRestore = this._onTargetRestore.bind(this);
|
|
216
227
|
this._memoCallbacksForGroups[group] = {
|
|
217
228
|
onDragStart,
|
|
218
229
|
onDrag,
|
|
@@ -234,7 +245,8 @@ class GridLayout extends React.PureComponent {
|
|
|
234
245
|
return memo;
|
|
235
246
|
}, temporaryItem ? { [temporaryItem.i]: temporaryItem } : {});
|
|
236
247
|
const newItemsLayoutById = newLayout.reduce((memo, item) => {
|
|
237
|
-
|
|
248
|
+
var _a;
|
|
249
|
+
const parent = (_a = itemsByGroup[item.i]) === null || _a === void 0 ? void 0 : _a.parent;
|
|
238
250
|
memo[item.i] = Object.assign({}, item);
|
|
239
251
|
if (parent) {
|
|
240
252
|
memo[item.i].parent = parent;
|
|
@@ -255,19 +267,19 @@ class GridLayout extends React.PureComponent {
|
|
|
255
267
|
const { isPageHidden } = this.state;
|
|
256
268
|
const autoupdateIntervalMs = Number(autoupdateInterval) * 1000;
|
|
257
269
|
const targetPlugins = targetIds
|
|
258
|
-
? this.pluginsRefs.filter((plugin) => targetIds.includes(plugin.props.id))
|
|
270
|
+
? this.pluginsRefs.filter((plugin) => hasPluginId(plugin) && targetIds.includes(plugin.props.id))
|
|
259
271
|
: this.pluginsRefs;
|
|
260
272
|
if (autoupdateIntervalMs) {
|
|
261
273
|
const timeSinceLastReload = new Date().getTime() - (this._lastReloadAt || 0);
|
|
262
274
|
const reloadIntervalRemains = autoupdateIntervalMs - timeSinceLastReload;
|
|
263
275
|
if (force || (!isPageHidden && !editMode && reloadIntervalRemains <= 0)) {
|
|
264
276
|
this._lastReloadAt = new Date().getTime();
|
|
265
|
-
reloadItems(targetPlugins, { silentLoading, noVeil: true });
|
|
277
|
+
reloadItems(targetPlugins, { silentLoading: Boolean(silentLoading), noVeil: true });
|
|
266
278
|
}
|
|
267
279
|
this._timeout = setTimeout(() => this.reloadItems(), reloadIntervalRemains <= 0 ? autoupdateIntervalMs : reloadIntervalRemains);
|
|
268
280
|
}
|
|
269
281
|
else if (force) {
|
|
270
|
-
reloadItems(targetPlugins, { silentLoading, noVeil: true });
|
|
282
|
+
reloadItems(targetPlugins, { silentLoading: Boolean(silentLoading), noVeil: true });
|
|
271
283
|
}
|
|
272
284
|
}
|
|
273
285
|
prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
@@ -289,11 +301,15 @@ class GridLayout extends React.PureComponent {
|
|
|
289
301
|
const item = temporaryLayout
|
|
290
302
|
? temporaryLayout.dragProps
|
|
291
303
|
: this.context.configItems.find(({ id }) => id === layoutId);
|
|
304
|
+
if (!item) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
292
307
|
let { offsetX, offsetY } = e.nativeEvent || {};
|
|
293
308
|
if (offsetX === undefined || offsetY === undefined) {
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
309
|
+
const target = e.currentTarget;
|
|
310
|
+
const gridRect = target === null || target === void 0 ? void 0 : target.getBoundingClientRect();
|
|
311
|
+
offsetX = e.clientX - ((gridRect === null || gridRect === void 0 ? void 0 : gridRect.left) || 0);
|
|
312
|
+
offsetY = e.clientY - ((gridRect === null || gridRect === void 0 ? void 0 : gridRect.top) || 0);
|
|
297
313
|
}
|
|
298
314
|
currentDraggingElement = {
|
|
299
315
|
group,
|
|
@@ -331,6 +347,9 @@ class GridLayout extends React.PureComponent {
|
|
|
331
347
|
}
|
|
332
348
|
_updateDragCoordinates(e) {
|
|
333
349
|
const parent = this._parendDragNode;
|
|
350
|
+
if (!parent) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
334
353
|
const parentRect = parent.getBoundingClientRect();
|
|
335
354
|
const { clientX, clientY } = e;
|
|
336
355
|
let isDraggedOut = this.state.isDraggedOut;
|
|
@@ -416,7 +435,10 @@ class GridLayout extends React.PureComponent {
|
|
|
416
435
|
}
|
|
417
436
|
const id = TEMPORARY_ITEM_ID;
|
|
418
437
|
const { type } = temporaryLayout.dragProps;
|
|
419
|
-
return (React.createElement(GridItem, { key: id,
|
|
438
|
+
return (React.createElement(GridItem, { key: id,
|
|
439
|
+
// TODO remove the expected error after translating GridItem to TS
|
|
440
|
+
// @ts-expect-error
|
|
441
|
+
id: id, item: { id, type, data: {} }, layout: temporaryLayout.data, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), gridLayout: gridLayout }));
|
|
420
442
|
}
|
|
421
443
|
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
|
|
422
444
|
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, onItemFocus, onItemBlur, } = this.context;
|
|
@@ -435,22 +457,43 @@ class GridLayout extends React.PureComponent {
|
|
|
435
457
|
group === currentDraggingElement.group &&
|
|
436
458
|
draggedOverGroup !== null &&
|
|
437
459
|
draggedOverGroup !== group;
|
|
438
|
-
return (React.createElement(Layout, Object.assign({ isDraggable: editMode, isResizable: editMode }, properties, {
|
|
460
|
+
return (React.createElement(Layout, Object.assign({ key: `group_${group}` }, Object.assign(Object.assign({ isDraggable: editMode, isResizable: editMode }, properties), {
|
|
439
461
|
// Layout props
|
|
440
|
-
compactType
|
|
462
|
+
compactType,
|
|
463
|
+
layout, draggableCancel: `.${DRAGGABLE_CANCEL_CLASS_NAME}`, draggableHandle: draggableHandleClassName
|
|
464
|
+
? `.${draggableHandleClassName}`
|
|
465
|
+
: null,
|
|
441
466
|
// Default callbacks
|
|
442
467
|
onDragStart: callbacks.onDragStart, onDrag: callbacks.onDrag, onDragStop: callbacks.onDragStop, onResizeStart: callbacks.onResizeStart, onResize: callbacks.onResize, onResizeStop: callbacks.onResizeStop,
|
|
443
468
|
// External Drag N Drop options
|
|
444
|
-
onDragTargetRestore: callbacks.onDragTargetRestore, onDropDragOver: callbacks.onDropDragOver, onDrop: callbacks.onDrop, hasSharedDragItem
|
|
469
|
+
onDragTargetRestore: callbacks.onDragTargetRestore, onDropDragOver: callbacks.onDropDragOver, onDrop: callbacks.onDrop, hasSharedDragItem, sharedDragPosition: currentDraggingElement === null || currentDraggingElement === void 0 ? void 0 : currentDraggingElement.cursorPosition, isDragCaptured, isDroppable: Boolean(outerDnDEnable) && editMode })),
|
|
445
470
|
renderItems.map((item, i) => {
|
|
446
471
|
const keyId = item.id;
|
|
447
472
|
const isDragging = this.state.isDragging;
|
|
448
|
-
const isCurrentDraggedItem =
|
|
473
|
+
const isCurrentDraggedItem = currentDraggingElement &&
|
|
474
|
+
'id' in currentDraggingElement.item &&
|
|
475
|
+
currentDraggingElement.item.id === keyId;
|
|
449
476
|
const isDraggedOut = isCurrentDraggedItem && this.state.isDraggedOut;
|
|
450
477
|
const itemNoOverlay = hasOwnGroupProperties && 'noOverlay' in properties
|
|
451
478
|
? properties.noOverlay
|
|
452
479
|
: noOverlay;
|
|
453
|
-
return (React.createElement(GridItem,
|
|
480
|
+
return (React.createElement(GridItem, Object.assign({ key: keyId }, {
|
|
481
|
+
forwardedPluginRef: this.getMemoForwardRefCallback(offset + i),
|
|
482
|
+
id: keyId,
|
|
483
|
+
item,
|
|
484
|
+
layout,
|
|
485
|
+
adjustWidgetLayout: this.adjustWidgetLayout,
|
|
486
|
+
isDragging,
|
|
487
|
+
isDraggedOut,
|
|
488
|
+
noOverlay: itemNoOverlay,
|
|
489
|
+
focusable,
|
|
490
|
+
withCustomHandle: Boolean(draggableHandleClassName),
|
|
491
|
+
onItemMountChange,
|
|
492
|
+
onItemRender,
|
|
493
|
+
gridLayout: properties,
|
|
494
|
+
onItemFocus,
|
|
495
|
+
onItemBlur,
|
|
496
|
+
})));
|
|
454
497
|
}),
|
|
455
498
|
this.renderTemporaryPlaceholder(properties)));
|
|
456
499
|
}
|
|
@@ -472,7 +515,7 @@ class GridLayout extends React.PureComponent {
|
|
|
472
515
|
defaultRenderLayout.push(item);
|
|
473
516
|
}
|
|
474
517
|
return memo;
|
|
475
|
-
},
|
|
518
|
+
}, {});
|
|
476
519
|
const itemsByGroup = this.context.configItems.reduce((memo, item) => {
|
|
477
520
|
const group = layoutMap[item.id];
|
|
478
521
|
if (group) {
|