@gravity-ui/dashkit 10.0.0 → 10.1.0

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.
Files changed (39) hide show
  1. package/build/cjs/components/GridItem/GridItem.js +13 -0
  2. package/build/cjs/components/GridItem/GridItem.js.map +1 -1
  3. package/build/cjs/components/GridLayout/GridLayout.d.ts +6 -1
  4. package/build/cjs/components/GridLayout/GridLayout.js +54 -34
  5. package/build/cjs/components/GridLayout/GridLayout.js.map +1 -1
  6. package/build/cjs/components/GridLayout/GroupLayout.d.ts +29 -0
  7. package/build/cjs/components/GridLayout/GroupLayout.js +60 -0
  8. package/build/cjs/components/GridLayout/GroupLayout.js.map +1 -0
  9. package/build/cjs/components/GridLayout/ReactGridLayout.d.ts +7 -2
  10. package/build/cjs/components/GridLayout/ReactGridLayout.js +24 -11
  11. package/build/cjs/components/GridLayout/ReactGridLayout.js.map +1 -1
  12. package/build/cjs/components/GridLayout/utils.d.ts +2 -0
  13. package/build/cjs/components/GridLayout/utils.js +25 -0
  14. package/build/cjs/components/GridLayout/utils.js.map +1 -0
  15. package/build/cjs/hocs/prepareItem.js +19 -5
  16. package/build/cjs/hocs/prepareItem.js.map +1 -1
  17. package/build/cjs/package.json +1 -1
  18. package/build/cjs/typings/common.d.ts +7 -0
  19. package/build/cjs/typings/common.js.map +1 -1
  20. package/build/esm/components/GridItem/GridItem.js +13 -0
  21. package/build/esm/components/GridItem/GridItem.js.map +1 -1
  22. package/build/esm/components/GridLayout/GridLayout.d.ts +6 -1
  23. package/build/esm/components/GridLayout/GridLayout.js +55 -35
  24. package/build/esm/components/GridLayout/GridLayout.js.map +1 -1
  25. package/build/esm/components/GridLayout/GroupLayout.d.ts +29 -0
  26. package/build/esm/components/GridLayout/GroupLayout.js +56 -0
  27. package/build/esm/components/GridLayout/GroupLayout.js.map +1 -0
  28. package/build/esm/components/GridLayout/ReactGridLayout.d.ts +7 -2
  29. package/build/esm/components/GridLayout/ReactGridLayout.js +24 -11
  30. package/build/esm/components/GridLayout/ReactGridLayout.js.map +1 -1
  31. package/build/esm/components/GridLayout/utils.d.ts +2 -0
  32. package/build/esm/components/GridLayout/utils.js +21 -0
  33. package/build/esm/components/GridLayout/utils.js.map +1 -0
  34. package/build/esm/hocs/prepareItem.js +19 -5
  35. package/build/esm/hocs/prepareItem.js.map +1 -1
  36. package/build/esm/package.json +1 -1
  37. package/build/esm/typings/common.d.ts +7 -0
  38. package/build/esm/typings/common.js.map +1 -1
  39. package/package.json +1 -1
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupLayout = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = tslib_1.__importDefault(require("react"));
6
+ const constants_1 = require("../../constants/index.js");
7
+ const context_1 = require("../../context/index.js");
8
+ const GridItem_1 = tslib_1.__importDefault(require("../GridItem/GridItem.js"));
9
+ const ReactGridLayout_1 = require("./ReactGridLayout.js");
10
+ const utils_1 = require("./utils.js");
11
+ function groupLayoutPropsAreEqual(prev, next) {
12
+ const needRerenderIfChanged = prev.group !== next.group ||
13
+ prev.layout !== next.layout ||
14
+ prev.offset !== next.offset ||
15
+ !(0, utils_1.shallowArrayEqual)(prev.renderItems, next.renderItems) ||
16
+ !(0, utils_1.shallowObjectEqual)(prev.properties, next.properties);
17
+ // Drag refs are stable and never trigger re-renders; only group-scoped state matters.
18
+ const needRerenderGroupScoped = prev.isDragCaptured !== next.isDragCaptured ||
19
+ prev.isAnyDragging !== next.isAnyDragging ||
20
+ prev.currentDraggingItemId !== next.currentDraggingItemId ||
21
+ prev.isAnyDraggedOut !== next.isAnyDraggedOut;
22
+ const hasTmpPlaceholderChanged = prev.temporaryPlaceholder !== next.temporaryPlaceholder;
23
+ return !needRerenderIfChanged && !needRerenderGroupScoped && !hasTmpPlaceholderChanged;
24
+ }
25
+ exports.GroupLayout = react_1.default.memo(function GroupLayout({ group, renderItems, offset, properties, compactType, callbacks, layout, temporaryPlaceholder, dragStateRef, sharedDragPositionRef, isDragCaptured, isAnyDragging, currentDraggingItemId, isAnyDraggedOut, adjustWidgetLayout, getMemoForwardRefCallback, }) {
26
+ const { editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, onItemFocus, onItemBlur, } = react_1.default.useContext(context_1.DashKitContext);
27
+ // Use group-specific noOverlay if it was explicitly set via groupGridProperties,
28
+ // otherwise fallback to the dashboard-level noOverlay from context.
29
+ const resolvedNoOverlay = 'noOverlay' in properties ? properties.noOverlay : noOverlay;
30
+ // Memoize items array; non-source groups have stable false/null drag props so React skips their subtrees.
31
+ const itemElements = react_1.default.useMemo(() => {
32
+ return renderItems.map((item, i) => {
33
+ const keyId = item.id;
34
+ const isDragging = isAnyDragging && keyId === currentDraggingItemId;
35
+ const isDraggedOut = isDragging && isAnyDraggedOut;
36
+ return (react_1.default.createElement(GridItem_1.default, { key: keyId, forwardedPluginRef: getMemoForwardRefCallback(offset + i), id: keyId, item: item, layout: layout, adjustWidgetLayout: adjustWidgetLayout, isDragging: isDragging, isDraggedOut: isDraggedOut || undefined, noOverlay: resolvedNoOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender, gridLayout: properties, onItemFocus: onItemFocus, onItemBlur: onItemBlur }));
37
+ });
38
+ }, [
39
+ renderItems,
40
+ isAnyDragging,
41
+ currentDraggingItemId,
42
+ isAnyDraggedOut,
43
+ offset,
44
+ layout,
45
+ adjustWidgetLayout,
46
+ resolvedNoOverlay,
47
+ focusable,
48
+ draggableHandleClassName,
49
+ onItemMountChange,
50
+ onItemRender,
51
+ properties,
52
+ onItemFocus,
53
+ onItemBlur,
54
+ getMemoForwardRefCallback,
55
+ ]);
56
+ return (react_1.default.createElement(ReactGridLayout_1.Layout, Object.assign({ key: `group_${group}`, isDraggable: editMode, isResizable: editMode }, properties, { compactType: compactType, layout: layout, draggableCancel: `.${constants_1.DRAGGABLE_CANCEL_CLASS_NAME}`, draggableHandle: draggableHandleClassName ? `.${draggableHandleClassName}` : undefined, onDragStart: callbacks.onDragStart, onDrag: callbacks.onDrag, onDragStop: callbacks.onDragStop, onResizeStart: callbacks.onResizeStart, onResize: callbacks.onResize, onResizeStop: callbacks.onResizeStop, onDragTargetRestore: callbacks.onDragTargetRestore, onDropDragOver: callbacks.onDropDragOver, onDrop: callbacks.onDrop, dragStateRef: dragStateRef, sharedDragPositionRef: sharedDragPositionRef, group: group, isDragCaptured: isDragCaptured, isDroppable: Boolean(outerDnDEnable) && editMode }),
57
+ itemElements,
58
+ temporaryPlaceholder));
59
+ }, groupLayoutPropsAreEqual);
60
+ //# sourceMappingURL=GroupLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupLayout.js","sourceRoot":"../../../../src","sources":["components/GridLayout/GroupLayout.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAE1B,wDAA4D;AAC5D,oDAA6C;AAG7C,+EAA4C;AAE5C,0DAAyC;AAEzC,sCAA8D;AA6B9D,SAAS,wBAAwB,CAAC,IAAsB,EAAE,IAAsB;IAC5E,MAAM,qBAAqB,GACvB,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK;QACzB,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC3B,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAC3B,CAAC,IAAA,yBAAiB,EAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC;QACtD,CAAC,IAAA,0BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAE1D,sFAAsF;IACtF,MAAM,uBAAuB,GACzB,IAAI,CAAC,cAAc,KAAK,IAAI,CAAC,cAAc;QAC3C,IAAI,CAAC,aAAa,KAAK,IAAI,CAAC,aAAa;QACzC,IAAI,CAAC,qBAAqB,KAAK,IAAI,CAAC,qBAAqB;QACzD,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AAc,EACxC,MAAM,EAAE,SAAS,CAAC,MAAM,EACxB,YAAY,EAAE,YAAY,EAC1B,qBAAqB,EAAE,qBAAqB,EAC5C,KAAK,EAAE,KAAK,EACZ,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,OAAO,CAAC,cAAc,CAAC,IAAI,QAAQ;QAE/C,YAAY;QACZ,oBAAoB,CAChB,CACZ,CAAC;AACN,CAAC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import React from 'react';\n\nimport {DRAGGABLE_CANCEL_CLASS_NAME} from '../../constants';\nimport {DashKitContext} from '../../context';\nimport type {ConfigItem, ConfigLayout} from '../../shared';\nimport type {PluginRef, PluginWidgetProps, ReactGridLayoutProps} from '../../typings';\nimport GridItem from '../GridItem/GridItem';\n\nimport {Layout} from './ReactGridLayout';\nimport type {GroupCallbacks} from './types';\nimport {shallowArrayEqual, shallowObjectEqual} from './utils';\n\nexport interface GroupLayoutProps {\n group: string;\n renderItems: ConfigItem[];\n offset: number;\n\n // Pre-computed by GridLayout.renderGroup (stable refs via getMemoGroupProps)\n properties: Partial<ReactGridLayoutProps>;\n compactType: 'vertical' | 'horizontal' | null | undefined;\n callbacks: GroupCallbacks;\n layout: ConfigLayout[];\n temporaryPlaceholder: React.ReactNode;\n\n // Refs read imperatively by DragOverLayout — no re-render on drag start.\n isDragCaptured: boolean;\n dragStateRef: React.MutableRefObject<{isDragging: boolean; sourceGroup: string | null}>;\n sharedDragPositionRef: React.MutableRefObject<{offsetX: number; offsetY: number} | null>;\n\n // Drag state scoped to this group only (always false/null for non-source groups)\n isAnyDragging: boolean;\n currentDraggingItemId: string | null;\n isAnyDraggedOut: boolean;\n\n // Stable instance method refs from GridLayout (arrow function class properties)\n adjustWidgetLayout: PluginWidgetProps['adjustWidgetLayout'];\n getMemoForwardRefCallback: (index: number) => (ref: PluginRef) => void;\n}\n\nfunction groupLayoutPropsAreEqual(prev: GroupLayoutProps, next: GroupLayoutProps): boolean {\n const needRerenderIfChanged =\n prev.group !== next.group ||\n prev.layout !== next.layout ||\n prev.offset !== next.offset ||\n !shallowArrayEqual(prev.renderItems, next.renderItems) ||\n !shallowObjectEqual(prev.properties, next.properties);\n\n // Drag refs are stable and never trigger re-renders; only group-scoped state matters.\n const needRerenderGroupScoped =\n prev.isDragCaptured !== next.isDragCaptured ||\n prev.isAnyDragging !== next.isAnyDragging ||\n prev.currentDraggingItemId !== next.currentDraggingItemId ||\n prev.isAnyDraggedOut !== next.isAnyDraggedOut;\n\n const hasTmpPlaceholderChanged = prev.temporaryPlaceholder !== next.temporaryPlaceholder;\n\n return !needRerenderIfChanged && !needRerenderGroupScoped && !hasTmpPlaceholderChanged;\n}\n\nexport const GroupLayout = React.memo(function GroupLayout({\n group,\n renderItems,\n offset,\n properties,\n compactType,\n callbacks,\n layout,\n temporaryPlaceholder,\n dragStateRef,\n sharedDragPositionRef,\n isDragCaptured,\n isAnyDragging,\n currentDraggingItemId,\n isAnyDraggedOut,\n adjustWidgetLayout,\n getMemoForwardRefCallback,\n}: GroupLayoutProps) {\n const {\n editMode,\n noOverlay,\n focusable,\n draggableHandleClassName,\n outerDnDEnable,\n onItemMountChange,\n onItemRender,\n onItemFocus,\n onItemBlur,\n } = React.useContext(DashKitContext);\n\n // Use group-specific noOverlay if it was explicitly set via groupGridProperties,\n // otherwise fallback to the dashboard-level noOverlay from context.\n const resolvedNoOverlay = 'noOverlay' in properties ? properties.noOverlay : noOverlay;\n\n // Memoize items array; non-source groups have stable false/null drag props so React skips their subtrees.\n const itemElements = React.useMemo(() => {\n return renderItems.map((item, i) => {\n const keyId = item.id;\n\n const isDragging = isAnyDragging && keyId === currentDraggingItemId;\n const isDraggedOut = isDragging && isAnyDraggedOut;\n\n return (\n <GridItem\n key={keyId}\n forwardedPluginRef={getMemoForwardRefCallback(offset + i)}\n id={keyId}\n item={item}\n layout={layout}\n adjustWidgetLayout={adjustWidgetLayout}\n isDragging={isDragging}\n isDraggedOut={isDraggedOut || undefined}\n noOverlay={resolvedNoOverlay}\n focusable={focusable}\n withCustomHandle={Boolean(draggableHandleClassName)}\n onItemMountChange={onItemMountChange}\n onItemRender={onItemRender}\n gridLayout={properties}\n onItemFocus={onItemFocus}\n onItemBlur={onItemBlur}\n />\n );\n });\n }, [\n renderItems,\n isAnyDragging,\n currentDraggingItemId,\n isAnyDraggedOut,\n offset,\n layout,\n adjustWidgetLayout,\n resolvedNoOverlay,\n focusable,\n draggableHandleClassName,\n onItemMountChange,\n onItemRender,\n properties,\n onItemFocus,\n onItemBlur,\n getMemoForwardRefCallback,\n ]);\n\n return (\n <Layout\n key={`group_${group}`}\n isDraggable={editMode}\n isResizable={editMode}\n {...properties}\n compactType={compactType}\n layout={layout}\n draggableCancel={`.${DRAGGABLE_CANCEL_CLASS_NAME}`}\n draggableHandle={draggableHandleClassName ? `.${draggableHandleClassName}` : undefined}\n onDragStart={callbacks.onDragStart}\n onDrag={callbacks.onDrag}\n onDragStop={callbacks.onDragStop}\n onResizeStart={callbacks.onResizeStart}\n onResize={callbacks.onResize}\n onResizeStop={callbacks.onResizeStop}\n onDragTargetRestore={callbacks.onDragTargetRestore}\n onDropDragOver={callbacks.onDropDragOver}\n onDrop={callbacks.onDrop}\n dragStateRef={dragStateRef}\n sharedDragPositionRef={sharedDragPositionRef}\n group={group}\n isDragCaptured={isDragCaptured}\n isDroppable={Boolean(outerDnDEnable) && editMode}\n >\n {itemElements}\n {temporaryPlaceholder}\n </Layout>\n );\n}, groupLayoutPropsAreEqual);\n"]}
@@ -7,8 +7,13 @@ type SharedDragPosition = {
7
7
  export declare const Layout: React.ComponentClass<ReactGridLayout.ReactGridLayoutProps & {
8
8
  innerRef?: React.Ref<HTMLDivElement>;
9
9
  isDragCaptured?: boolean;
10
- hasSharedDragItem?: boolean;
11
- sharedDragPosition?: SharedDragPosition;
10
+ dragStateRef?: React.MutableRefObject<{
11
+ isDragging: boolean;
12
+ sourceGroup: string | null;
13
+ }>;
14
+ sharedDragPositionRef?: React.MutableRefObject<SharedDragPosition | null>;
15
+ group?: string;
12
16
  onDragTargetRestore?: () => void;
17
+ transformScaleRef?: React.MutableRefObject<number>;
13
18
  } & ReactGridLayout.WidthProviderProps, any>;
14
19
  export {};
@@ -85,10 +85,17 @@ class DragOverLayout extends react_grid_layout_1.default {
85
85
  this.parentOnDragStop(i, x, y, sintEv);
86
86
  }
87
87
  };
88
+ // Returns true when another group's item is being dragged over this grid.
89
+ // Reads from the ref directly — no re-render required to stay current.
90
+ this.isSharedDragTarget = () => {
91
+ var _a;
92
+ const drag = (_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current;
93
+ return Boolean((drag === null || drag === void 0 ? void 0 : drag.isDragging) && (drag === null || drag === void 0 ? void 0 : drag.sourceGroup) !== this.props.group);
94
+ };
88
95
  // Proxy mouse events -> drag methods for dnd between groups
89
96
  this.mouseEnterHandler = (e) => {
90
97
  var _a, _b;
91
- if (this.props.hasSharedDragItem) {
98
+ if (this.isSharedDragTarget()) {
92
99
  // @ts-expect-error - onDragEnter is a protected method in parent class
93
100
  this.onDragEnter(e);
94
101
  }
@@ -98,14 +105,14 @@ class DragOverLayout extends react_grid_layout_1.default {
98
105
  };
99
106
  this.mouseLeaveHandler = (e) => {
100
107
  var _a, _b;
101
- if (this.props.hasSharedDragItem) {
108
+ if (this.isSharedDragTarget()) {
102
109
  // @ts-expect-error - onDragLeave is a protected method in parent class
103
110
  this.onDragLeave(e);
104
111
  (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
105
112
  }
106
113
  };
107
114
  this.mouseMoveHandler = (e) => {
108
- if (this.props.hasSharedDragItem) {
115
+ if (this.isSharedDragTarget()) {
109
116
  if (!e.nativeEvent) {
110
117
  // Emulate nativeEvent for firefox
111
118
  const target = this.getInnerElement() || e.target;
@@ -121,7 +128,7 @@ class DragOverLayout extends react_grid_layout_1.default {
121
128
  };
122
129
  this.mouseUpHandler = (e) => {
123
130
  var _a, _b;
124
- if (this.props.hasSharedDragItem) {
131
+ if (this.isSharedDragTarget()) {
125
132
  e.preventDefault();
126
133
  const { droppingItem } = this.props;
127
134
  const { layout } = this.state;
@@ -187,8 +194,9 @@ class DragOverLayout extends react_grid_layout_1.default {
187
194
  return innerRef && isRefObject(innerRef) && innerRef.current ? innerRef.current : null;
188
195
  }
189
196
  calculateDroppingPosition(itemProps) {
197
+ var _a;
190
198
  const { containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition } = itemProps;
191
- const { sharedDragPosition } = this.props;
199
+ const sharedDragPosition = (_a = this.props.sharedDragPositionRef) === null || _a === void 0 ? void 0 : _a.current;
192
200
  let offsetX, offsetY;
193
201
  if (sharedDragPosition) {
194
202
  offsetX = sharedDragPosition.offsetX;
@@ -211,15 +219,20 @@ class DragOverLayout extends react_grid_layout_1.default {
211
219
  if (!gridItem) {
212
220
  return gridItem;
213
221
  }
222
+ // Lazy proxy for transformScaleRef so react-draggable reads fresh scale without re-render.
223
+ const { transformScaleRef } = this.props;
224
+ const lazyScale = transformScaleRef
225
+ ? { valueOf: () => transformScaleRef.current }
226
+ : undefined;
214
227
  if (isDroppingItem) {
215
228
  // React.cloneElement is just cleaner then copy-paste whole processGridItem method
216
- return react_1.default.cloneElement(gridItem, {
229
+ return react_1.default.cloneElement(gridItem, Object.assign(Object.assign({}, (lazyScale !== undefined && { transformScale: lazyScale })), {
217
230
  // hiding preview if dragging shared item
218
- style: this.props.hasSharedDragItem
219
- ? Object.assign(Object.assign({}, gridItem.props.style), { opacity: 0 }) : gridItem.props.style,
220
- className: `${constants_1.OVERLAY_CLASS_NAME} ${constants_1.DROPPING_ELEMENT_CLASS_NAME}`,
221
- droppingPosition: this.calculateDroppingPosition(gridItem.props),
222
- });
231
+ style: this.isSharedDragTarget()
232
+ ? Object.assign(Object.assign({}, gridItem.props.style), { opacity: 0 }) : gridItem.props.style, className: `${constants_1.OVERLAY_CLASS_NAME} ${constants_1.DROPPING_ELEMENT_CLASS_NAME}`, droppingPosition: this.calculateDroppingPosition(gridItem.props) }));
233
+ }
234
+ if (lazyScale !== undefined) {
235
+ return react_1.default.cloneElement(gridItem, { transformScale: lazyScale });
223
236
  }
224
237
  return gridItem;
225
238
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ReactGridLayout.js","sourceRoot":"../../../../src","sources":["components/GridLayout/ReactGridLayout.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAG1B,+DAA+D;AAC/D,+EAAwE;AAExE,wDAAgF;AAEhF,MAAM,WAAW,GAAG,CAChB,KAAgC,EACQ,EAAE;IAC1C,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CACpC,CAAC;AACN,CAAC,CAAC;AA6BF,MAAM,cAAe,SAAQ,2BAAe;IAUxC,YAAY,KAA0B,EAAE,OAAiB;QACrD,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAH1B,2BAAsB,GAAuB,IAAI,CAAC;QAoElD,mDAAmD;QACnD,6BAAwB,GAAG,GAAS,EAAE;YAClC,8EAA8E;YAC9E,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACxB,8EAA8E;gBAC9E,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;gBAC1B,qFAAqF;gBACrF,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACrC,CAAC;QACL,CAAC,CAAC;QAEF,+CAA+C;QAC/C,yBAAoB,GAAG,CAAC,CAAS,EAAe,EAAE;YAC9C,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC5B,MAAM,EAAC,IAAI,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;YAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,mBAAK,IAAI,EAAE,CAAC,CAAC;YAEtD,IAAI,aAAoC,CAAC;YACzC,MAAM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from 'react-grid-layout';\n// @ts-expect-error - utils is not exported in type definitions\nimport ReactGridLayout, {WidthProvider, utils} from 'react-grid-layout';\n\nimport {DROPPING_ELEMENT_CLASS_NAME, OVERLAY_CLASS_NAME} from '../../constants';\n\nconst isRefObject = (\n value: React.Ref<HTMLDivElement>,\n): value is React.RefObject<HTMLDivElement> => {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'current' in value &&\n typeof value.current === 'object'\n );\n};\n\ntype SharedDragPosition = {\n offsetX: number;\n offsetY: number;\n};\n\ntype DragOverLayoutProps = ReactGridLayout.ReactGridLayoutProps & {\n innerRef?: React.Ref<HTMLDivElement>;\n isDragCaptured?: boolean;\n hasSharedDragItem?: boolean;\n sharedDragPosition?: SharedDragPosition;\n onDragTargetRestore?: () => void;\n};\n\ntype DragOverLayoutState = {\n layout: RGLLayout[];\n activeDrag: RGLLayout | null;\n};\n\ntype RGLLayoutWithPlaceholder = RGLLayout & {placeholder?: boolean};\n\ntype OnDragMethod = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n) => void;\n\nclass DragOverLayout extends ReactGridLayout {\n // @ts-expect-error - TypeScript doesn't allow direct property redeclaration in extending classes. We need to narrow the props type from ReactGridLayoutProps to DragOverLayoutProps for type safety in our custom methods\n props: DragOverLayoutProps;\n // @ts-expect-error - TypeScript doesn't allow direct property redeclaration in extending classes. State is initialized by parent constructor\n state: DragOverLayoutState;\n\n parentOnDrag: OnDragMethod;\n parentOnDragStop: OnDragMethod;\n _savedDraggedOutLayout: RGLLayout[] | null = null;\n\n constructor(props: DragOverLayoutProps, context?: unknown) {\n super(props, context);\n\n // @ts-expect-error - onDrag is a protected method in parent class\n this.parentOnDrag = this.onDrag;\n // @ts-expect-error - assigning custom method to parent's onDrag\n this.onDrag = this.extendedOnDrag;\n\n // @ts-expect-error - onDragStop is a protected method in parent class\n this.parentOnDragStop = this.onDragStop;\n // @ts-expect-error - assigning custom method to parent's onDragStop\n this.onDragStop = this.extendedOnDragStop;\n }\n\n componentDidMount(): void {\n super.componentDidMount?.();\n\n // If cursor is moved out of the window there is a bug\n // which leaves placeholder element in grid, this action needed to reset this state\n window.addEventListener('dragend', this.resetExternalPlaceholder);\n const innerElement = this.getInnerElement();\n\n if (innerElement) {\n innerElement.addEventListener('mouseup', this.mouseUpHandler);\n innerElement.addEventListener('mouseenter', this.mouseEnterHandler);\n innerElement.addEventListener('mouseleave', this.mouseLeaveHandler);\n innerElement.addEventListener('mousemove', this.mouseMoveHandler);\n }\n }\n\n componentWillUnmount(): void {\n window.removeEventListener('dragend', this.resetExternalPlaceholder);\n const innerElement = this.getInnerElement();\n\n if (innerElement) {\n innerElement.removeEventListener('mouseup', this.mouseUpHandler);\n innerElement.removeEventListener('mouseenter', this.mouseEnterHandler);\n innerElement.removeEventListener('mouseleave', this.mouseLeaveHandler);\n innerElement.removeEventListener('mousemove', this.mouseMoveHandler);\n }\n }\n\n // react-grid-layout doens't calculate it's height when last element is removed\n // and just keeps the previous value\n // so for autosize to work in that case we are resetting it's height value\n containerHeight(): string | undefined {\n if (this.props.autoSize && this.state.layout.length === 0) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n // @ts-expect-error - containerHeight is a protected method in parent class\n return super.containerHeight();\n }\n\n // innerRef is passed by WithProvider without this wrapper there are only\n // * findDOMNode - deprecated\n // * rewrite whole ReactGridLayout.render method\n // so in that case don't try to use this class on it's own\n // or pass innerRef: React.MutableRef as it's not optional prop\n getInnerElement(): HTMLDivElement | null {\n const {innerRef} = this.props;\n\n return innerRef && isRefObject(innerRef) && innerRef.current ? innerRef.current : null;\n }\n\n // Reset placeholder when item dragged from outside\n resetExternalPlaceholder = (): void => {\n // @ts-expect-error - dragEnterCounter is an internal property of parent class\n if (this.dragEnterCounter) {\n // @ts-expect-error - dragEnterCounter is an internal property of parent class\n this.dragEnterCounter = 0;\n // @ts-expect-error - removeDroppingPlaceholder is a protected method in parent class\n this.removeDroppingPlaceholder();\n }\n };\n\n // Hide placeholder when element is dragged out\n hideLocalPlaceholder = (i: string): RGLLayout[] => {\n const {layout} = this.state;\n const {cols} = this.props;\n const savedLayout = layout.map((item) => ({...item}));\n\n let hiddenElement: RGLLayout | undefined;\n const newLayout = utils.compact(\n layout.filter((item) => {\n if (item.i === i) {\n hiddenElement = item;\n return false;\n }\n\n return true;\n }),\n utils.compactType(this.props),\n cols,\n );\n\n if (hiddenElement) {\n newLayout.push(hiddenElement);\n }\n\n this.setState({\n activeDrag: null,\n layout: newLayout,\n });\n\n return savedLayout;\n };\n\n extendedOnDrag = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n ): void => {\n if (this.props.isDragCaptured) {\n if (!this._savedDraggedOutLayout) {\n this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);\n }\n\n return;\n }\n\n this._savedDraggedOutLayout = null;\n // parent onDrag will show new placeholder again\n this.parentOnDrag(i, x, y, sintEv);\n };\n\n extendedOnDragStop = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n ): void => {\n // Restoring layout if item was dropped outside of the grid\n if (this._savedDraggedOutLayout) {\n const savedLayout = this._savedDraggedOutLayout;\n const l = utils.getLayoutItem(savedLayout, i);\n\n // Create placeholder (display only)\n const placeholder: RGLLayoutWithPlaceholder = {\n w: l.w,\n h: l.h,\n x: l.x,\n y: l.y,\n placeholder: true,\n i: i,\n };\n\n this.setState(\n {\n layout: savedLayout,\n activeDrag: placeholder,\n },\n () => {\n this.parentOnDragStop(i, x, y, sintEv);\n },\n );\n\n this._savedDraggedOutLayout = null;\n } else {\n this.parentOnDragStop(i, x, y, sintEv);\n }\n };\n\n // Proxy mouse events -> drag methods for dnd between groups\n mouseEnterHandler = (e: MouseEvent): void => {\n if (this.props.hasSharedDragItem) {\n // @ts-expect-error - onDragEnter is a protected method in parent class\n this.onDragEnter(e);\n } else if (this.props.isDragCaptured) {\n this.props.onDragTargetRestore?.();\n }\n };\n\n mouseLeaveHandler = (e: MouseEvent): void => {\n if (this.props.hasSharedDragItem) {\n // @ts-expect-error - onDragLeave is a protected method in parent class\n this.onDragLeave(e);\n this.props.onDragTargetRestore?.();\n }\n };\n\n mouseMoveHandler = (e: MouseEvent): void => {\n if (this.props.hasSharedDragItem) {\n if (!(e as MouseEvent & {nativeEvent?: MouseEvent}).nativeEvent) {\n // Emulate nativeEvent for firefox\n const target = this.getInnerElement() || (e.target as HTMLElement);\n\n (e as MouseEvent & {nativeEvent: Partial<MouseEvent>}).nativeEvent = {\n clientX: e.clientX,\n clientY: e.clientY,\n target,\n };\n }\n\n // @ts-expect-error - onDragOver is a protected method in parent class\n this.onDragOver(e);\n }\n };\n\n mouseUpHandler = (e: MouseEvent): void => {\n if (this.props.hasSharedDragItem) {\n e.preventDefault();\n const {droppingItem} = this.props;\n const {layout} = this.state;\n const item = layout.find((l) => l.i === droppingItem?.i);\n\n // reset dragEnter counter on drop\n this.resetExternalPlaceholder();\n\n if (item) {\n this.props.onDrop?.(layout, item, e);\n }\n }\n };\n\n calculateDroppingPosition(itemProps: {\n containerWidth: number;\n cols: number;\n w: number;\n h: number;\n rowHeight: number;\n margin: [number, number];\n transformScale: number;\n droppingPosition: {left: number; top: number};\n }): {left: number; top: number} {\n const {containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition} =\n itemProps;\n const {sharedDragPosition} = this.props;\n\n let offsetX: number, offsetY: number;\n\n if (sharedDragPosition) {\n offsetX = sharedDragPosition.offsetX;\n offsetY = sharedDragPosition.offsetY;\n } else {\n offsetX = (((containerWidth / cols) * w) / 2 || 0) * transformScale;\n offsetY = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;\n }\n\n return {\n ...droppingPosition,\n left: droppingPosition.left - offsetX,\n top: droppingPosition.top - offsetY,\n };\n }\n\n // Drop item from outside gets 0,0 droppingPosition\n // centering cursor on newly creted grid item\n // And cause grid-layout using it's own GridItem to make it look\n // like overlay adding className\n processGridItem(\n child: React.ReactElement,\n isDroppingItem?: boolean,\n ): React.ReactElement | undefined {\n // @ts-expect-error - processGridItem is a protected method in parent class\n const gridItem = super.processGridItem?.(child, isDroppingItem);\n\n if (!gridItem) {\n return gridItem;\n }\n\n if (isDroppingItem) {\n // React.cloneElement is just cleaner then copy-paste whole processGridItem method\n return React.cloneElement(gridItem, {\n // hiding preview if dragging shared item\n style: this.props.hasSharedDragItem\n ? {...gridItem.props.style, opacity: 0}\n : gridItem.props.style,\n className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`,\n droppingPosition: this.calculateDroppingPosition(gridItem.props),\n });\n }\n\n return gridItem;\n }\n}\n\n// eslint-disable-next-line new-cap\nexport const Layout = WidthProvider<DragOverLayoutProps>(DragOverLayout);\n"]}
1
+ {"version":3,"file":"ReactGridLayout.js","sourceRoot":"../../../../src","sources":["components/GridLayout/ReactGridLayout.tsx"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAG1B,+DAA+D;AAC/D,+EAAwE;AAExE,wDAAgF;AAEhF,MAAM,WAAW,GAAG,CAChB,KAAgC,EACQ,EAAE;IAC1C,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CACpC,CAAC;AACN,CAAC,CAAC;AA+BF,MAAM,cAAe,SAAQ,2BAAe;IAUxC,YAAY,KAA0B,EAAE,OAAiB;QACrD,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAH1B,2BAAsB,GAAuB,IAAI,CAAC;QAoElD,mDAAmD;QACnD,6BAAwB,GAAG,GAAS,EAAE;YAClC,8EAA8E;YAC9E,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBACxB,8EAA8E;gBAC9E,IAAI,CAAC,gBAAgB,GAAG,CAAC,CAAC;gBAC1B,qFAAqF;gBACrF,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACrC,CAAC;QACL,CAAC,CAAC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QAEhE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,OAAO,QAAQ,CAAC;QACpB,CAAC;QAED,2FAA2F;QAC3F,MAAM,EAAC,iBAAiB,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;QACvC,MAAM,SAAS,GAAG,iBAAiB;YAC/B,CAAC,CAAE,EAAC,OAAO,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAuB;YACnE,CAAC,CAAC,SAAS,CAAC;QAEhB,IAAI,cAAc,EAAE,CAAC;YACjB,kFAAkF;YAClF,OAAO,eAAK,CAAC,YAAY,CAAC,QAAQ,kCAC3B,CAAC,SAAS,KAAK,SAAS,IAAI,EAAC,cAAc,EAAE,SAAS,EAAC,CAAC;gBAC3D,yCAAyC;gBACzC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE;oBAC5B,CAAC,iCAAK,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAE,OAAO,EAAE,CAAC,IACtC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAC1B,SAAS,EAAE,GAAG,8BAAkB,IAAI,uCAA2B,EAAE,EACjE,gBAAgB,EAAE,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC,IAClE,CAAC;QACP,CAAC;QAED,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,eAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAC,cAAc,EAAE,SAAS,EAAC,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAED,mCAAmC;AACtB,QAAA,MAAM,GAAG,IAAA,iCAAa,EAAsB,cAAc,CAAC,CAAC","sourcesContent":["import React from 'react';\n\nimport type {Layout as RGLLayout} from 'react-grid-layout';\n// @ts-expect-error - utils is not exported in type definitions\nimport ReactGridLayout, {WidthProvider, utils} from 'react-grid-layout';\n\nimport {DROPPING_ELEMENT_CLASS_NAME, OVERLAY_CLASS_NAME} from '../../constants';\n\nconst isRefObject = (\n value: React.Ref<HTMLDivElement>,\n): value is React.RefObject<HTMLDivElement> => {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'current' in value &&\n typeof value.current === 'object'\n );\n};\n\ntype SharedDragPosition = {\n offsetX: number;\n offsetY: number;\n};\n\ntype DragOverLayoutProps = ReactGridLayout.ReactGridLayoutProps & {\n innerRef?: React.Ref<HTMLDivElement>;\n isDragCaptured?: boolean;\n dragStateRef?: React.MutableRefObject<{isDragging: boolean; sourceGroup: string | null}>;\n sharedDragPositionRef?: React.MutableRefObject<SharedDragPosition | null>;\n group?: string;\n onDragTargetRestore?: () => void;\n transformScaleRef?: React.MutableRefObject<number>;\n};\n\ntype DragOverLayoutState = {\n layout: RGLLayout[];\n activeDrag: RGLLayout | null;\n};\n\ntype RGLLayoutWithPlaceholder = RGLLayout & {placeholder?: boolean};\n\ntype OnDragMethod = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n) => void;\n\nclass DragOverLayout extends ReactGridLayout {\n // @ts-expect-error - TypeScript doesn't allow direct property redeclaration in extending classes. We need to narrow the props type from ReactGridLayoutProps to DragOverLayoutProps for type safety in our custom methods\n props: DragOverLayoutProps;\n // @ts-expect-error - TypeScript doesn't allow direct property redeclaration in extending classes. State is initialized by parent constructor\n state: DragOverLayoutState;\n\n parentOnDrag: OnDragMethod;\n parentOnDragStop: OnDragMethod;\n _savedDraggedOutLayout: RGLLayout[] | null = null;\n\n constructor(props: DragOverLayoutProps, context?: unknown) {\n super(props, context);\n\n // @ts-expect-error - onDrag is a protected method in parent class\n this.parentOnDrag = this.onDrag;\n // @ts-expect-error - assigning custom method to parent's onDrag\n this.onDrag = this.extendedOnDrag;\n\n // @ts-expect-error - onDragStop is a protected method in parent class\n this.parentOnDragStop = this.onDragStop;\n // @ts-expect-error - assigning custom method to parent's onDragStop\n this.onDragStop = this.extendedOnDragStop;\n }\n\n componentDidMount(): void {\n super.componentDidMount?.();\n\n // If cursor is moved out of the window there is a bug\n // which leaves placeholder element in grid, this action needed to reset this state\n window.addEventListener('dragend', this.resetExternalPlaceholder);\n const innerElement = this.getInnerElement();\n\n if (innerElement) {\n innerElement.addEventListener('mouseup', this.mouseUpHandler);\n innerElement.addEventListener('mouseenter', this.mouseEnterHandler);\n innerElement.addEventListener('mouseleave', this.mouseLeaveHandler);\n innerElement.addEventListener('mousemove', this.mouseMoveHandler);\n }\n }\n\n componentWillUnmount(): void {\n window.removeEventListener('dragend', this.resetExternalPlaceholder);\n const innerElement = this.getInnerElement();\n\n if (innerElement) {\n innerElement.removeEventListener('mouseup', this.mouseUpHandler);\n innerElement.removeEventListener('mouseenter', this.mouseEnterHandler);\n innerElement.removeEventListener('mouseleave', this.mouseLeaveHandler);\n innerElement.removeEventListener('mousemove', this.mouseMoveHandler);\n }\n }\n\n // react-grid-layout doens't calculate it's height when last element is removed\n // and just keeps the previous value\n // so for autosize to work in that case we are resetting it's height value\n containerHeight(): string | undefined {\n if (this.props.autoSize && this.state.layout.length === 0) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n // @ts-expect-error - containerHeight is a protected method in parent class\n return super.containerHeight();\n }\n\n // innerRef is passed by WithProvider without this wrapper there are only\n // * findDOMNode - deprecated\n // * rewrite whole ReactGridLayout.render method\n // so in that case don't try to use this class on it's own\n // or pass innerRef: React.MutableRef as it's not optional prop\n getInnerElement(): HTMLDivElement | null {\n const {innerRef} = this.props;\n\n return innerRef && isRefObject(innerRef) && innerRef.current ? innerRef.current : null;\n }\n\n // Reset placeholder when item dragged from outside\n resetExternalPlaceholder = (): void => {\n // @ts-expect-error - dragEnterCounter is an internal property of parent class\n if (this.dragEnterCounter) {\n // @ts-expect-error - dragEnterCounter is an internal property of parent class\n this.dragEnterCounter = 0;\n // @ts-expect-error - removeDroppingPlaceholder is a protected method in parent class\n this.removeDroppingPlaceholder();\n }\n };\n\n // Hide placeholder when element is dragged out\n hideLocalPlaceholder = (i: string): RGLLayout[] => {\n const {layout} = this.state;\n const {cols} = this.props;\n const savedLayout = layout.map((item) => ({...item}));\n\n let hiddenElement: RGLLayout | undefined;\n const newLayout = utils.compact(\n layout.filter((item) => {\n if (item.i === i) {\n hiddenElement = item;\n return false;\n }\n\n return true;\n }),\n utils.compactType(this.props),\n cols,\n );\n\n if (hiddenElement) {\n newLayout.push(hiddenElement);\n }\n\n this.setState({\n activeDrag: null,\n layout: newLayout,\n });\n\n return savedLayout;\n };\n\n extendedOnDrag = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n ): void => {\n if (this.props.isDragCaptured) {\n if (!this._savedDraggedOutLayout) {\n this._savedDraggedOutLayout = this.hideLocalPlaceholder(i);\n }\n\n return;\n }\n\n this._savedDraggedOutLayout = null;\n // parent onDrag will show new placeholder again\n this.parentOnDrag(i, x, y, sintEv);\n };\n\n extendedOnDragStop = (\n i: string,\n x: number,\n y: number,\n sintEv: {e: Event; node: HTMLElement},\n ): void => {\n // Restoring layout if item was dropped outside of the grid\n if (this._savedDraggedOutLayout) {\n const savedLayout = this._savedDraggedOutLayout;\n const l = utils.getLayoutItem(savedLayout, i);\n\n // Create placeholder (display only)\n const placeholder: RGLLayoutWithPlaceholder = {\n w: l.w,\n h: l.h,\n x: l.x,\n y: l.y,\n placeholder: true,\n i: i,\n };\n\n this.setState(\n {\n layout: savedLayout,\n activeDrag: placeholder,\n },\n () => {\n this.parentOnDragStop(i, x, y, sintEv);\n },\n );\n\n this._savedDraggedOutLayout = null;\n } else {\n this.parentOnDragStop(i, x, y, sintEv);\n }\n };\n\n // Returns true when another group's item is being dragged over this grid.\n // Reads from the ref directly — no re-render required to stay current.\n isSharedDragTarget = (): boolean => {\n const drag = this.props.dragStateRef?.current;\n return Boolean(drag?.isDragging && drag?.sourceGroup !== this.props.group);\n };\n\n // Proxy mouse events -> drag methods for dnd between groups\n mouseEnterHandler = (e: MouseEvent): void => {\n if (this.isSharedDragTarget()) {\n // @ts-expect-error - onDragEnter is a protected method in parent class\n this.onDragEnter(e);\n } else if (this.props.isDragCaptured) {\n this.props.onDragTargetRestore?.();\n }\n };\n\n mouseLeaveHandler = (e: MouseEvent): void => {\n if (this.isSharedDragTarget()) {\n // @ts-expect-error - onDragLeave is a protected method in parent class\n this.onDragLeave(e);\n this.props.onDragTargetRestore?.();\n }\n };\n\n mouseMoveHandler = (e: MouseEvent): void => {\n if (this.isSharedDragTarget()) {\n if (!(e as MouseEvent & {nativeEvent?: MouseEvent}).nativeEvent) {\n // Emulate nativeEvent for firefox\n const target = this.getInnerElement() || (e.target as HTMLElement);\n\n (e as MouseEvent & {nativeEvent: Partial<MouseEvent>}).nativeEvent = {\n clientX: e.clientX,\n clientY: e.clientY,\n target,\n };\n }\n\n // @ts-expect-error - onDragOver is a protected method in parent class\n this.onDragOver(e);\n }\n };\n\n mouseUpHandler = (e: MouseEvent): void => {\n if (this.isSharedDragTarget()) {\n e.preventDefault();\n const {droppingItem} = this.props;\n const {layout} = this.state;\n const item = layout.find((l) => l.i === droppingItem?.i);\n\n // reset dragEnter counter on drop\n this.resetExternalPlaceholder();\n\n if (item) {\n this.props.onDrop?.(layout, item, e);\n }\n }\n };\n\n calculateDroppingPosition(itemProps: {\n containerWidth: number;\n cols: number;\n w: number;\n h: number;\n rowHeight: number;\n margin: [number, number];\n transformScale: number;\n droppingPosition: {left: number; top: number};\n }): {left: number; top: number} {\n const {containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition} =\n itemProps;\n const sharedDragPosition = this.props.sharedDragPositionRef?.current;\n\n let offsetX: number, offsetY: number;\n\n if (sharedDragPosition) {\n offsetX = sharedDragPosition.offsetX;\n offsetY = sharedDragPosition.offsetY;\n } else {\n offsetX = (((containerWidth / cols) * w) / 2 || 0) * transformScale;\n offsetY = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;\n }\n\n return {\n ...droppingPosition,\n left: droppingPosition.left - offsetX,\n top: droppingPosition.top - offsetY,\n };\n }\n\n // Drop item from outside gets 0,0 droppingPosition\n // centering cursor on newly creted grid item\n // And cause grid-layout using it's own GridItem to make it look\n // like overlay adding className\n processGridItem(\n child: React.ReactElement,\n isDroppingItem?: boolean,\n ): React.ReactElement | undefined {\n // @ts-expect-error - processGridItem is a protected method in parent class\n const gridItem = super.processGridItem?.(child, isDroppingItem);\n\n if (!gridItem) {\n return gridItem;\n }\n\n // Lazy proxy for transformScaleRef so react-draggable reads fresh scale without re-render.\n const {transformScaleRef} = this.props;\n const lazyScale = transformScaleRef\n ? ({valueOf: () => transformScaleRef.current} as unknown as number)\n : undefined;\n\n if (isDroppingItem) {\n // React.cloneElement is just cleaner then copy-paste whole processGridItem method\n return React.cloneElement(gridItem, {\n ...(lazyScale !== undefined && {transformScale: lazyScale}),\n // hiding preview if dragging shared item\n style: this.isSharedDragTarget()\n ? {...gridItem.props.style, opacity: 0}\n : gridItem.props.style,\n className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`,\n droppingPosition: this.calculateDroppingPosition(gridItem.props),\n });\n }\n\n if (lazyScale !== undefined) {\n return React.cloneElement(gridItem, {transformScale: lazyScale});\n }\n\n return gridItem;\n }\n}\n\n// eslint-disable-next-line new-cap\nexport const Layout = WidthProvider<DragOverLayoutProps>(DragOverLayout);\n"]}
@@ -0,0 +1,2 @@
1
+ export declare function shallowArrayEqual<T>(a: T[], b: T[]): boolean;
2
+ export declare function shallowObjectEqual<T extends object>(a: T, b: T): boolean;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.shallowArrayEqual = shallowArrayEqual;
4
+ exports.shallowObjectEqual = shallowObjectEqual;
5
+ function shallowArrayEqual(a, b) {
6
+ if (a === b) {
7
+ return true;
8
+ }
9
+ if (a.length !== b.length) {
10
+ return false;
11
+ }
12
+ return a.every((item, i) => item === b[i]);
13
+ }
14
+ function shallowObjectEqual(a, b) {
15
+ if (a === b) {
16
+ return true;
17
+ }
18
+ const keysA = Object.keys(a);
19
+ const keysB = Object.keys(b);
20
+ if (keysA.length !== keysB.length) {
21
+ return false;
22
+ }
23
+ return keysA.every((key) => a[key] === b[key]);
24
+ }
25
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"../../../../src","sources":["components/GridLayout/utils.tsx"],"names":[],"mappings":";;AAAA,8CAQC;AAED,gDAUC;AApBD,SAAgB,iBAAiB,CAAI,CAAM,EAAE,CAAM;IAC/C,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,kBAAkB,CAAmB,CAAI,EAAE,CAAI;IAC3D,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACV,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAmB,CAAC;IAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAmB,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnD,CAAC","sourcesContent":["export function shallowArrayEqual<T>(a: T[], b: T[]): boolean {\n if (a === b) {\n return true;\n }\n if (a.length !== b.length) {\n return false;\n }\n return a.every((item, i) => item === b[i]);\n}\n\nexport function shallowObjectEqual<T extends object>(a: T, b: T): boolean {\n if (a === b) {\n return true;\n }\n const keysA = Object.keys(a) as Array<keyof T>;\n const keysB = Object.keys(b) as Array<keyof T>;\n if (keysA.length !== keysB.length) {\n return false;\n }\n return keysA.every((key) => a[key] === b[key]);\n}\n"]}
@@ -48,13 +48,27 @@ function prepareItem(WrappedComponent) {
48
48
  return this._currentRenderProps;
49
49
  };
50
50
  }
51
- shouldComponentUpdate(nextProps) {
51
+ shouldComponentUpdate(nextProps, _nextState, nextContext) {
52
52
  const { width, height, transform } = this.props;
53
53
  const { width: widthNext, height: heightNext, transform: transformNext } = nextProps;
54
- return (nextProps.shouldItemUpdate ||
55
- width !== widthNext ||
56
- height !== heightNext ||
57
- transform !== transformNext);
54
+ // Layout changes (position/size) always trigger re-render
55
+ if (width !== widthNext || height !== heightNext || transform !== transformNext) {
56
+ return true;
57
+ }
58
+ // While dragging — skip content updates
59
+ if (!nextProps.shouldItemUpdate) {
60
+ return false;
61
+ }
62
+ const id = this.props.id;
63
+ const ctx = this.context;
64
+ // Re-render only if data relevant to this specific item changed
65
+ return (this.props.item !== nextProps.item ||
66
+ this.props.layout !== nextProps.layout ||
67
+ ctx.itemsParams[id] !== nextContext.itemsParams[id] ||
68
+ ctx.itemsState[id] !== nextContext.itemsState[id] ||
69
+ ctx.editMode !== nextContext.editMode ||
70
+ ctx.settings !== nextContext.settings ||
71
+ ctx.context !== nextContext.context);
58
72
  }
59
73
  render() {
60
74
  const { item, isPlaceholder, forwardedPluginRef, onItemMountChange, onItemRender } = this.props;
@@ -1 +1 @@
1
- {"version":3,"file":"prepareItem.js","sourceRoot":"../../../src","sources":["hocs/prepareItem.tsx"],"names":[],"mappings":";;AA4BA,kCAsFC;;AAlHD,0DAA0B;AAE1B,wEAAqC;AAIrC,iDAA0C;AAsB1C,SAAgB,WAAW,CACvB,gBAAgD;;IAEhD,YAAO,MAAM,WAAY,SAAQ,eAAK,CAAC,SAA2B;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AAK,CAAC,CAAC;wBACjF,CAAC;wBAED,OAAO,IAAI,CAAC,mBAAmB,CAAC,GAA0B,CAAC,KAAK,KAAK,CAAC;oBAC1E,CAAC,CAAC,CAAC;oBAEH,IAAI,WAAW,EAAE,CAAC;wBACd,IAAI,CAAC,mBAAmB,GAAG,aAAa,CAAC;oBAC7C,CAAC;oBAED,OAAO,IAAI,CAAC,mBAAmB,CAAC;gBACpC,CAAC,CAAC;YAmBN,CAAC;YA5EG,qBAAqB,CAAC,SAA2B;gBAC7C,MAAM,EAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;gBAC9C,MAAM,EAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAC,GAAG,SAAS,CAAC;gBAEnF,OAAO,CACH,SAAS,CAAC,gBAAgB;oBAC1B,KAAK,KAAK,SAAS;oBACnB,MAAM,KAAK,UAAU;oBACrB,SAAS,KAAK,aAAa,CAC9B,CAAC;YACN,CAAC;YAiDD,MAAM;gBACF,MAAM,EAAC,IAAI,EAAE,aAAa,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,YAAY,EAAC,GAC5E,IAAI,CAAC,KAAK,CAAC;gBACf,MAAM,EAAC,eAAe,EAAC,GAAG,IAAI,CAAC,OAAO,CAAC;gBAEvC,OAAO,CACH,8BAAC,gBAAgB,IACb,kBAAkB,EAAE,kBAAkB,EACtC,aAAa,EAAE,IAAI,CAAC,cAAc,EAAE,EACpC,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,aAAa,EAC5B,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,IAAI,GACZ,CACL,CAAC;YACN,CAAC;SACJ;QAjFU,cAAW,GAAG,wBAAe;WAiFtC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport isEqual from 'lodash/isEqual';\n\nimport type {DashKitProps} from '../components/DashKit';\nimport type {ItemProps, RendererProps} from '../components/Item/types';\nimport {DashKitContext} from '../context';\nimport type {ConfigItem, ConfigLayout} from '../shared';\nimport type {PluginRef, PluginWidgetProps, ReactGridLayoutProps} from '../typings';\n\ntype PrepareItemProps = {\n gridLayout?: ReactGridLayoutProps;\n adjustWidgetLayout: PluginWidgetProps['adjustWidgetLayout'];\n layout: ConfigLayout[];\n id: string;\n item: ConfigItem;\n shouldItemUpdate?: boolean;\n width?: number;\n height?: number;\n transform?: string;\n isPlaceholder?: boolean;\n\n onItemRender?: DashKitProps['onItemRender'];\n onItemMountChange?: DashKitProps['onItemMountChange'];\n\n forwardedPluginRef?: (ref: PluginRef) => void;\n};\n\nexport function prepareItem(\n WrappedComponent: React.ComponentType<ItemProps>,\n): React.ComponentClass<PrepareItemProps> {\n return class PrepareItem extends React.Component<PrepareItemProps> {\n static contextType = DashKitContext;\n context!: React.ContextType<typeof DashKitContext>;\n\n _currentRenderProps: RendererProps = {} as RendererProps;\n\n shouldComponentUpdate(nextProps: PrepareItemProps) {\n const {width, height, transform} = this.props;\n const {width: widthNext, height: heightNext, transform: transformNext} = nextProps;\n\n return (\n nextProps.shouldItemUpdate ||\n width !== widthNext ||\n height !== heightNext ||\n transform !== transformNext\n );\n }\n\n _onStateAndParamsChange: PluginWidgetProps['onStateAndParamsChange'] = (\n stateAndParams,\n options,\n ) => {\n this.context.onItemStateAndParamsChange(this.props.id, stateAndParams, options);\n };\n\n getRenderProps = (): RendererProps => {\n const {id, width, height, item, adjustWidgetLayout, layout, gridLayout} = this.props;\n const {itemsState, itemsParams, registerManager, settings, context, editMode} =\n this.context;\n const {data, defaults, namespace} = item;\n\n const rendererProps: RendererProps = {\n data,\n editMode,\n params: itemsParams[id],\n state: itemsState[id],\n onStateAndParamsChange: this._onStateAndParamsChange,\n width,\n height,\n id,\n defaults,\n namespace,\n settings,\n context,\n layout,\n gridLayout: gridLayout || registerManager.gridLayout,\n adjustWidgetLayout,\n };\n\n const changedProp = Object.entries(rendererProps).find(([key, value]) => {\n // Checking gridLayoout deep as groups gridProperties method has tendancy to creat new objects\n if (key === 'gridLayout') {\n return !isEqual(this._currentRenderProps[key as keyof RendererProps], value);\n }\n\n return this._currentRenderProps[key as keyof RendererProps] !== value;\n });\n\n if (changedProp) {\n this._currentRenderProps = rendererProps;\n }\n\n return this._currentRenderProps;\n };\n\n render() {\n const {item, isPlaceholder, forwardedPluginRef, onItemMountChange, onItemRender} =\n this.props;\n const {registerManager} = this.context;\n\n return (\n <WrappedComponent\n forwardedPluginRef={forwardedPluginRef}\n rendererProps={this.getRenderProps()}\n registerManager={registerManager}\n isPlaceholder={isPlaceholder}\n onItemMountChange={onItemMountChange}\n onItemRender={onItemRender}\n item={item}\n />\n );\n }\n };\n}\n"]}
1
+ {"version":3,"file":"prepareItem.js","sourceRoot":"../../../src","sources":["hocs/prepareItem.tsx"],"names":[],"mappings":";;AA6BA,kCA2GC;;AAxID,0DAA0B;AAE1B,wEAAqC;AAIrC,iDAA0C;AAuB1C,SAAgB,WAAW,CACvB,gBAAgD;;IAEhD,YAAO,MAAM,WAAY,SAAQ,eAAK,CAAC,SAA2B;YAA3D;;gBAIH,wBAAmB,GAAkB,EAAmB,CAAC;gBAqDzD,4BAAuB,GAAgD,CACnE,cAAc,EACd,OAAO,EACT,EAAE;oBACA,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;gBACpF,CAAC,CAAC;gBAEF,mBAAc,GAAG,GAAkB,EAAE;oBACjC,MAAM,EAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,MAAM,EAAE,UAAU,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC;oBACrF,MAAM,EAAC,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAC,GACzE,IAAI,CAAC,OAAO,CAAC;oBACj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BAAiB,EACpC,YAAY,EAAE,YAAY,EAC1B,IAAI,EAAE,IAAI,GACZ,CACL,CAAC;YACN,CAAC;SAgDJ;QAtGU,cAAW,GAAG,wBAAe;WAsGtC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport isEqual from 'lodash/isEqual';\n\nimport type {DashKitProps} from '../components/DashKit';\nimport type {ItemProps, RendererProps} from '../components/Item/types';\nimport {DashKitContext} from '../context';\nimport type {DashKitCtxShape} from '../context';\nimport type {ConfigItem, ConfigLayout} from '../shared';\nimport type {PluginRef, PluginWidgetProps, ReactGridLayoutProps} from '../typings';\n\ntype PrepareItemProps = {\n gridLayout?: ReactGridLayoutProps;\n adjustWidgetLayout: PluginWidgetProps['adjustWidgetLayout'];\n layout: ConfigLayout[];\n id: string;\n item: ConfigItem;\n shouldItemUpdate?: boolean;\n width?: number;\n height?: number;\n transform?: string;\n isPlaceholder?: boolean;\n\n onItemRender?: DashKitProps['onItemRender'];\n onItemMountChange?: DashKitProps['onItemMountChange'];\n\n forwardedPluginRef?: (ref: PluginRef) => void;\n};\n\nexport function prepareItem(\n WrappedComponent: React.ComponentType<ItemProps>,\n): React.ComponentClass<PrepareItemProps> {\n return class PrepareItem extends React.Component<PrepareItemProps> {\n static contextType = DashKitContext;\n context!: React.ContextType<typeof DashKitContext>;\n\n _currentRenderProps: RendererProps = {} as RendererProps;\n\n shouldComponentUpdate(\n nextProps: PrepareItemProps,\n _nextState: never,\n nextContext: DashKitCtxShape,\n ) {\n const {width, height, transform} = this.props;\n const {width: widthNext, height: heightNext, transform: transformNext} = nextProps;\n\n // Layout changes (position/size) always trigger re-render\n if (width !== widthNext || height !== heightNext || transform !== transformNext) {\n return true;\n }\n\n // While dragging — skip content updates\n if (!nextProps.shouldItemUpdate) {\n return false;\n }\n\n const id = this.props.id;\n const ctx = this.context;\n\n // Re-render only if data relevant to this specific item changed\n return (\n this.props.item !== nextProps.item ||\n this.props.layout !== nextProps.layout ||\n ctx.itemsParams[id] !== nextContext.itemsParams[id] ||\n ctx.itemsState[id] !== nextContext.itemsState[id] ||\n ctx.editMode !== nextContext.editMode ||\n ctx.settings !== nextContext.settings ||\n ctx.context !== nextContext.context\n );\n }\n\n render() {\n const {item, isPlaceholder, forwardedPluginRef, onItemMountChange, onItemRender} =\n this.props;\n const {registerManager} = this.context;\n\n return (\n <WrappedComponent\n forwardedPluginRef={forwardedPluginRef}\n rendererProps={this.getRenderProps()}\n registerManager={registerManager}\n isPlaceholder={isPlaceholder}\n onItemMountChange={onItemMountChange}\n onItemRender={onItemRender}\n item={item}\n />\n );\n }\n\n _onStateAndParamsChange: PluginWidgetProps['onStateAndParamsChange'] = (\n stateAndParams,\n options,\n ) => {\n this.context.onItemStateAndParamsChange(this.props.id, stateAndParams, options);\n };\n\n getRenderProps = (): RendererProps => {\n const {id, width, height, item, adjustWidgetLayout, layout, gridLayout} = this.props;\n const {itemsState, itemsParams, registerManager, settings, context, editMode} =\n this.context;\n const {data, defaults, namespace} = item;\n\n const rendererProps: RendererProps = {\n data,\n editMode,\n params: itemsParams[id],\n state: itemsState[id],\n onStateAndParamsChange: this._onStateAndParamsChange,\n width,\n height,\n id,\n defaults,\n namespace,\n settings,\n context,\n layout,\n gridLayout: gridLayout || registerManager.gridLayout,\n adjustWidgetLayout,\n };\n\n const changedProp = Object.entries(rendererProps).find(([key, value]) => {\n // Checking gridLayoout deep as groups gridProperties method has tendancy to creat new objects\n if (key === 'gridLayout') {\n return !isEqual(this._currentRenderProps[key as keyof RendererProps], value);\n }\n\n return this._currentRenderProps[key as keyof RendererProps] !== value;\n });\n\n if (changedProp) {\n this._currentRenderProps = rendererProps;\n }\n\n return this._currentRenderProps;\n };\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":"10.0.0","type":"commonjs","sideEffects":["*.scss","*.css"]}
1
+ {"version":"10.1.0","type":"commonjs","sideEffects":["*.scss","*.css"]}
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  import type ReactGridLayout from 'react-grid-layout';
2
3
  import type { OverlayCustomControlItem } from "../components/OverlayControls/OverlayControls.js";
3
4
  import { MenuItems } from "../constants/index.js";
@@ -6,6 +7,12 @@ export type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] |
6
7
  export type ReactGridLayoutProps = Omit<ReactGridLayout.ReactGridLayoutProps, 'children' | 'compactType' | 'innerRef' | 'key' | 'layout' | 'onDragStart' | 'onDragStop' | 'onResizeStart' | 'onResizeStop' | 'draggableHandle' | 'isDroppable' | 'onDropDragOver' | 'onDrop' | 'draggableCancel'> & {
7
8
  compactType?: CompactType;
8
9
  noOverlay?: boolean;
10
+ /**
11
+ * When the grid is inside a scaled container, pass a ref to the scale factor.
12
+ * DragOverLayout will inject a lazy proxy so react-draggable reads the fresh
13
+ * value via valueOf() at drag time — no re-render required.
14
+ */
15
+ transformScaleRef?: React.MutableRefObject<number>;
9
16
  };
10
17
  export interface Settings {
11
18
  gridLayout?: ReactGridLayoutProps;
@@ -1 +1 @@
1
- {"version":3,"file":"common.js","sourceRoot":"../../../src","sources":["typings/common.ts"],"names":[],"mappings":"","sourcesContent":["import type ReactGridLayout from 'react-grid-layout';\n\nimport type {OverlayCustomControlItem} from '../components/OverlayControls/OverlayControls';\nimport {MenuItems} from '../constants';\nimport {AdditionalWidgetLayout} from '../shared';\n\nexport type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';\n\nexport type ReactGridLayoutProps = Omit<\n ReactGridLayout.ReactGridLayoutProps,\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 noOverlay?: boolean;\n};\n\nexport interface Settings {\n gridLayout?: ReactGridLayoutProps;\n theme?: string;\n isMobile?: boolean;\n // @deprecated as it's possibly mutable property use Dashkit overlayMenuItems property instead\n menu?: Array<MenuItem>;\n}\n\nexport type MenuItem = (typeof MenuItems)[keyof typeof MenuItems] | OverlayCustomControlItem;\n\nexport interface SettingsProps {\n autoupdateInterval: number;\n silentLoading: boolean;\n}\n\nexport interface ContextProps {\n [key: string]: any;\n}\n\nexport interface WidgetLayout extends AdditionalWidgetLayout {\n i: string;\n w: number;\n h: number;\n x: number;\n y: number;\n minW?: number;\n minH?: number;\n maxW?: number;\n maxH?: number;\n}\n"]}
1
+ {"version":3,"file":"common.js","sourceRoot":"../../../src","sources":["typings/common.ts"],"names":[],"mappings":"","sourcesContent":["import React from 'react';\n\nimport type ReactGridLayout from 'react-grid-layout';\n\nimport type {OverlayCustomControlItem} from '../components/OverlayControls/OverlayControls';\nimport {MenuItems} from '../constants';\nimport {AdditionalWidgetLayout} from '../shared';\n\nexport type CompactType = ReactGridLayout.ReactGridLayoutProps['compactType'] | 'horizontal-nowrap';\n\nexport type ReactGridLayoutProps = Omit<\n ReactGridLayout.ReactGridLayoutProps,\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 noOverlay?: boolean;\n /**\n * When the grid is inside a scaled container, pass a ref to the scale factor.\n * DragOverLayout will inject a lazy proxy so react-draggable reads the fresh\n * value via valueOf() at drag time — no re-render required.\n */\n transformScaleRef?: React.MutableRefObject<number>;\n};\n\nexport interface Settings {\n gridLayout?: ReactGridLayoutProps;\n theme?: string;\n isMobile?: boolean;\n // @deprecated as it's possibly mutable property use Dashkit overlayMenuItems property instead\n menu?: Array<MenuItem>;\n}\n\nexport type MenuItem = (typeof MenuItems)[keyof typeof MenuItems] | OverlayCustomControlItem;\n\nexport interface SettingsProps {\n autoupdateInterval: number;\n silentLoading: boolean;\n}\n\nexport interface ContextProps {\n [key: string]: any;\n}\n\nexport interface WidgetLayout extends AdditionalWidgetLayout {\n i: string;\n w: number;\n h: number;\n x: number;\n y: number;\n minW?: number;\n minH?: number;\n maxW?: number;\n maxH?: number;\n}\n"]}
@@ -37,6 +37,7 @@ class GridItem extends React.PureComponent {
37
37
  constructor() {
38
38
  super(...arguments);
39
39
  this._isAsyncItem = false;
40
+ this._isMounted = false;
40
41
  this.controller = null;
41
42
  this.state = {
42
43
  isFocused: false,
@@ -54,6 +55,9 @@ class GridItem extends React.PureComponent {
54
55
  });
55
56
  // requestAnimationFrame to make call after alert() or confirm()
56
57
  requestAnimationFrame(() => {
58
+ if (!this._isMounted) {
59
+ return;
60
+ }
57
61
  // Adding elment an changing focus
58
62
  document.body.appendChild(focusDummy);
59
63
  focusDummy.focus();
@@ -86,6 +90,15 @@ class GridItem extends React.PureComponent {
86
90
  });
87
91
  };
88
92
  }
93
+ componentDidMount() {
94
+ this._isMounted = true;
95
+ }
96
+ componentWillUnmount() {
97
+ this._isMounted = false;
98
+ if (this.controller) {
99
+ this.controller.abort();
100
+ }
101
+ }
89
102
  renderOverlay() {
90
103
  const { isPlaceholder } = this.props;
91
104
  const { editMode } = this.context;
@@ -1 +1 @@
1
- {"version":3,"file":"GridItem.js","sourceRoot":"../../../../src","sources":["components/GridItem/GridItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,kBAAkB,EAAC,iCAAwB;AACnD,OAAO,EAAC,cAAc,EAAC,+BAAsB;AAG7C,OAAO,EAAC,EAAE,EAAC,0BAAuB;AAElC,OAAO,IAAI,wBAAqB;AAChC,OAAO,eAAe,8CAA2C;AAEjE,wBAAyB;AAEzB,MAAM,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;AAElC,MAAM,mBAAmB;IAIrB;QAHA,gBAAW,GAAG,CAAC,CAAC;QAChB,cAAS,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;QAO7B,gBAAW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KAAK,CAAC,YAAY,EACrC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GACnC,CACA;YACL,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,EAAE;YAClC,gBAAgB,CACf,CACT,CAAC;IACN,CAAC;;AA9KM,oBAAW,GAAG,cAAc,AAAjB,CAAkB;AAiLxC,MAAM,oBAAoB,GAAG,KAAK,CAAC,UAAU,CACzC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACX,OAAO,oBAAC,QAAQ,oBAAK,KAAK,IAAE,YAAY,EAAE,GAAG,IAAI,CAAC;AACtD,CAAC,CACJ,CAAC;AAEF,oBAAoB,CAAC,WAAW,GAAG,sBAAsB,CAAC;AAE1D,eAAe,oBAAoB,CAAC","sourcesContent":["import React from 'react';\n\nimport {FOCUSED_CLASS_NAME} from '../../constants';\nimport {DashKitContext} from '../../context';\nimport type {ConfigItem, ConfigLayout} from '../../shared';\nimport type {PluginRef, PluginWidgetProps, ReactGridLayoutProps} from '../../typings';\nimport {cn} from '../../utils/cn';\nimport type {DashKitProps} from '../DashKit';\nimport Item from '../Item/Item';\nimport OverlayControls from '../OverlayControls/OverlayControls';\n\nimport './GridItem.scss';\n\nconst b = cn('dashkit-grid-item');\n\nclass WindowFocusObserver {\n subscribers = 0;\n isFocused = !document.hidden;\n\n constructor() {\n window.addEventListener('blur', this.blurHandler, true);\n window.addEventListener('focus', this.focusHandler, true);\n }\n\n blurHandler = (e: FocusEvent) => {\n if (e.target === window) {\n this.isFocused = false;\n }\n };\n\n focusHandler = (e: FocusEvent) => {\n if (e.target === window) {\n this.isFocused = true;\n }\n };\n\n // Method to get state after all blur\\focus events in document are triggered\n async getFocusedState(): Promise<boolean> {\n return new Promise((resolve) => {\n requestAnimationFrame(() => {\n resolve(this.isFocused);\n });\n });\n }\n}\n\nconst windowFocusObserver = new WindowFocusObserver();\n\ntype GridItemProps = {\n adjustWidgetLayout: PluginWidgetProps['adjustWidgetLayout'];\n gridLayout?: ReactGridLayoutProps;\n id: string;\n item: ConfigItem;\n isDragging?: boolean;\n isDraggedOut?: boolean;\n layout: ConfigLayout[];\n\n forwardedRef?: React.Ref<HTMLDivElement>;\n forwardedPluginRef?: (pluginRef: PluginRef) => void;\n isPlaceholder?: boolean;\n\n onItemMountChange?: DashKitProps['onItemMountChange'];\n onItemRender?: DashKitProps['onItemRender'];\n\n // from react-grid-layout:\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n noOverlay?: boolean;\n focusable?: boolean;\n withCustomHandle?: boolean;\n onMouseDown?: (e: React.MouseEvent<HTMLDivElement>) => void;\n onMouseUp?: (e: React.MouseEvent<HTMLDivElement>) => void;\n onTouchEnd?: (e: React.TouchEvent<HTMLDivElement>) => void;\n onTouchStart?: (e: React.TouchEvent<HTMLDivElement>) => void;\n onItemFocus?: DashKitProps['onItemFocus'];\n onItemBlur?: DashKitProps['onItemBlur'];\n};\n\ntype GridItemState = {\n isFocused: boolean;\n};\n\nclass GridItem extends React.PureComponent<GridItemProps, GridItemState> {\n static contextType = DashKitContext;\n context!: React.ContextType<typeof DashKitContext>;\n\n _isAsyncItem = false;\n controller: AbortController | null = null;\n\n state: GridItemState = {\n isFocused: false,\n };\n\n renderOverlay() {\n const {isPlaceholder} = this.props;\n const {editMode} = this.context;\n\n if (editMode && this.props.item.data._editActive) {\n // needed for correst pointer-events: none work in firefox\n return <div className={b('overlay-placeholder')} />;\n }\n\n if (!editMode || this.props.item.data._editActive || isPlaceholder) {\n return null;\n }\n\n const {item, focusable} = this.props;\n\n return (\n <React.Fragment>\n <div className={b('overlay')} />\n <OverlayControls\n configItem={item}\n onItemClick={focusable ? this.onOverlayItemClick : undefined}\n />\n </React.Fragment>\n );\n }\n\n onOverlayItemClick = () => {\n // Creating button element to trigger focus out\n const focusDummy = document.createElement('button');\n Object.assign(focusDummy.style, {\n width: '0',\n height: '0',\n opacity: '0',\n position: 'fixed',\n top: '0',\n left: '0',\n });\n\n // requestAnimationFrame to make call after alert() or confirm()\n requestAnimationFrame(() => {\n // Adding elment an changing focus\n document.body.appendChild(focusDummy);\n focusDummy.focus();\n document.body.removeChild(focusDummy);\n\n this.setState({isFocused: false});\n });\n };\n\n onFocusHandler = () => {\n this.setState({isFocused: true});\n\n if (this.props.onItemFocus) {\n // Sync focus and blur handlers\n windowFocusObserver.getFocusedState().then(() => {\n this.props.onItemFocus?.(this.props.item);\n });\n }\n\n if (this.controller) {\n this.controller.abort();\n }\n };\n\n onBlurHandler = () => {\n this.controller = new AbortController();\n\n windowFocusObserver.getFocusedState().then((isWindowFocused) => {\n if (!this.controller?.signal.aborted && isWindowFocused) {\n this.setState({isFocused: false});\n this.props.onItemBlur?.(this.props.item);\n }\n\n this.controller = null;\n });\n };\n\n render() {\n // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable\n // https://github.com/STRML/react-grid-layout/issues/721\n const {\n style,\n onMouseDown,\n onMouseUp,\n onTouchEnd,\n onTouchStart,\n children,\n className,\n isDragging,\n isDraggedOut,\n noOverlay,\n focusable,\n withCustomHandle,\n isPlaceholder = false,\n } = this.props;\n const {editMode} = this.context;\n const {isFocused} = this.state;\n\n const width =\n style?.width === undefined ? undefined : Number.parseInt(String(style.width), 10);\n const height =\n style?.height === undefined ? undefined : Number.parseInt(String(style.height), 10);\n const transform = style?.transform;\n const preparedClassName =\n (editMode\n ? className\n : className\n ?.replace('react-resizable', '')\n .replace('react-draggable', '')\n .replace(FOCUSED_CLASS_NAME, '')) +\n (isFocused ? ` ${FOCUSED_CLASS_NAME}` : '');\n const computedClassName = b(\n {\n 'is-dragging': isDragging,\n 'is-dragged-out': isDraggedOut,\n 'is-focused': isFocused,\n 'with-custom-handle': withCustomHandle,\n },\n preparedClassName,\n );\n\n const preparedChildren = editMode ? children : null;\n const reactGridLayoutProps = editMode\n ? {onMouseDown, onMouseUp, onTouchEnd, onTouchStart}\n : {};\n const reactFocusProps = focusable\n ? {\n onFocus: this.onFocusHandler,\n onBlur: this.onBlurHandler,\n tabIndex: -1,\n }\n : {};\n const {_editActive} = this.props.item.data;\n\n return (\n <div\n className={computedClassName}\n data-qa=\"dashkit-grid-item\"\n style={style}\n ref={this.props.forwardedRef}\n {...reactGridLayoutProps}\n {...reactFocusProps}\n >\n <div className={b('item', {editMode: editMode && !_editActive && !noOverlay})}>\n <Item\n id={this.props.id}\n item={this.props.item}\n shouldItemUpdate={!isDragging}\n width={width}\n height={height}\n transform={transform}\n isPlaceholder={isPlaceholder}\n adjustWidgetLayout={this.props.adjustWidgetLayout}\n layout={this.props.layout}\n forwardedPluginRef={this.props.forwardedPluginRef}\n onItemMountChange={this.props.onItemMountChange}\n onItemRender={this.props.onItemRender}\n gridLayout={this.props.gridLayout}\n />\n </div>\n {!noOverlay && this.renderOverlay()}\n {preparedChildren}\n </div>\n );\n }\n}\n\nconst GridItemForwarderRef = React.forwardRef<HTMLDivElement, Omit<GridItemProps, 'forwardedRef'>>(\n (props, ref) => {\n return <GridItem {...props} forwardedRef={ref} />;\n },\n);\n\nGridItemForwarderRef.displayName = 'forwardRef(GridItem)';\n\nexport default GridItemForwarderRef;\n"]}
1
+ {"version":3,"file":"GridItem.js","sourceRoot":"../../../../src","sources":["components/GridItem/GridItem.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,kBAAkB,EAAC,iCAAwB;AACnD,OAAO,EAAC,cAAc,EAAC,+BAAsB;AAG7C,OAAO,EAAC,EAAE,EAAC,0BAAuB;AAElC,OAAO,IAAI,wBAAqB;AAChC,OAAO,eAAe,8CAA2C;AAEjE,wBAAyB;AAEzB,MAAM,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,CAAC;AAElC,MAAM,mBAAmB;IAIrB;QAHA,gBAAW,GAAG,CAAC,CAAC;QAChB,cAAS,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;QAO7B,gBAAW,GAAG,CAAC,CAAa,EAAE,EAAE;YAC5B,IAAI,CAAC,CAAC,MAAM,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S,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,kBAAkB,EACjD,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,kBAAkB,EAAE,IAAI,CAAC,KAAK,CAAC,kBAAkB,EACjD,iBAAiB,EAAE,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAC/C,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,EACrC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GACnC,CACA;YACL,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,EAAE;YAClC,gBAAgB,CACf,CACT,CAAC;IACN,CAAC;;AA9LM,oBAAW,GAAG,cAAc,AAAjB,CAAkB;AAiMxC,MAAM,oBAAoB,GAAG,KAAK,CAAC,UAAU,CACzC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACX,OAAO,oBAAC,QAAQ,oBAAK,KAAK,IAAE,YAAY,EAAE,GAAG,IAAI,CAAC;AACtD,CAAC,CACJ,CAAC;AAEF,oBAAoB,CAAC,WAAW,GAAG,sBAAsB,CAAC;AAE1D,eAAe,oBAAoB,CAAC","sourcesContent":["import React from 'react';\n\nimport {FOCUSED_CLASS_NAME} from '../../constants';\nimport {DashKitContext} from '../../context';\nimport type {ConfigItem, ConfigLayout} from '../../shared';\nimport type {PluginRef, PluginWidgetProps, ReactGridLayoutProps} from '../../typings';\nimport {cn} from '../../utils/cn';\nimport type {DashKitProps} from '../DashKit';\nimport Item from '../Item/Item';\nimport OverlayControls from '../OverlayControls/OverlayControls';\n\nimport './GridItem.scss';\n\nconst b = cn('dashkit-grid-item');\n\nclass WindowFocusObserver {\n subscribers = 0;\n isFocused = !document.hidden;\n\n constructor() {\n window.addEventListener('blur', this.blurHandler, true);\n window.addEventListener('focus', this.focusHandler, true);\n }\n\n blurHandler = (e: FocusEvent) => {\n if (e.target === window) {\n this.isFocused = false;\n }\n };\n\n focusHandler = (e: FocusEvent) => {\n if (e.target === window) {\n this.isFocused = true;\n }\n };\n\n // Method to get state after all blur\\focus events in document are triggered\n async getFocusedState(): Promise<boolean> {\n return new Promise((resolve) => {\n requestAnimationFrame(() => {\n resolve(this.isFocused);\n });\n });\n }\n}\n\nconst windowFocusObserver = new WindowFocusObserver();\n\ntype GridItemProps = {\n adjustWidgetLayout: PluginWidgetProps['adjustWidgetLayout'];\n gridLayout?: ReactGridLayoutProps;\n id: string;\n item: ConfigItem;\n isDragging?: boolean;\n isDraggedOut?: boolean;\n layout: ConfigLayout[];\n\n forwardedRef?: React.Ref<HTMLDivElement>;\n forwardedPluginRef?: (pluginRef: PluginRef) => void;\n isPlaceholder?: boolean;\n\n onItemMountChange?: DashKitProps['onItemMountChange'];\n onItemRender?: DashKitProps['onItemRender'];\n\n // from react-grid-layout:\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n noOverlay?: boolean;\n focusable?: boolean;\n withCustomHandle?: boolean;\n onMouseDown?: (e: React.MouseEvent<HTMLDivElement>) => void;\n onMouseUp?: (e: React.MouseEvent<HTMLDivElement>) => void;\n onTouchEnd?: (e: React.TouchEvent<HTMLDivElement>) => void;\n onTouchStart?: (e: React.TouchEvent<HTMLDivElement>) => void;\n onItemFocus?: DashKitProps['onItemFocus'];\n onItemBlur?: DashKitProps['onItemBlur'];\n};\n\ntype GridItemState = {\n isFocused: boolean;\n};\n\nclass GridItem extends React.PureComponent<GridItemProps, GridItemState> {\n static contextType = DashKitContext;\n context!: React.ContextType<typeof DashKitContext>;\n\n _isAsyncItem = false;\n _isMounted = false;\n controller: AbortController | null = null;\n\n state: GridItemState = {\n isFocused: false,\n };\n\n componentDidMount() {\n this._isMounted = true;\n }\n\n componentWillUnmount() {\n this._isMounted = false;\n if (this.controller) {\n this.controller.abort();\n }\n }\n\n renderOverlay() {\n const {isPlaceholder} = this.props;\n const {editMode} = this.context;\n\n if (editMode && this.props.item.data._editActive) {\n // needed for correst pointer-events: none work in firefox\n return <div className={b('overlay-placeholder')} />;\n }\n\n if (!editMode || this.props.item.data._editActive || isPlaceholder) {\n return null;\n }\n\n const {item, focusable} = this.props;\n\n return (\n <React.Fragment>\n <div className={b('overlay')} />\n <OverlayControls\n configItem={item}\n onItemClick={focusable ? this.onOverlayItemClick : undefined}\n />\n </React.Fragment>\n );\n }\n\n onOverlayItemClick = () => {\n // Creating button element to trigger focus out\n const focusDummy = document.createElement('button');\n Object.assign(focusDummy.style, {\n width: '0',\n height: '0',\n opacity: '0',\n position: 'fixed',\n top: '0',\n left: '0',\n });\n\n // requestAnimationFrame to make call after alert() or confirm()\n requestAnimationFrame(() => {\n if (!this._isMounted) {\n return;\n }\n\n // Adding elment an changing focus\n document.body.appendChild(focusDummy);\n focusDummy.focus();\n document.body.removeChild(focusDummy);\n\n this.setState({isFocused: false});\n });\n };\n\n onFocusHandler = () => {\n this.setState({isFocused: true});\n\n if (this.props.onItemFocus) {\n // Sync focus and blur handlers\n windowFocusObserver.getFocusedState().then(() => {\n this.props.onItemFocus?.(this.props.item);\n });\n }\n\n if (this.controller) {\n this.controller.abort();\n }\n };\n\n onBlurHandler = () => {\n this.controller = new AbortController();\n\n windowFocusObserver.getFocusedState().then((isWindowFocused) => {\n if (!this.controller?.signal.aborted && isWindowFocused) {\n this.setState({isFocused: false});\n this.props.onItemBlur?.(this.props.item);\n }\n\n this.controller = null;\n });\n };\n\n render() {\n // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable\n // https://github.com/STRML/react-grid-layout/issues/721\n const {\n style,\n onMouseDown,\n onMouseUp,\n onTouchEnd,\n onTouchStart,\n children,\n className,\n isDragging,\n isDraggedOut,\n noOverlay,\n focusable,\n withCustomHandle,\n isPlaceholder = false,\n } = this.props;\n const {editMode} = this.context;\n const {isFocused} = this.state;\n\n const width =\n style?.width === undefined ? undefined : Number.parseInt(String(style.width), 10);\n const height =\n style?.height === undefined ? undefined : Number.parseInt(String(style.height), 10);\n const transform = style?.transform;\n const preparedClassName =\n (editMode\n ? className\n : className\n ?.replace('react-resizable', '')\n .replace('react-draggable', '')\n .replace(FOCUSED_CLASS_NAME, '')) +\n (isFocused ? ` ${FOCUSED_CLASS_NAME}` : '');\n const computedClassName = b(\n {\n 'is-dragging': isDragging,\n 'is-dragged-out': isDraggedOut,\n 'is-focused': isFocused,\n 'with-custom-handle': withCustomHandle,\n },\n preparedClassName,\n );\n\n const preparedChildren = editMode ? children : null;\n const reactGridLayoutProps = editMode\n ? {onMouseDown, onMouseUp, onTouchEnd, onTouchStart}\n : {};\n const reactFocusProps = focusable\n ? {\n onFocus: this.onFocusHandler,\n onBlur: this.onBlurHandler,\n tabIndex: -1,\n }\n : {};\n const {_editActive} = this.props.item.data;\n\n return (\n <div\n className={computedClassName}\n data-qa=\"dashkit-grid-item\"\n style={style}\n ref={this.props.forwardedRef}\n {...reactGridLayoutProps}\n {...reactFocusProps}\n >\n <div className={b('item', {editMode: editMode && !_editActive && !noOverlay})}>\n <Item\n id={this.props.id}\n item={this.props.item}\n shouldItemUpdate={!isDragging}\n width={width}\n height={height}\n transform={transform}\n isPlaceholder={isPlaceholder}\n adjustWidgetLayout={this.props.adjustWidgetLayout}\n layout={this.props.layout}\n forwardedPluginRef={this.props.forwardedPluginRef}\n onItemMountChange={this.props.onItemMountChange}\n onItemRender={this.props.onItemRender}\n gridLayout={this.props.gridLayout}\n />\n </div>\n {!noOverlay && this.renderOverlay()}\n {preparedChildren}\n </div>\n );\n }\n}\n\nconst GridItemForwarderRef = React.forwardRef<HTMLDivElement, Omit<GridItemProps, 'forwardedRef'>>(\n (props, ref) => {\n return <GridItem {...props} forwardedRef={ref} />;\n },\n);\n\nGridItemForwarderRef.displayName = 'forwardRef(GridItem)';\n\nexport default GridItemForwarderRef;\n"]}
@@ -12,6 +12,9 @@ export default class GridLayout extends React.PureComponent<GridLayoutProps, Gri
12
12
  private _memoGroupsProps;
13
13
  private _memoGroupsLayouts;
14
14
  private _memoCallbacksForGroups;
15
+ private _memoGroupsItems;
16
+ private _sharedDragRef;
17
+ private _sharedDragPositionRef;
15
18
  private _timeout?;
16
19
  private _lastReloadAt?;
17
20
  private _parendDragNode;
@@ -25,9 +28,11 @@ export default class GridLayout extends React.PureComponent<GridLayoutProps, Gri
25
28
  getActiveLayout(): ConfigLayout[];
26
29
  getMemoGroupLayout(group: string, layout: ConfigLayout[]): MemoGroupLayout;
27
30
  getMemoGroupCallbacks(group: string): GroupCallbacks;
28
- getMemoGroupProps: (group: string, renderLayout: ConfigLayout[], properties: Partial<ReactGridLayoutProps>) => {
31
+ getMemoGroupItems(group: string, nextItems: ConfigItem[]): ConfigItem[];
32
+ getMemoGroupProps: (group: string, renderLayout: ConfigLayout[], nextProperties: Partial<ReactGridLayoutProps>) => {
29
33
  layout: ConfigLayout[];
30
34
  callbacks: GroupCallbacks;
35
+ stableProperties: Partial<ReactGridLayoutProps>;
31
36
  };
32
37
  getLayoutAndPropsByGroup: (group: string) => LayoutAndPropsByGroup;
33
38
  getMemoForwardRefCallback: (refIndex: number) => (pluginRef: PluginRef) => void;