@reltio/components 1.4.1732 → 1.4.1733

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.
@@ -1,5 +1,5 @@
1
1
  import React, { ElementType } from 'react';
2
- import { DragOverEvent } from 'react-grid-layout';
2
+ import { ReactGridLayoutProps } from 'react-grid-layout';
3
3
  import { ReltioGridLayoutItem } from '@reltio/mdm-sdk';
4
4
  import { ReactGridLayoutItem, ReltioGridLayoutOptions } from '../../types';
5
5
  type Props<ViewConfig = Record<string, unknown>> = {
@@ -8,10 +8,7 @@ type Props<ViewConfig = Record<string, unknown>> = {
8
8
  layoutOptions?: ReltioGridLayoutOptions;
9
9
  onLayoutChanged?: (layout: ReltioGridLayoutItem[]) => void;
10
10
  onDrop?: (layout: ReltioGridLayoutItem[], layoutItem: ReltioGridLayoutItem, e: Event) => void;
11
- onDropDragOver?: (e: DragOverEvent) => {
12
- w?: number;
13
- h?: number;
14
- } | false | undefined;
11
+ onDropDragOver?: ReactGridLayoutProps['onDropDragOver'];
15
12
  onRemove?: (id: string) => void;
16
13
  LayoutItem: ElementType;
17
14
  draggableHandle?: string;
@@ -22,7 +19,7 @@ type Props<ViewConfig = Record<string, unknown>> = {
22
19
  root?: string;
23
20
  item?: string;
24
21
  };
25
- onResize?: (layout: ReactGridLayoutItem[], oldLayoutItem: ReactGridLayoutItem, layoutItem: ReactGridLayoutItem, placeholder: ReactGridLayoutItem) => void;
22
+ onResize?: ReactGridLayoutProps['onResize'];
26
23
  };
27
24
  declare const _default: React.MemoExoticComponent<{
28
25
  ({ views, layout, layoutOptions, onLayoutChanged, draggableHandle, LayoutItem, onRemove, onDrop, droppingItem, isDroppable, onDropDragOver, isStatic, classes, onResize }: Props<Record<string, unknown>>): JSX.Element;
@@ -54,6 +54,7 @@ var ReltioGridLayout = function (_a) {
54
54
  var _b;
55
55
  var views = _a.views, layout = _a.layout, _c = _a.layoutOptions, layoutOptions = _c === void 0 ? DEFAULT_LAYOUT_OPTIONS : _c, _d = _a.onLayoutChanged, onLayoutChanged = _d === void 0 ? core_1.noop : _d, draggableHandle = _a.draggableHandle, LayoutItem = _a.LayoutItem, onRemove = _a.onRemove, onDrop = _a.onDrop, droppingItem = _a.droppingItem, isDroppable = _a.isDroppable, onDropDragOver = _a.onDropDragOver, isStatic = _a.isStatic, classes = _a.classes, _e = _a.onResize, onResize = _e === void 0 ? core_1.noop : _e;
56
56
  var ref = (0, react_1.useRef)();
57
+ var shouldCompareLayout = (0, react_1.useRef)(false);
57
58
  var heightsMap = (0, react_1.useRef)({});
58
59
  var styles = (0, styles_1.useStyles)();
59
60
  var _f = (0, react_1.useState)(null), resizingItemId = _f[0], setResizingItemId = _f[1];
@@ -61,7 +62,8 @@ var ReltioGridLayout = function (_a) {
61
62
  var _h = (0, react_1.useState)(0), width = _h[0], setWidth = _h[1];
62
63
  var cols = layoutOptions.cols, rowHeight = layoutOptions.rowHeight, margin = layoutOptions.margin;
63
64
  var processedLayout = (0, react_1.useMemo)(function () { return (0, helpers_1.reltioLayoutToReactGridLayout)(layout); }, [layout]);
64
- var onReltioLayoutChanged = (0, ramda_1.pipe)(helpers_1.reactGridLayoutToReltioLayout, (0, helpers_1.copyPropsFromPreviousLayout)(['autosizing'], layout), (0, ramda_1.ifElse)((0, ramda_1.always)(isStatic), (0, helpers_1.alignGroupedItemsHeights)(heightsMap.current), (0, helpers_1.calcLayoutItemsHeight)(heightsMap.current)), onLayoutChanged);
65
+ var convertReactLayoutToReltioLayout = (0, ramda_1.pipe)(helpers_1.reactGridLayoutToReltioLayout, (0, helpers_1.copyPropsFromPreviousLayout)(['autosizing'], layout), (0, ramda_1.ifElse)((0, ramda_1.always)(isStatic), (0, helpers_1.alignGroupedItemsHeights)(heightsMap.current), (0, helpers_1.calcLayoutItemsHeight)(heightsMap.current)));
66
+ var onReltioLayoutChanged = (0, ramda_1.pipe)(convertReactLayoutToReltioLayout, onLayoutChanged);
65
67
  var handleDrop = function (layout, layoutItem, e) {
66
68
  if (onDrop && layoutItem) {
67
69
  onDrop((0, helpers_1.reactGridLayoutToReltioLayout)(layout), (0, helpers_1.reactGridLayoutItemToReltioLayoutItem)(layoutItem), e);
@@ -74,10 +76,26 @@ var ReltioGridLayout = function (_a) {
74
76
  var newHeight = (0, helpers_1.calcHeight)(height, layoutOptions);
75
77
  if (newHeight !== heightsMap.current[layoutItemId]) {
76
78
  heightsMap.current[layoutItemId] = newHeight;
79
+ shouldCompareLayout.current = false;
77
80
  onReltioLayoutChanged(processedLayout);
78
81
  }
79
82
  }
80
83
  } })); };
84
+ (0, react_1.useEffect)(function () {
85
+ if (isStatic) {
86
+ if (shouldCompareLayout.current) {
87
+ var expectedLayout = convertReactLayoutToReltioLayout(processedLayout);
88
+ var isSameLayout = (0, ramda_1.equals)((0, helpers_1.reltioLayoutToReactGridLayout)(expectedLayout), processedLayout);
89
+ if (!isSameLayout) {
90
+ shouldCompareLayout.current = false;
91
+ onLayoutChanged(expectedLayout);
92
+ }
93
+ }
94
+ else {
95
+ shouldCompareLayout.current = true;
96
+ }
97
+ }
98
+ }, [processedLayout, isStatic]);
81
99
  return (react_1.default.createElement(react_1.default.Fragment, null,
82
100
  react_1.default.createElement(react_resize_detector_1.default, { refreshMode: "debounce", refreshRate: 50, handleWidth: true, onResize: function (width) { return setWidth(width); } }),
83
101
  !!width && (react_1.default.createElement(react_grid_layout_1.default, { innerRef: ref, layout: processedLayout, cols: cols, draggableHandle: draggableHandle, autoSize: true, rowHeight: rowHeight, width: width, margin: margin, onLayoutChange: isStatic ? undefined : onReltioLayoutChanged, isResizable: !isStatic && !isFullscreenEnabled, isDraggable: !isStatic && !isFullscreenEnabled, className: (0, classnames_1.default)(classes === null || classes === void 0 ? void 0 : classes.root, styles.gridLayout, (_b = {},
@@ -1,17 +1,7 @@
1
1
  import React from 'react';
2
2
  import { AttributeType, SearchFilter, SearchOperator } from '@reltio/mdm-sdk';
3
- export type ReactGridLayoutItem = {
4
- i: string;
5
- x: number;
6
- y: number;
7
- w: number;
8
- h: number;
9
- minW?: number;
10
- minH?: number;
11
- maxW?: number;
12
- maxH?: number;
13
- static?: boolean;
14
- };
3
+ import { Layout as LayoutItem } from 'react-grid-layout';
4
+ export type ReactGridLayoutItem = LayoutItem;
15
5
  export type ReltioGridLayoutOptions = {
16
6
  cols: number;
17
7
  rowHeight: number;
@@ -1,5 +1,5 @@
1
1
  import React, { ElementType } from 'react';
2
- import { DragOverEvent } from 'react-grid-layout';
2
+ import { ReactGridLayoutProps } from 'react-grid-layout';
3
3
  import { ReltioGridLayoutItem } from '@reltio/mdm-sdk';
4
4
  import { ReactGridLayoutItem, ReltioGridLayoutOptions } from '../../types';
5
5
  type Props<ViewConfig = Record<string, unknown>> = {
@@ -8,10 +8,7 @@ type Props<ViewConfig = Record<string, unknown>> = {
8
8
  layoutOptions?: ReltioGridLayoutOptions;
9
9
  onLayoutChanged?: (layout: ReltioGridLayoutItem[]) => void;
10
10
  onDrop?: (layout: ReltioGridLayoutItem[], layoutItem: ReltioGridLayoutItem, e: Event) => void;
11
- onDropDragOver?: (e: DragOverEvent) => {
12
- w?: number;
13
- h?: number;
14
- } | false | undefined;
11
+ onDropDragOver?: ReactGridLayoutProps['onDropDragOver'];
15
12
  onRemove?: (id: string) => void;
16
13
  LayoutItem: ElementType;
17
14
  draggableHandle?: string;
@@ -22,7 +19,7 @@ type Props<ViewConfig = Record<string, unknown>> = {
22
19
  root?: string;
23
20
  item?: string;
24
21
  };
25
- onResize?: (layout: ReactGridLayoutItem[], oldLayoutItem: ReactGridLayoutItem, layoutItem: ReactGridLayoutItem, placeholder: ReactGridLayoutItem) => void;
22
+ onResize?: ReactGridLayoutProps['onResize'];
26
23
  };
27
24
  declare const _default: React.MemoExoticComponent<{
28
25
  ({ views, layout, layoutOptions, onLayoutChanged, draggableHandle, LayoutItem, onRemove, onDrop, droppingItem, isDroppable, onDropDragOver, isStatic, classes, onResize }: Props<Record<string, unknown>>): JSX.Element;
@@ -9,10 +9,10 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import React, { useCallback, useMemo, useRef, useState, memo } from 'react';
12
+ import React, { useEffect, useCallback, useMemo, useRef, useState, memo } from 'react';
13
13
  import GridLayout from 'react-grid-layout';
14
14
  import ReactResizeDetector from 'react-resize-detector';
15
- import { pipe, ifElse, always } from 'ramda';
15
+ import { pipe, ifElse, always, equals } from 'ramda';
16
16
  import classnames from 'classnames';
17
17
  import { alignGroupedItemsHeights, calcLayoutItemsHeight, reltioLayoutToReactGridLayout, reactGridLayoutToReltioLayout, reactGridLayoutItemToReltioLayoutItem, copyPropsFromPreviousLayout, calcHeight, getReltioLayoutItemById } from './helpers';
18
18
  import { noop } from '../../core';
@@ -26,6 +26,7 @@ var ReltioGridLayout = function (_a) {
26
26
  var _b;
27
27
  var views = _a.views, layout = _a.layout, _c = _a.layoutOptions, layoutOptions = _c === void 0 ? DEFAULT_LAYOUT_OPTIONS : _c, _d = _a.onLayoutChanged, onLayoutChanged = _d === void 0 ? noop : _d, draggableHandle = _a.draggableHandle, LayoutItem = _a.LayoutItem, onRemove = _a.onRemove, onDrop = _a.onDrop, droppingItem = _a.droppingItem, isDroppable = _a.isDroppable, onDropDragOver = _a.onDropDragOver, isStatic = _a.isStatic, classes = _a.classes, _e = _a.onResize, onResize = _e === void 0 ? noop : _e;
28
28
  var ref = useRef();
29
+ var shouldCompareLayout = useRef(false);
29
30
  var heightsMap = useRef({});
30
31
  var styles = useStyles();
31
32
  var _f = useState(null), resizingItemId = _f[0], setResizingItemId = _f[1];
@@ -33,7 +34,8 @@ var ReltioGridLayout = function (_a) {
33
34
  var _h = useState(0), width = _h[0], setWidth = _h[1];
34
35
  var cols = layoutOptions.cols, rowHeight = layoutOptions.rowHeight, margin = layoutOptions.margin;
35
36
  var processedLayout = useMemo(function () { return reltioLayoutToReactGridLayout(layout); }, [layout]);
36
- var onReltioLayoutChanged = pipe(reactGridLayoutToReltioLayout, copyPropsFromPreviousLayout(['autosizing'], layout), ifElse(always(isStatic), alignGroupedItemsHeights(heightsMap.current), calcLayoutItemsHeight(heightsMap.current)), onLayoutChanged);
37
+ var convertReactLayoutToReltioLayout = pipe(reactGridLayoutToReltioLayout, copyPropsFromPreviousLayout(['autosizing'], layout), ifElse(always(isStatic), alignGroupedItemsHeights(heightsMap.current), calcLayoutItemsHeight(heightsMap.current)));
38
+ var onReltioLayoutChanged = pipe(convertReactLayoutToReltioLayout, onLayoutChanged);
37
39
  var handleDrop = function (layout, layoutItem, e) {
38
40
  if (onDrop && layoutItem) {
39
41
  onDrop(reactGridLayoutToReltioLayout(layout), reactGridLayoutItemToReltioLayoutItem(layoutItem), e);
@@ -46,10 +48,26 @@ var ReltioGridLayout = function (_a) {
46
48
  var newHeight = calcHeight(height, layoutOptions);
47
49
  if (newHeight !== heightsMap.current[layoutItemId]) {
48
50
  heightsMap.current[layoutItemId] = newHeight;
51
+ shouldCompareLayout.current = false;
49
52
  onReltioLayoutChanged(processedLayout);
50
53
  }
51
54
  }
52
55
  } })); };
56
+ useEffect(function () {
57
+ if (isStatic) {
58
+ if (shouldCompareLayout.current) {
59
+ var expectedLayout = convertReactLayoutToReltioLayout(processedLayout);
60
+ var isSameLayout = equals(reltioLayoutToReactGridLayout(expectedLayout), processedLayout);
61
+ if (!isSameLayout) {
62
+ shouldCompareLayout.current = false;
63
+ onLayoutChanged(expectedLayout);
64
+ }
65
+ }
66
+ else {
67
+ shouldCompareLayout.current = true;
68
+ }
69
+ }
70
+ }, [processedLayout, isStatic]);
53
71
  return (React.createElement(React.Fragment, null,
54
72
  React.createElement(ReactResizeDetector, { refreshMode: "debounce", refreshRate: 50, handleWidth: true, onResize: function (width) { return setWidth(width); } }),
55
73
  !!width && (React.createElement(GridLayout, { innerRef: ref, layout: processedLayout, cols: cols, draggableHandle: draggableHandle, autoSize: true, rowHeight: rowHeight, width: width, margin: margin, onLayoutChange: isStatic ? undefined : onReltioLayoutChanged, isResizable: !isStatic && !isFullscreenEnabled, isDraggable: !isStatic && !isFullscreenEnabled, className: classnames(classes === null || classes === void 0 ? void 0 : classes.root, styles.gridLayout, (_b = {},
@@ -1,17 +1,7 @@
1
1
  import React from 'react';
2
2
  import { AttributeType, SearchFilter, SearchOperator } from '@reltio/mdm-sdk';
3
- export type ReactGridLayoutItem = {
4
- i: string;
5
- x: number;
6
- y: number;
7
- w: number;
8
- h: number;
9
- minW?: number;
10
- minH?: number;
11
- maxW?: number;
12
- maxH?: number;
13
- static?: boolean;
14
- };
3
+ import { Layout as LayoutItem } from 'react-grid-layout';
4
+ export type ReactGridLayoutItem = LayoutItem;
15
5
  export type ReltioGridLayoutOptions = {
16
6
  cols: number;
17
7
  rowHeight: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1732",
3
+ "version": "1.4.1733",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",