@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
@@ -81,10 +81,17 @@ class DragOverLayout extends ReactGridLayout {
81
81
  this.parentOnDragStop(i, x, y, sintEv);
82
82
  }
83
83
  };
84
+ // Returns true when another group's item is being dragged over this grid.
85
+ // Reads from the ref directly — no re-render required to stay current.
86
+ this.isSharedDragTarget = () => {
87
+ var _a;
88
+ const drag = (_a = this.props.dragStateRef) === null || _a === void 0 ? void 0 : _a.current;
89
+ return Boolean((drag === null || drag === void 0 ? void 0 : drag.isDragging) && (drag === null || drag === void 0 ? void 0 : drag.sourceGroup) !== this.props.group);
90
+ };
84
91
  // Proxy mouse events -> drag methods for dnd between groups
85
92
  this.mouseEnterHandler = (e) => {
86
93
  var _a, _b;
87
- if (this.props.hasSharedDragItem) {
94
+ if (this.isSharedDragTarget()) {
88
95
  // @ts-expect-error - onDragEnter is a protected method in parent class
89
96
  this.onDragEnter(e);
90
97
  }
@@ -94,14 +101,14 @@ class DragOverLayout extends ReactGridLayout {
94
101
  };
95
102
  this.mouseLeaveHandler = (e) => {
96
103
  var _a, _b;
97
- if (this.props.hasSharedDragItem) {
104
+ if (this.isSharedDragTarget()) {
98
105
  // @ts-expect-error - onDragLeave is a protected method in parent class
99
106
  this.onDragLeave(e);
100
107
  (_b = (_a = this.props).onDragTargetRestore) === null || _b === void 0 ? void 0 : _b.call(_a);
101
108
  }
102
109
  };
103
110
  this.mouseMoveHandler = (e) => {
104
- if (this.props.hasSharedDragItem) {
111
+ if (this.isSharedDragTarget()) {
105
112
  if (!e.nativeEvent) {
106
113
  // Emulate nativeEvent for firefox
107
114
  const target = this.getInnerElement() || e.target;
@@ -117,7 +124,7 @@ class DragOverLayout extends ReactGridLayout {
117
124
  };
118
125
  this.mouseUpHandler = (e) => {
119
126
  var _a, _b;
120
- if (this.props.hasSharedDragItem) {
127
+ if (this.isSharedDragTarget()) {
121
128
  e.preventDefault();
122
129
  const { droppingItem } = this.props;
123
130
  const { layout } = this.state;
@@ -183,8 +190,9 @@ class DragOverLayout extends ReactGridLayout {
183
190
  return innerRef && isRefObject(innerRef) && innerRef.current ? innerRef.current : null;
184
191
  }
185
192
  calculateDroppingPosition(itemProps) {
193
+ var _a;
186
194
  const { containerWidth, cols, w, h, rowHeight, margin, transformScale, droppingPosition } = itemProps;
187
- const { sharedDragPosition } = this.props;
195
+ const sharedDragPosition = (_a = this.props.sharedDragPositionRef) === null || _a === void 0 ? void 0 : _a.current;
188
196
  let offsetX, offsetY;
189
197
  if (sharedDragPosition) {
190
198
  offsetX = sharedDragPosition.offsetX;
@@ -207,15 +215,20 @@ class DragOverLayout extends ReactGridLayout {
207
215
  if (!gridItem) {
208
216
  return gridItem;
209
217
  }
218
+ // Lazy proxy for transformScaleRef so react-draggable reads fresh scale without re-render.
219
+ const { transformScaleRef } = this.props;
220
+ const lazyScale = transformScaleRef
221
+ ? { valueOf: () => transformScaleRef.current }
222
+ : undefined;
210
223
  if (isDroppingItem) {
211
224
  // React.cloneElement is just cleaner then copy-paste whole processGridItem method
212
- return React.cloneElement(gridItem, {
225
+ return React.cloneElement(gridItem, Object.assign(Object.assign({}, (lazyScale !== undefined && { transformScale: lazyScale })), {
213
226
  // hiding preview if dragging shared item
214
- style: this.props.hasSharedDragItem
215
- ? Object.assign(Object.assign({}, gridItem.props.style), { opacity: 0 }) : gridItem.props.style,
216
- className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`,
217
- droppingPosition: this.calculateDroppingPosition(gridItem.props),
218
- });
227
+ style: this.isSharedDragTarget()
228
+ ? Object.assign(Object.assign({}, gridItem.props.style), { opacity: 0 }) : gridItem.props.style, className: `${OVERLAY_CLASS_NAME} ${DROPPING_ELEMENT_CLASS_NAME}`, droppingPosition: this.calculateDroppingPosition(gridItem.props) }));
229
+ }
230
+ if (lazyScale !== undefined) {
231
+ return React.cloneElement(gridItem, { transformScale: lazyScale });
219
232
  }
220
233
  return gridItem;
221
234
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ReactGridLayout.js","sourceRoot":"../../../../src","sources":["components/GridLayout/ReactGridLayout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,+DAA+D;AAC/D,OAAO,eAAe,EAAE,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAC,2BAA2B,EAAE,kBAAkB,EAAC,iCAAwB;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,eAAe;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;YA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AE;gBACjE,gBAAgB,EAAE,IAAI,CAAC,yBAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC;aACnE,CAAC,CAAC;QACP,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAsB,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 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,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,+DAA+D;AAC/D,OAAO,eAAe,EAAE,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAC,2BAA2B,EAAE,kBAAkB,EAAC,iCAAwB;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,cAA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OAAO,KAAK,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAC,cAAc,EAAE,SAAS,EAAC,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAsB,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,21 @@
1
+ export function shallowArrayEqual(a, b) {
2
+ if (a === b) {
3
+ return true;
4
+ }
5
+ if (a.length !== b.length) {
6
+ return false;
7
+ }
8
+ return a.every((item, i) => item === b[i]);
9
+ }
10
+ export function shallowObjectEqual(a, b) {
11
+ if (a === b) {
12
+ return true;
13
+ }
14
+ const keysA = Object.keys(a);
15
+ const keysB = Object.keys(b);
16
+ if (keysA.length !== keysB.length) {
17
+ return false;
18
+ }
19
+ return keysA.every((key) => a[key] === b[key]);
20
+ }
21
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"../../../../src","sources":["components/GridLayout/utils.tsx"],"names":[],"mappings":"AAAA,MAAM,UAAU,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,MAAM,UAAU,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"]}
@@ -44,13 +44,27 @@ export function prepareItem(WrappedComponent) {
44
44
  return this._currentRenderProps;
45
45
  };
46
46
  }
47
- shouldComponentUpdate(nextProps) {
47
+ shouldComponentUpdate(nextProps, _nextState, nextContext) {
48
48
  const { width, height, transform } = this.props;
49
49
  const { width: widthNext, height: heightNext, transform: transformNext } = nextProps;
50
- return (nextProps.shouldItemUpdate ||
51
- width !== widthNext ||
52
- height !== heightNext ||
53
- transform !== transformNext);
50
+ // Layout changes (position/size) always trigger re-render
51
+ if (width !== widthNext || height !== heightNext || transform !== transformNext) {
52
+ return true;
53
+ }
54
+ // While dragging — skip content updates
55
+ if (!nextProps.shouldItemUpdate) {
56
+ return false;
57
+ }
58
+ const id = this.props.id;
59
+ const ctx = this.context;
60
+ // Re-render only if data relevant to this specific item changed
61
+ return (this.props.item !== nextProps.item ||
62
+ this.props.layout !== nextProps.layout ||
63
+ ctx.itemsParams[id] !== nextContext.itemsParams[id] ||
64
+ ctx.itemsState[id] !== nextContext.itemsState[id] ||
65
+ ctx.editMode !== nextContext.editMode ||
66
+ ctx.settings !== nextContext.settings ||
67
+ ctx.context !== nextContext.context);
54
68
  }
55
69
  render() {
56
70
  const { item, isPlaceholder, forwardedPluginRef, onItemMountCh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,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,cAAe;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":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,OAAO,0BAAuB;AAIrC,OAAO,EAAC,cAAc,EAAC,4BAAmB;AAuB1C,MAAM,UAAU,WAAW,CACvB,gBAAgD;;IAEhD,YAAO,MAAM,WAAY,SAAQ,KAAK,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,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C,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,oBAAC,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;SAgDJ;QAtGU,cAAW,GAAG,cAAe;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":"module","sideEffects":["*.scss","*.css"]}
1
+ {"version":"10.1.0","type":"module","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {