@gravity-ui/dashkit 10.5.2 → 11.0.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.
- package/README.md +20 -1
- package/build/cjs/components/ActionPanel/ActionPanel.css +1 -1
- package/build/cjs/components/ActionPanel/ActionPanel.js +7 -9
- package/build/cjs/components/ActionPanel/ActionPanel.js.map +1 -1
- package/build/cjs/components/DashKit/DashKit.d.ts +1 -2
- package/build/cjs/components/DashKit/DashKit.js +50 -52
- package/build/cjs/components/DashKit/DashKit.js.map +1 -1
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js.map +1 -1
- package/build/cjs/components/DashKitView/DashKitView.js +1 -1
- package/build/cjs/components/DashKitView/DashKitView.js.map +1 -1
- package/build/cjs/components/GridItem/GridItem.js +79 -75
- package/build/cjs/components/GridItem/GridItem.js.map +1 -1
- package/build/cjs/components/GridLayout/GridLayout.d.ts +2 -2
- package/build/cjs/components/GridLayout/GridLayout.js +184 -187
- package/build/cjs/components/GridLayout/GridLayout.js.map +1 -1
- package/build/cjs/components/GridLayout/GroupLayout.js +1 -1
- package/build/cjs/components/GridLayout/GroupLayout.js.map +1 -1
- package/build/cjs/components/GridLayout/ReactGridLayout.js +303 -299
- package/build/cjs/components/GridLayout/ReactGridLayout.js.map +1 -1
- package/build/cjs/components/GridLayout/types.d.ts +1 -1
- package/build/cjs/components/GridLayout/types.js.map +1 -1
- package/build/cjs/components/Item/Item.js +8 -11
- package/build/cjs/components/Item/Item.js.map +1 -1
- package/build/cjs/components/MobileLayout/MobileLayout.d.ts +2 -2
- package/build/cjs/components/MobileLayout/MobileLayout.js +14 -14
- package/build/cjs/components/MobileLayout/MobileLayout.js.map +1 -1
- package/build/cjs/components/OverlayControls/OverlayControls.css +1 -1
- package/build/cjs/components/OverlayControls/OverlayControls.d.ts +7 -32
- package/build/cjs/components/OverlayControls/OverlayControls.js +164 -151
- package/build/cjs/components/OverlayControls/OverlayControls.js.map +1 -1
- package/build/cjs/hocs/prepareItem.js +65 -70
- package/build/cjs/hocs/prepareItem.js.map +1 -1
- package/build/cjs/hocs/withContext.js +27 -17
- package/build/cjs/hocs/withContext.js.map +1 -1
- package/build/cjs/hooks/useDeepEqualMemo.js +1 -1
- package/build/cjs/hooks/useDeepEqualMemo.js.map +1 -1
- package/build/cjs/i18n/index.d.ts +8 -0
- package/build/cjs/package.json +1 -1
- package/build/cjs/plugins/Text/Text.js +14 -17
- package/build/cjs/plugins/Text/Text.js.map +1 -1
- package/build/cjs/plugins/Title/Title.js +3 -4
- package/build/cjs/plugins/Title/Title.js.map +1 -1
- package/build/cjs/plugins/Title/index.d.ts +1 -1
- package/build/cjs/plugins/Title/index.js.map +1 -1
- package/build/cjs/shared/modules/helpers.js +34 -23
- package/build/cjs/shared/modules/helpers.js.map +1 -1
- package/build/cjs/shared/modules/state-and-params.js +30 -14
- package/build/cjs/shared/modules/state-and-params.js.map +1 -1
- package/build/cjs/shared/units/datalens/index.js +5 -2
- package/build/cjs/shared/units/datalens/index.js.map +1 -1
- package/build/cjs/utils/enrichLayoutWithDefaults.d.ts +1 -1
- package/build/cjs/utils/enrichLayoutWithDefaults.js +4 -1
- package/build/cjs/utils/enrichLayoutWithDefaults.js.map +1 -1
- package/build/cjs/utils/events.js +1 -1
- package/build/cjs/utils/events.js.map +1 -1
- package/build/cjs/utils/get-layout-patches.js +1 -1
- package/build/cjs/utils/get-layout-patches.js.map +1 -1
- package/build/cjs/utils/register-manager.js +25 -24
- package/build/cjs/utils/register-manager.js.map +1 -1
- package/build/cjs/utils/update-manager.js +103 -66
- package/build/cjs/utils/update-manager.js.map +1 -1
- package/build/docs/INDEX.md +24 -1
- package/build/docs/guides/migration-to-v11.md +122 -0
- package/build/esm/components/ActionPanel/ActionPanel.css +1 -1
- package/build/esm/components/ActionPanel/ActionPanel.js +7 -10
- package/build/esm/components/ActionPanel/ActionPanel.js.map +1 -1
- package/build/esm/components/DashKit/DashKit.d.ts +1 -2
- package/build/esm/components/DashKit/DashKit.js +50 -52
- package/build/esm/components/DashKit/DashKit.js.map +1 -1
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js.map +1 -1
- package/build/esm/components/DashKitView/DashKitView.js +1 -1
- package/build/esm/components/DashKitView/DashKitView.js.map +1 -1
- package/build/esm/components/GridItem/GridItem.js +79 -75
- package/build/esm/components/GridItem/GridItem.js.map +1 -1
- package/build/esm/components/GridLayout/GridLayout.d.ts +2 -2
- package/build/esm/components/GridLayout/GridLayout.js +185 -189
- package/build/esm/components/GridLayout/GridLayout.js.map +1 -1
- package/build/esm/components/GridLayout/GroupLayout.js +1 -1
- package/build/esm/components/GridLayout/GroupLayout.js.map +1 -1
- package/build/esm/components/GridLayout/ReactGridLayout.js +303 -300
- package/build/esm/components/GridLayout/ReactGridLayout.js.map +1 -1
- package/build/esm/components/GridLayout/types.d.ts +1 -1
- package/build/esm/components/GridLayout/types.js.map +1 -1
- package/build/esm/components/Item/Item.js +8 -11
- package/build/esm/components/Item/Item.js.map +1 -1
- package/build/esm/components/MobileLayout/MobileLayout.d.ts +2 -2
- package/build/esm/components/MobileLayout/MobileLayout.js +15 -16
- package/build/esm/components/MobileLayout/MobileLayout.js.map +1 -1
- package/build/esm/components/OverlayControls/OverlayControls.css +1 -1
- package/build/esm/components/OverlayControls/OverlayControls.d.ts +7 -32
- package/build/esm/components/OverlayControls/OverlayControls.js +165 -152
- package/build/esm/components/OverlayControls/OverlayControls.js.map +1 -1
- package/build/esm/hocs/prepareItem.js +65 -70
- package/build/esm/hocs/prepareItem.js.map +1 -1
- package/build/esm/hocs/withContext.js +27 -18
- package/build/esm/hocs/withContext.js.map +1 -1
- package/build/esm/hooks/useDeepEqualMemo.js +1 -1
- package/build/esm/hooks/useDeepEqualMemo.js.map +1 -1
- package/build/esm/i18n/index.d.ts +8 -0
- package/build/esm/package.json +1 -1
- package/build/esm/plugins/Text/Text.js +14 -17
- package/build/esm/plugins/Text/Text.js.map +1 -1
- package/build/esm/plugins/Title/Title.js +3 -4
- package/build/esm/plugins/Title/Title.js.map +1 -1
- package/build/esm/plugins/Title/index.d.ts +1 -1
- package/build/esm/plugins/Title/index.js.map +1 -1
- package/build/esm/shared/modules/helpers.js +34 -23
- package/build/esm/shared/modules/helpers.js.map +1 -1
- package/build/esm/shared/modules/state-and-params.js +30 -14
- package/build/esm/shared/modules/state-and-params.js.map +1 -1
- package/build/esm/shared/units/datalens/index.js +5 -2
- package/build/esm/shared/units/datalens/index.js.map +1 -1
- package/build/esm/utils/enrichLayoutWithDefaults.d.ts +1 -1
- package/build/esm/utils/enrichLayoutWithDefaults.js +4 -1
- package/build/esm/utils/enrichLayoutWithDefaults.js.map +1 -1
- package/build/esm/utils/events.js +1 -1
- package/build/esm/utils/events.js.map +1 -1
- package/build/esm/utils/get-layout-patches.js +1 -1
- package/build/esm/utils/get-layout-patches.js.map +1 -1
- package/build/esm/utils/register-manager.js +25 -24
- package/build/esm/utils/register-manager.js.map +1 -1
- package/build/esm/utils/update-manager.js +103 -66
- package/build/esm/utils/update-manager.js.map +1 -1
- package/package.json +25 -19
- package/build/cjs/components/DashKit/__tests__/controlled-layout.test.d.ts +0 -4
- package/build/cjs/components/DashKit/__tests__/controlled-layout.test.js +0 -260
- package/build/cjs/components/DashKit/__tests__/controlled-layout.test.js.map +0 -1
- package/build/cjs/components/DashKit/__tests__/events.test.d.ts +0 -1
- package/build/cjs/components/DashKit/__tests__/events.test.js +0 -227
- package/build/cjs/components/DashKit/__tests__/events.test.js.map +0 -1
- package/build/cjs/components/GridLayout/__tests__/passive-resize.test.d.ts +0 -2
- package/build/cjs/components/GridLayout/__tests__/passive-resize.test.js +0 -386
- package/build/cjs/components/GridLayout/__tests__/passive-resize.test.js.map +0 -1
- package/build/cjs/hooks/__tests__/useDnDItemProps.test.d.ts +0 -2
- package/build/cjs/hooks/__tests__/useDnDItemProps.test.js +0 -45
- package/build/cjs/hooks/__tests__/useDnDItemProps.test.js.map +0 -1
- package/build/cjs/shared/modules/__tests__/global-items.test.d.ts +0 -1
- package/build/cjs/shared/modules/__tests__/global-items.test.js +0 -372
- package/build/cjs/shared/modules/__tests__/global-items.test.js.map +0 -1
- package/build/cjs/shared/modules/__tests__/helpers.test.d.ts +0 -1
- package/build/cjs/shared/modules/__tests__/helpers.test.js +0 -505
- package/build/cjs/shared/modules/__tests__/helpers.test.js.map +0 -1
- package/build/cjs/shared/modules/__tests__/uniq-id.test.d.ts +0 -1
- package/build/cjs/shared/modules/__tests__/uniq-id.test.js +0 -78
- package/build/cjs/shared/modules/__tests__/uniq-id.test.js.map +0 -1
- package/build/cjs/shared/units/__tests__/state-and-params.test.d.ts +0 -241
- package/build/cjs/shared/units/__tests__/state-and-params.test.js +0 -724
- package/build/cjs/shared/units/__tests__/state-and-params.test.js.map +0 -1
- package/build/cjs/utils/__tests__/get-layout-patches.test.d.ts +0 -1
- package/build/cjs/utils/__tests__/get-layout-patches.test.js +0 -51
- package/build/cjs/utils/__tests__/get-layout-patches.test.js.map +0 -1
- package/build/cjs/utils/__tests__/update-manager.test.d.ts +0 -1
- package/build/cjs/utils/__tests__/update-manager.test.js +0 -824
- package/build/cjs/utils/__tests__/update-manager.test.js.map +0 -1
- package/build/esm/components/DashKit/__tests__/controlled-layout.test.d.ts +0 -4
- package/build/esm/components/DashKit/__tests__/controlled-layout.test.js +0 -257
- package/build/esm/components/DashKit/__tests__/controlled-layout.test.js.map +0 -1
- package/build/esm/components/DashKit/__tests__/events.test.d.ts +0 -1
- package/build/esm/components/DashKit/__tests__/events.test.js +0 -225
- package/build/esm/components/DashKit/__tests__/events.test.js.map +0 -1
- package/build/esm/components/GridLayout/__tests__/passive-resize.test.d.ts +0 -2
- package/build/esm/components/GridLayout/__tests__/passive-resize.test.js +0 -383
- package/build/esm/components/GridLayout/__tests__/passive-resize.test.js.map +0 -1
- package/build/esm/hooks/__tests__/useDnDItemProps.test.d.ts +0 -2
- package/build/esm/hooks/__tests__/useDnDItemProps.test.js +0 -42
- package/build/esm/hooks/__tests__/useDnDItemProps.test.js.map +0 -1
- package/build/esm/shared/modules/__tests__/global-items.test.d.ts +0 -1
- package/build/esm/shared/modules/__tests__/global-items.test.js +0 -370
- package/build/esm/shared/modules/__tests__/global-items.test.js.map +0 -1
- package/build/esm/shared/modules/__tests__/helpers.test.d.ts +0 -1
- package/build/esm/shared/modules/__tests__/helpers.test.js +0 -503
- package/build/esm/shared/modules/__tests__/helpers.test.js.map +0 -1
- package/build/esm/shared/modules/__tests__/uniq-id.test.d.ts +0 -1
- package/build/esm/shared/modules/__tests__/uniq-id.test.js +0 -75
- package/build/esm/shared/modules/__tests__/uniq-id.test.js.map +0 -1
- package/build/esm/shared/units/__tests__/state-and-params.test.d.ts +0 -241
- package/build/esm/shared/units/__tests__/state-and-params.test.js +0 -720
- package/build/esm/shared/units/__tests__/state-and-params.test.js.map +0 -1
- package/build/esm/utils/__tests__/get-layout-patches.test.d.ts +0 -1
- package/build/esm/utils/__tests__/get-layout-patches.test.js +0 -49
- package/build/esm/utils/__tests__/get-layout-patches.test.js.map +0 -1
- package/build/esm/utils/__tests__/update-manager.test.d.ts +0 -1
- package/build/esm/utils/__tests__/update-manager.test.js +0 -822
- package/build/esm/utils/__tests__/update-manager.test.js.map +0 -1
|
@@ -13,177 +13,24 @@ const hasPluginId = (value) => {
|
|
|
13
13
|
'id' in value.props &&
|
|
14
14
|
typeof value.props.id === 'string');
|
|
15
15
|
};
|
|
16
|
-
class GridLayout extends React.PureComponent {
|
|
16
|
+
export default class GridLayout extends React.PureComponent {
|
|
17
|
+
static contextType = DashKitContext;
|
|
18
|
+
pluginsRefs;
|
|
19
|
+
_memoForwardedPluginRef = [];
|
|
20
|
+
_memoGroupsProps = {};
|
|
21
|
+
_memoGroupsLayouts = {};
|
|
22
|
+
_memoCallbacksForGroups = {};
|
|
23
|
+
_memoGroupsItems = {};
|
|
24
|
+
_sharedDragRef = { current: { isDragging: false, sourceGroup: null } };
|
|
25
|
+
_sharedDragPositionRef = { current: null };
|
|
26
|
+
_groupResetRegistryRef = {
|
|
27
|
+
current: new Map(),
|
|
28
|
+
};
|
|
29
|
+
_timeout;
|
|
30
|
+
_lastReloadAt;
|
|
31
|
+
_parendDragNode = null;
|
|
17
32
|
constructor(props, context) {
|
|
18
33
|
super(props, context);
|
|
19
|
-
this._memoForwardedPluginRef = [];
|
|
20
|
-
this._memoGroupsProps = {};
|
|
21
|
-
this._memoGroupsLayouts = {};
|
|
22
|
-
this._memoCallbacksForGroups = {};
|
|
23
|
-
this._memoGroupsItems = {};
|
|
24
|
-
this._sharedDragRef = { current: { isDragging: false, sourceGroup: null } };
|
|
25
|
-
this._sharedDragPositionRef = { current: null };
|
|
26
|
-
this._groupResetRegistryRef = {
|
|
27
|
-
current: new Map(),
|
|
28
|
-
};
|
|
29
|
-
this._parendDragNode = null;
|
|
30
|
-
this.onVisibilityChange = () => {
|
|
31
|
-
this.setState({
|
|
32
|
-
isPageHidden: document.hidden,
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
this.adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout, }) => {
|
|
36
|
-
const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
|
|
37
|
-
if (needSetDefault) {
|
|
38
|
-
revertToOriginalLayout(widgetId);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (!adjustedWidgetLayout) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
|
|
45
|
-
memorizeOriginalLayout(widgetId, Object.assign({}, layout[correspondedLayoutItemIndex]), adjustedWidgetLayout);
|
|
46
|
-
};
|
|
47
|
-
this.getItemsMeta = () => {
|
|
48
|
-
const { getItemsMeta } = this.context;
|
|
49
|
-
return getItemsMeta(this.pluginsRefs);
|
|
50
|
-
};
|
|
51
|
-
this.getMemoGroupProps = (group, renderLayout, nextProperties) => {
|
|
52
|
-
// Return stable ref to prevent useMemo invalidation when properties are shallowly equal.
|
|
53
|
-
const prevProperties = this._memoGroupsProps[group];
|
|
54
|
-
const keysNext = Object.keys(nextProperties);
|
|
55
|
-
const stableProperties = prevProperties &&
|
|
56
|
-
Object.keys(prevProperties).length === keysNext.length &&
|
|
57
|
-
keysNext.every((k) => prevProperties[k] === nextProperties[k])
|
|
58
|
-
? prevProperties
|
|
59
|
-
: nextProperties;
|
|
60
|
-
// Needed for _onDropDragOver
|
|
61
|
-
this._memoGroupsProps[group] = stableProperties;
|
|
62
|
-
return {
|
|
63
|
-
layout: this.getMemoGroupLayout(group, renderLayout).layout,
|
|
64
|
-
callbacks: this.getMemoGroupCallbacks(group),
|
|
65
|
-
stableProperties,
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
this.getLayoutAndPropsByGroup = (group) => {
|
|
69
|
-
return {
|
|
70
|
-
properties: this._memoGroupsProps[group],
|
|
71
|
-
layout: this._memoGroupsLayouts[group].layout,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
this.getMemoForwardRefCallback = (refIndex) => {
|
|
75
|
-
if (!this._memoForwardedPluginRef[refIndex]) {
|
|
76
|
-
this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
|
|
77
|
-
this.pluginsRefs[refIndex] = pluginRef;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return this._memoForwardedPluginRef[refIndex];
|
|
81
|
-
};
|
|
82
|
-
this._onStop = (group, newLayout) => {
|
|
83
|
-
const { layoutChange, onDrop, temporaryLayout } = this.context;
|
|
84
|
-
const { draggedOverGroup, currentDraggingElement } = this.state;
|
|
85
|
-
if (currentDraggingElement &&
|
|
86
|
-
draggedOverGroup !== null &&
|
|
87
|
-
draggedOverGroup !== currentDraggingElement.group) {
|
|
88
|
-
// Skipping layout update when change event called for source grid
|
|
89
|
-
// and waiting _onDrop
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const groupedLayout = this.mergeGroupsLayout(group, newLayout);
|
|
93
|
-
this._clearSharedDragState();
|
|
94
|
-
this.setState({
|
|
95
|
-
isDragging: false,
|
|
96
|
-
currentDraggingElement: null,
|
|
97
|
-
draggedOverGroup: null,
|
|
98
|
-
});
|
|
99
|
-
if (temporaryLayout) {
|
|
100
|
-
const temporaryItem = groupedLayout.find(({ i }) => i === TEMPORARY_ITEM_ID);
|
|
101
|
-
if (onDrop && temporaryItem) {
|
|
102
|
-
onDrop(groupedLayout, temporaryItem);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
layoutChange(groupedLayout);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
this._onSharedDrop = (targetGroup, newLayout, tempItem) => {
|
|
110
|
-
const { currentDraggingElement } = this.state;
|
|
111
|
-
const { layoutChange } = this.context;
|
|
112
|
-
if (!currentDraggingElement) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const sourceLayoutItem = currentDraggingElement.layoutItem;
|
|
116
|
-
const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
|
|
117
|
-
if (item.i === sourceLayoutItem.i) {
|
|
118
|
-
const copy = Object.assign({}, tempItem);
|
|
119
|
-
delete copy.parent;
|
|
120
|
-
if (targetGroup !== DEFAULT_GROUP) {
|
|
121
|
-
copy.parent = targetGroup;
|
|
122
|
-
}
|
|
123
|
-
copy.i = sourceLayoutItem.i;
|
|
124
|
-
return copy;
|
|
125
|
-
}
|
|
126
|
-
return item;
|
|
127
|
-
});
|
|
128
|
-
this._clearSharedDragState();
|
|
129
|
-
this.setState({
|
|
130
|
-
isDragging: false,
|
|
131
|
-
currentDraggingElement: null,
|
|
132
|
-
draggedOverGroup: null,
|
|
133
|
-
});
|
|
134
|
-
// TODO temporaryLayout
|
|
135
|
-
layoutChange(groupedLayout);
|
|
136
|
-
};
|
|
137
|
-
this._onExternalDrop = (group, newLayout, item, e) => {
|
|
138
|
-
const { onDrop } = this.context;
|
|
139
|
-
if (group !== DEFAULT_GROUP) {
|
|
140
|
-
item.parent = group;
|
|
141
|
-
}
|
|
142
|
-
const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
|
|
143
|
-
this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
|
|
144
|
-
this.setState({ isDragging: false });
|
|
145
|
-
onDrop === null || onDrop === void 0 ? void 0 : onDrop(groupedLayout, item, e);
|
|
146
|
-
};
|
|
147
|
-
this._onDrop = (group, newLayout, item, e) => {
|
|
148
|
-
if (!item || !this.context.editMode) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
const { draggedOverGroup, currentDraggingElement } = this.state;
|
|
152
|
-
if (currentDraggingElement && draggedOverGroup === group) {
|
|
153
|
-
this._onSharedDrop(group, newLayout, item);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
this._onExternalDrop(group, newLayout, item, e);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
this._onDropDragOver = (group, e) => {
|
|
160
|
-
const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
|
|
161
|
-
const { currentDraggingElement } = this.state;
|
|
162
|
-
// TODO If temporary item is trying to change group
|
|
163
|
-
if (temporaryLayout && currentDraggingElement) {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
const { properties, layout } = this.getLayoutAndPropsByGroup(group);
|
|
170
|
-
if (currentDraggingElement) {
|
|
171
|
-
const { h, w, i } = currentDraggingElement.layoutItem;
|
|
172
|
-
const { type } = currentDraggingElement.item;
|
|
173
|
-
const sharedItem = {
|
|
174
|
-
h,
|
|
175
|
-
w,
|
|
176
|
-
i,
|
|
177
|
-
type,
|
|
178
|
-
parent: currentDraggingElement.group,
|
|
179
|
-
};
|
|
180
|
-
return onDropDragOver(e, group, properties, layout, sharedItem);
|
|
181
|
-
}
|
|
182
|
-
if (dragOverPlugin) {
|
|
183
|
-
return onDropDragOver(e, group, properties, layout);
|
|
184
|
-
}
|
|
185
|
-
return false;
|
|
186
|
-
};
|
|
187
34
|
this.pluginsRefs = [];
|
|
188
35
|
this.state = {
|
|
189
36
|
isDragging: false,
|
|
@@ -210,9 +57,30 @@ class GridLayout extends React.PureComponent {
|
|
|
210
57
|
this._memoGroupsItems = {};
|
|
211
58
|
this._memoForwardedPluginRef = [];
|
|
212
59
|
}
|
|
60
|
+
onVisibilityChange = () => {
|
|
61
|
+
this.setState({
|
|
62
|
+
isPageHidden: document.hidden,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
adjustWidgetLayout = ({ widgetId, needSetDefault, adjustedWidgetLayout, }) => {
|
|
66
|
+
const { layout, memorizeOriginalLayout, revertToOriginalLayout } = this.context;
|
|
67
|
+
if (needSetDefault) {
|
|
68
|
+
revertToOriginalLayout(widgetId);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (!adjustedWidgetLayout) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const correspondedLayoutItemIndex = layout.findIndex((layoutItem) => layoutItem.i === widgetId);
|
|
75
|
+
memorizeOriginalLayout(widgetId, { ...layout[correspondedLayoutItemIndex] }, adjustedWidgetLayout);
|
|
76
|
+
};
|
|
77
|
+
getItemsMeta = () => {
|
|
78
|
+
const { getItemsMeta } = this.context;
|
|
79
|
+
return getItemsMeta(this.pluginsRefs);
|
|
80
|
+
};
|
|
213
81
|
getActiveLayout() {
|
|
214
82
|
const { layout, temporaryLayout } = this.context;
|
|
215
|
-
return
|
|
83
|
+
return temporaryLayout?.data || layout;
|
|
216
84
|
}
|
|
217
85
|
getMemoGroupLayout(group, layout) {
|
|
218
86
|
// fastest possible way to match json
|
|
@@ -269,6 +137,37 @@ class GridLayout extends React.PureComponent {
|
|
|
269
137
|
this._memoGroupsItems[group] = nextItems;
|
|
270
138
|
return nextItems;
|
|
271
139
|
}
|
|
140
|
+
getMemoGroupProps = (group, renderLayout, nextProperties) => {
|
|
141
|
+
// Return stable ref to prevent useMemo invalidation when properties are shallowly equal.
|
|
142
|
+
const prevProperties = this._memoGroupsProps[group];
|
|
143
|
+
const keysNext = Object.keys(nextProperties);
|
|
144
|
+
const stableProperties = prevProperties &&
|
|
145
|
+
Object.keys(prevProperties).length === keysNext.length &&
|
|
146
|
+
keysNext.every((k) => prevProperties[k] === nextProperties[k])
|
|
147
|
+
? prevProperties
|
|
148
|
+
: nextProperties;
|
|
149
|
+
// Needed for _onDropDragOver
|
|
150
|
+
this._memoGroupsProps[group] = stableProperties;
|
|
151
|
+
return {
|
|
152
|
+
layout: this.getMemoGroupLayout(group, renderLayout).layout,
|
|
153
|
+
callbacks: this.getMemoGroupCallbacks(group),
|
|
154
|
+
stableProperties,
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
getLayoutAndPropsByGroup = (group) => {
|
|
158
|
+
return {
|
|
159
|
+
properties: this._memoGroupsProps[group],
|
|
160
|
+
layout: this._memoGroupsLayouts[group].layout,
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
getMemoForwardRefCallback = (refIndex) => {
|
|
164
|
+
if (!this._memoForwardedPluginRef[refIndex]) {
|
|
165
|
+
this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
|
|
166
|
+
this.pluginsRefs[refIndex] = pluginRef;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return this._memoForwardedPluginRef[refIndex];
|
|
170
|
+
};
|
|
272
171
|
mergeGroupsLayout(group, newLayout, temporaryItem) {
|
|
273
172
|
const renderLayout = this.getActiveLayout();
|
|
274
173
|
const itemsByGroup = renderLayout.reduce((memo, item) => {
|
|
@@ -276,9 +175,8 @@ class GridLayout extends React.PureComponent {
|
|
|
276
175
|
return memo;
|
|
277
176
|
}, temporaryItem ? { [temporaryItem.i]: temporaryItem } : {});
|
|
278
177
|
const newItemsLayoutById = newLayout.reduce((memo, item) => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
memo[item.i] = Object.assign({}, item);
|
|
178
|
+
const parent = itemsByGroup[item.i]?.parent;
|
|
179
|
+
memo[item.i] = { ...item };
|
|
282
180
|
if (parent) {
|
|
283
181
|
memo[item.i].parent = parent;
|
|
284
182
|
}
|
|
@@ -418,8 +316,7 @@ class GridLayout extends React.PureComponent {
|
|
|
418
316
|
this.setState({ isDraggedOut: false });
|
|
419
317
|
}
|
|
420
318
|
_onDragStart(group, _newLayout, layoutItem, _newItem, _placeholder, e, element) {
|
|
421
|
-
|
|
422
|
-
(_a = this.context.onDragStart) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
|
|
319
|
+
this.context.onDragStart?.call(this, this.prepareDefaultArguments(group, _newLayout, layoutItem, _newItem, _placeholder, e, element));
|
|
423
320
|
if (this.context.dragOverPlugin) {
|
|
424
321
|
this.setState({ isDragging: true });
|
|
425
322
|
}
|
|
@@ -441,33 +338,28 @@ class GridLayout extends React.PureComponent {
|
|
|
441
338
|
}
|
|
442
339
|
}
|
|
443
340
|
_onDrag(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
444
|
-
var _a;
|
|
445
341
|
if (!this.context.dragOverPlugin) {
|
|
446
342
|
this._updateDragCoordinates(e);
|
|
447
343
|
}
|
|
448
|
-
|
|
344
|
+
this.context.onDrag?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
449
345
|
}
|
|
450
346
|
_onDragStop(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
451
|
-
var _a;
|
|
452
347
|
this._resetDragWatcher();
|
|
453
348
|
this._onStop(group, layout);
|
|
454
|
-
|
|
349
|
+
this.context.onDragStop?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
455
350
|
}
|
|
456
351
|
_onResizeStart(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
457
|
-
var _a;
|
|
458
352
|
this.setState({
|
|
459
353
|
isDragging: true,
|
|
460
354
|
});
|
|
461
|
-
|
|
355
|
+
this.context.onResizeStart?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
462
356
|
}
|
|
463
357
|
_onResize(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
464
|
-
|
|
465
|
-
(_a = this.context.onResize) === null || _a === void 0 ? void 0 : _a.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
358
|
+
this.context.onResize?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
466
359
|
}
|
|
467
360
|
_onResizeStop(group, layout, oldItem, newItem, placeholder, e, element) {
|
|
468
|
-
var _a;
|
|
469
361
|
this._onStop(group, layout);
|
|
470
|
-
|
|
362
|
+
this.context.onResizeStop?.call(this, this.prepareDefaultArguments(group, layout, oldItem, newItem, placeholder, e, element));
|
|
471
363
|
}
|
|
472
364
|
_onTargetRestore() {
|
|
473
365
|
if (this.context.temporaryLayout) {
|
|
@@ -480,6 +372,111 @@ class GridLayout extends React.PureComponent {
|
|
|
480
372
|
});
|
|
481
373
|
}
|
|
482
374
|
}
|
|
375
|
+
_onStop = (group, newLayout) => {
|
|
376
|
+
const { layoutChange, onDrop, temporaryLayout } = this.context;
|
|
377
|
+
const { draggedOverGroup, currentDraggingElement } = this.state;
|
|
378
|
+
if (currentDraggingElement &&
|
|
379
|
+
draggedOverGroup !== null &&
|
|
380
|
+
draggedOverGroup !== currentDraggingElement.group) {
|
|
381
|
+
// Skipping layout update when change event called for source grid
|
|
382
|
+
// and waiting _onDrop
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
const groupedLayout = this.mergeGroupsLayout(group, newLayout);
|
|
386
|
+
this._clearSharedDragState();
|
|
387
|
+
this.setState({
|
|
388
|
+
isDragging: false,
|
|
389
|
+
currentDraggingElement: null,
|
|
390
|
+
draggedOverGroup: null,
|
|
391
|
+
});
|
|
392
|
+
if (temporaryLayout) {
|
|
393
|
+
const temporaryItem = groupedLayout.find(({ i }) => i === TEMPORARY_ITEM_ID);
|
|
394
|
+
if (onDrop && temporaryItem) {
|
|
395
|
+
onDrop(groupedLayout, temporaryItem);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
layoutChange(groupedLayout);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
_onSharedDrop = (targetGroup, newLayout, tempItem) => {
|
|
403
|
+
const { currentDraggingElement } = this.state;
|
|
404
|
+
const { layoutChange } = this.context;
|
|
405
|
+
if (!currentDraggingElement) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const sourceLayoutItem = currentDraggingElement.layoutItem;
|
|
409
|
+
const groupedLayout = this.mergeGroupsLayout(targetGroup, newLayout, tempItem).map((item) => {
|
|
410
|
+
if (item.i === sourceLayoutItem.i) {
|
|
411
|
+
const copy = { ...tempItem };
|
|
412
|
+
delete copy.parent;
|
|
413
|
+
if (targetGroup !== DEFAULT_GROUP) {
|
|
414
|
+
copy.parent = targetGroup;
|
|
415
|
+
}
|
|
416
|
+
copy.i = sourceLayoutItem.i;
|
|
417
|
+
return copy;
|
|
418
|
+
}
|
|
419
|
+
return item;
|
|
420
|
+
});
|
|
421
|
+
this._clearSharedDragState();
|
|
422
|
+
this.setState({
|
|
423
|
+
isDragging: false,
|
|
424
|
+
currentDraggingElement: null,
|
|
425
|
+
draggedOverGroup: null,
|
|
426
|
+
});
|
|
427
|
+
// TODO temporaryLayout
|
|
428
|
+
layoutChange(groupedLayout);
|
|
429
|
+
};
|
|
430
|
+
_onExternalDrop = (group, newLayout, item, e) => {
|
|
431
|
+
const { onDrop } = this.context;
|
|
432
|
+
if (group !== DEFAULT_GROUP) {
|
|
433
|
+
item.parent = group;
|
|
434
|
+
}
|
|
435
|
+
const groupedLayout = this.mergeGroupsLayout(group, newLayout, item);
|
|
436
|
+
this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
|
|
437
|
+
this.setState({ isDragging: false });
|
|
438
|
+
onDrop?.(groupedLayout, item, e);
|
|
439
|
+
};
|
|
440
|
+
_onDrop = (group, newLayout, item, e) => {
|
|
441
|
+
if (!item || !this.context.editMode) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
const { draggedOverGroup, currentDraggingElement } = this.state;
|
|
445
|
+
if (currentDraggingElement && draggedOverGroup === group) {
|
|
446
|
+
this._onSharedDrop(group, newLayout, item);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
this._onExternalDrop(group, newLayout, item, e);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
_onDropDragOver = (group, e) => {
|
|
453
|
+
const { editMode, dragOverPlugin, onDropDragOver, temporaryLayout } = this.context;
|
|
454
|
+
const { currentDraggingElement } = this.state;
|
|
455
|
+
// TODO If temporary item is trying to change group
|
|
456
|
+
if (temporaryLayout && currentDraggingElement) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
if (!editMode || (!dragOverPlugin && !currentDraggingElement)) {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
const { properties, layout } = this.getLayoutAndPropsByGroup(group);
|
|
463
|
+
if (currentDraggingElement) {
|
|
464
|
+
const { h, w, i } = currentDraggingElement.layoutItem;
|
|
465
|
+
const { type } = currentDraggingElement.item;
|
|
466
|
+
const sharedItem = {
|
|
467
|
+
h,
|
|
468
|
+
w,
|
|
469
|
+
i,
|
|
470
|
+
type,
|
|
471
|
+
parent: currentDraggingElement.group,
|
|
472
|
+
};
|
|
473
|
+
return onDropDragOver(e, group, properties, layout, sharedItem);
|
|
474
|
+
}
|
|
475
|
+
if (dragOverPlugin) {
|
|
476
|
+
return onDropDragOver(e, group, properties, layout);
|
|
477
|
+
}
|
|
478
|
+
return false;
|
|
479
|
+
};
|
|
483
480
|
_clearSharedDragState() {
|
|
484
481
|
this._sharedDragRef.current = { isDragging: false, sourceGroup: null };
|
|
485
482
|
this._sharedDragPositionRef.current = null;
|
|
@@ -501,7 +498,7 @@ class GridLayout extends React.PureComponent {
|
|
|
501
498
|
const { currentDraggingElement, draggedOverGroup, isDragging, isDraggedOut } = this.state;
|
|
502
499
|
const hasOwnGroupProperties = typeof groupGridProperties === 'function';
|
|
503
500
|
const properties = hasOwnGroupProperties
|
|
504
|
-
? groupGridProperties(
|
|
501
|
+
? groupGridProperties({ ...registerManager.gridLayout })
|
|
505
502
|
: registerManager.gridLayout;
|
|
506
503
|
const { callbacks, layout, stableProperties } = this.getMemoGroupProps(group, renderLayout, properties);
|
|
507
504
|
const compactType = stableProperties.compactType === COMPACT_TYPE_HORIZONTAL_NOWRAP
|
|
@@ -515,12 +512,13 @@ class GridLayout extends React.PureComponent {
|
|
|
515
512
|
? currentDraggingElement.item.id
|
|
516
513
|
: null;
|
|
517
514
|
// Non-source groups get stable false/null — memo skips re-render on drag move.
|
|
518
|
-
const isSourceGroup = Boolean(
|
|
515
|
+
const isSourceGroup = Boolean(currentDraggingElement?.group === group);
|
|
519
516
|
const groupIsAnyDragging = isDragging && isSourceGroup;
|
|
520
517
|
const groupCurrentDraggingItemId = isSourceGroup ? currentDraggingItemId : null;
|
|
521
518
|
const groupIsAnyDraggedOut = isSourceGroup ? isDraggedOut : false;
|
|
522
519
|
return (React.createElement(GroupLayout, { key: `group_${group}`, group: group, renderItems: renderItems, offset: offset, properties: stableProperties, compactType: compactType, callbacks: callbacks, layout: layout, temporaryPlaceholder: this.renderTemporaryPlaceholder(stableProperties), dragStateRef: this._sharedDragRef, sharedDragPositionRef: this._sharedDragPositionRef, groupResetRegistryRef: this._groupResetRegistryRef, isDragCaptured: isDragCaptured, isAnyDragging: groupIsAnyDragging, currentDraggingItemId: groupCurrentDraggingItemId, isAnyDraggedOut: groupIsAnyDraggedOut, adjustWidgetLayout: this.adjustWidgetLayout, getMemoForwardRefCallback: this.getMemoForwardRefCallback }));
|
|
523
520
|
}
|
|
521
|
+
// An explicit type: the inferred one spells out ReactNode of the @types/react the package is built with
|
|
524
522
|
render() {
|
|
525
523
|
const { config, groups, editMode, context } = this.context;
|
|
526
524
|
this.pluginsRefs.length = this.context.configItems.length;
|
|
@@ -589,6 +587,4 @@ class GridLayout extends React.PureComponent {
|
|
|
589
587
|
}
|
|
590
588
|
}
|
|
591
589
|
}
|
|
592
|
-
GridLayout.contextType = DashKitContext;
|
|
593
|
-
export default GridLayout;
|
|
594
590
|
//# sourceMappingURL=GridLayout.js.map
|