@gravity-ui/dashkit 8.24.3 → 8.26.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 +6 -0
- package/build/cjs/components/DashKit/DashKit.d.ts +2 -0
- package/build/cjs/components/GridItem/GridItem.js +14 -3
- package/build/cjs/components/GridLayout/GridLayout.js +2 -2
- package/build/cjs/constants/common.d.ts +1 -0
- package/build/cjs/constants/common.js +2 -1
- package/build/cjs/hocs/withContext.js +4 -0
- package/build/esm/components/DashKit/DashKit.d.ts +2 -0
- package/build/esm/components/GridItem/GridItem.js +14 -3
- package/build/esm/components/GridLayout/GridLayout.js +2 -2
- package/build/esm/constants/common.d.ts +1 -0
- package/build/esm/constants/common.js +1 -0
- package/build/esm/hocs/withContext.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,11 @@ interface DashKitProps {
|
|
|
57
57
|
overlayControls?: Record<string, OverlayControlItem[]> | null;
|
|
58
58
|
overlayMenuItems?: MenuItems[] | null;
|
|
59
59
|
noOverlay?: boolean;
|
|
60
|
+
|
|
60
61
|
focusable?: boolean;
|
|
62
|
+
onItemFocus: (item: ConfigItem) => void;
|
|
63
|
+
onItemBlur: (item: ConfigItem) => void;
|
|
64
|
+
|
|
61
65
|
draggableHandleClassName?: string;
|
|
62
66
|
getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
|
|
63
67
|
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
|
|
@@ -79,6 +83,8 @@ interface DashKitProps {
|
|
|
79
83
|
- **overlayMenuItems**: Custom dropdown menu items
|
|
80
84
|
- **noOverlay**: If `true`, overlay and controls are not displayed while editing.
|
|
81
85
|
- **focusable**: If `true`, grid items will be focusable.
|
|
86
|
+
- **onItemFocus**: Called when `focusable` is true and item is focused.
|
|
87
|
+
- **onItemBlur**: Called when `focusable` is true and item is focused out.
|
|
82
88
|
- **draggableHandleClassName** : СSS class name of the element that makes the widget draggable.
|
|
83
89
|
- **onDragStart**: ReactGridLayout called when item drag started
|
|
84
90
|
- **onDrag**: ReactGridLayout called while item drag
|
|
@@ -33,6 +33,8 @@ interface DashKitDefaultProps {
|
|
|
33
33
|
onItemRender?: (item: ConfigItem) => void;
|
|
34
34
|
getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
|
|
35
35
|
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
|
|
36
|
+
onItemFocus?: (item: ConfigItem) => void;
|
|
37
|
+
onItemBlur?: (item: ConfigItem) => void;
|
|
36
38
|
onDragStart?: ItemManipulationCallback;
|
|
37
39
|
onDrag?: ItemManipulationCallback;
|
|
38
40
|
onDragStop?: ItemManipulationCallback;
|
|
@@ -27,7 +27,7 @@ class WindowFocusObserver {
|
|
|
27
27
|
window.addEventListener('focus', this.focusHandler, true);
|
|
28
28
|
}
|
|
29
29
|
// Method to get state after all blur\focus events in document are triggered
|
|
30
|
-
async
|
|
30
|
+
async getFocusedState() {
|
|
31
31
|
return new Promise((resolve) => {
|
|
32
32
|
requestAnimationFrame(() => {
|
|
33
33
|
resolve(this.isFocused);
|
|
@@ -68,15 +68,24 @@ class GridItem extends react_1.default.PureComponent {
|
|
|
68
68
|
};
|
|
69
69
|
this.onFocusHandler = () => {
|
|
70
70
|
this.setState({ isFocused: true });
|
|
71
|
+
if (this.props.onItemFocus) {
|
|
72
|
+
// Sync focus and blur handlers
|
|
73
|
+
windowFocusObserver.getFocusedState().then(() => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
(_b = (_a = this.props).onItemFocus) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
71
78
|
if (this.controller) {
|
|
72
79
|
this.controller.abort();
|
|
73
80
|
}
|
|
74
81
|
};
|
|
75
82
|
this.onBlurHandler = () => {
|
|
76
83
|
this.controller = new AbortController();
|
|
77
|
-
windowFocusObserver.
|
|
78
|
-
|
|
84
|
+
windowFocusObserver.getFocusedState().then((isWindowFocused) => {
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
if (!((_a = this.controller) === null || _a === void 0 ? void 0 : _a.signal.aborted) && isWindowFocused) {
|
|
79
87
|
this.setState({ isFocused: false });
|
|
88
|
+
(_c = (_b = this.props).onItemBlur) === null || _c === void 0 ? void 0 : _c.call(_b, this.props.item);
|
|
80
89
|
}
|
|
81
90
|
this.controller = null;
|
|
82
91
|
});
|
|
@@ -155,6 +164,8 @@ GridItem.propTypes = {
|
|
|
155
164
|
onMouseUp: prop_types_1.default.func,
|
|
156
165
|
onTouchEnd: prop_types_1.default.func,
|
|
157
166
|
onTouchStart: prop_types_1.default.func,
|
|
167
|
+
onItemFocus: prop_types_1.default.func,
|
|
168
|
+
onItemBlur: prop_types_1.default.func,
|
|
158
169
|
};
|
|
159
170
|
GridItem.contextType = context_1.DashKitContext;
|
|
160
171
|
const GridItemForwarderRef = react_1.default.forwardRef((props, ref) => {
|
|
@@ -417,7 +417,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
417
417
|
return (react_1.default.createElement(GridItem_1.default, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout.data, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), gridLayout: gridLayout }));
|
|
418
418
|
}
|
|
419
419
|
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
|
|
420
|
-
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, } = this.context;
|
|
420
|
+
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, onItemFocus, onItemBlur, } = this.context;
|
|
421
421
|
const { currentDraggingElement, draggedOverGroup } = this.state;
|
|
422
422
|
const hasOwnGroupProperties = typeof groupGridProperties === 'function';
|
|
423
423
|
const properties = hasOwnGroupProperties
|
|
@@ -448,7 +448,7 @@ class GridLayout extends react_1.default.PureComponent {
|
|
|
448
448
|
const itemNoOverlay = hasOwnGroupProperties && 'noOverlay' in properties
|
|
449
449
|
? properties.noOverlay
|
|
450
450
|
: noOverlay;
|
|
451
|
-
return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: keyId, id: keyId, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: isDragging, isDraggedOut: isDraggedOut, noOverlay: itemNoOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender, gridLayout: properties }));
|
|
451
|
+
return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: keyId, id: keyId, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: isDragging, isDraggedOut: isDraggedOut, noOverlay: itemNoOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender, gridLayout: properties, onItemFocus: onItemFocus, onItemBlur: onItemBlur }));
|
|
452
452
|
}),
|
|
453
453
|
this.renderTemporaryPlaceholder(properties)));
|
|
454
454
|
}
|
|
@@ -2,6 +2,7 @@ export declare const COPIED_WIDGET_STORE_KEY = "dashCopiedItem";
|
|
|
2
2
|
export declare const DEFAULT_NAMESPACE = "default";
|
|
3
3
|
export declare const OVERLAY_CONTROLS_CLASS_NAME = "dashkit-overlay-controls";
|
|
4
4
|
export declare const OVERLAY_CLASS_NAME = "dashkit-grid-item__overlay";
|
|
5
|
+
export declare const ITEM_CLASS_NAME = "dashkit-grid-item";
|
|
5
6
|
export declare const OVERLAY_ICON_SIZE = 16;
|
|
6
7
|
export declare const TEMPORARY_ITEM_ID = "__dropping-elem__";
|
|
7
8
|
export declare const MenuItems: {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DROPPING_ELEMENT_CLASS_NAME = exports.FOCUSED_CLASS_NAME = exports.DRAGGABLE_CANCEL_CLASS_NAME = exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_ICON_SIZE = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
|
|
3
|
+
exports.DROPPING_ELEMENT_CLASS_NAME = exports.FOCUSED_CLASS_NAME = exports.DRAGGABLE_CANCEL_CLASS_NAME = exports.COMPACT_TYPE_HORIZONTAL_NOWRAP = exports.DEFAULT_GROUP = exports.DEFAULT_WIDGET_WIDTH = exports.DEFAULT_WIDGET_HEIGHT = exports.MenuItems = exports.TEMPORARY_ITEM_ID = exports.OVERLAY_ICON_SIZE = exports.ITEM_CLASS_NAME = exports.OVERLAY_CLASS_NAME = exports.OVERLAY_CONTROLS_CLASS_NAME = exports.DEFAULT_NAMESPACE = exports.COPIED_WIDGET_STORE_KEY = void 0;
|
|
4
4
|
exports.COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
|
|
5
5
|
exports.DEFAULT_NAMESPACE = 'default';
|
|
6
6
|
exports.OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
|
|
7
7
|
exports.OVERLAY_CLASS_NAME = 'dashkit-grid-item__overlay';
|
|
8
|
+
exports.ITEM_CLASS_NAME = 'dashkit-grid-item';
|
|
8
9
|
exports.OVERLAY_ICON_SIZE = 16;
|
|
9
10
|
exports.TEMPORARY_ITEM_ID = '__dropping-elem__';
|
|
10
11
|
exports.MenuItems = {
|
|
@@ -343,6 +343,8 @@ function useMemoStateContext(props) {
|
|
|
343
343
|
onDropDragOver,
|
|
344
344
|
outerDnDEnable,
|
|
345
345
|
dragOverPlugin,
|
|
346
|
+
onItemFocus: props.onItemFocus,
|
|
347
|
+
onItemBlur: props.onItemBlur,
|
|
346
348
|
/* default handlers bypass */
|
|
347
349
|
onDragStart: props.onDragStart,
|
|
348
350
|
onDrag: props.onDrag,
|
|
@@ -378,6 +380,8 @@ function useMemoStateContext(props) {
|
|
|
378
380
|
props.draggableHandleClassName,
|
|
379
381
|
outerDnDEnable,
|
|
380
382
|
dragOverPlugin,
|
|
383
|
+
props.onItemFocus,
|
|
384
|
+
props.onItemBlur,
|
|
381
385
|
props.onDragStart,
|
|
382
386
|
props.onDrag,
|
|
383
387
|
props.onDragStop,
|
|
@@ -33,6 +33,8 @@ interface DashKitDefaultProps {
|
|
|
33
33
|
onItemRender?: (item: ConfigItem) => void;
|
|
34
34
|
getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
|
|
35
35
|
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
|
|
36
|
+
onItemFocus?: (item: ConfigItem) => void;
|
|
37
|
+
onItemBlur?: (item: ConfigItem) => void;
|
|
36
38
|
onDragStart?: ItemManipulationCallback;
|
|
37
39
|
onDrag?: ItemManipulationCallback;
|
|
38
40
|
onDragStop?: ItemManipulationCallback;
|
|
@@ -25,7 +25,7 @@ class WindowFocusObserver {
|
|
|
25
25
|
window.addEventListener('focus', this.focusHandler, true);
|
|
26
26
|
}
|
|
27
27
|
// Method to get state after all blur\focus events in document are triggered
|
|
28
|
-
async
|
|
28
|
+
async getFocusedState() {
|
|
29
29
|
return new Promise((resolve) => {
|
|
30
30
|
requestAnimationFrame(() => {
|
|
31
31
|
resolve(this.isFocused);
|
|
@@ -66,15 +66,24 @@ class GridItem extends React.PureComponent {
|
|
|
66
66
|
};
|
|
67
67
|
this.onFocusHandler = () => {
|
|
68
68
|
this.setState({ isFocused: true });
|
|
69
|
+
if (this.props.onItemFocus) {
|
|
70
|
+
// Sync focus and blur handlers
|
|
71
|
+
windowFocusObserver.getFocusedState().then(() => {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
(_b = (_a = this.props).onItemFocus) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.item);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
69
76
|
if (this.controller) {
|
|
70
77
|
this.controller.abort();
|
|
71
78
|
}
|
|
72
79
|
};
|
|
73
80
|
this.onBlurHandler = () => {
|
|
74
81
|
this.controller = new AbortController();
|
|
75
|
-
windowFocusObserver.
|
|
76
|
-
|
|
82
|
+
windowFocusObserver.getFocusedState().then((isWindowFocused) => {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
if (!((_a = this.controller) === null || _a === void 0 ? void 0 : _a.signal.aborted) && isWindowFocused) {
|
|
77
85
|
this.setState({ isFocused: false });
|
|
86
|
+
(_c = (_b = this.props).onItemBlur) === null || _c === void 0 ? void 0 : _c.call(_b, this.props.item);
|
|
78
87
|
}
|
|
79
88
|
this.controller = null;
|
|
80
89
|
});
|
|
@@ -153,6 +162,8 @@ GridItem.propTypes = {
|
|
|
153
162
|
onMouseUp: PropTypes.func,
|
|
154
163
|
onTouchEnd: PropTypes.func,
|
|
155
164
|
onTouchStart: PropTypes.func,
|
|
165
|
+
onItemFocus: PropTypes.func,
|
|
166
|
+
onItemBlur: PropTypes.func,
|
|
156
167
|
};
|
|
157
168
|
GridItem.contextType = DashKitContext;
|
|
158
169
|
const GridItemForwarderRef = React.forwardRef((props, ref) => {
|
|
@@ -414,7 +414,7 @@ class GridLayout extends React.PureComponent {
|
|
|
414
414
|
return (React.createElement(GridItem, { key: id, id: id, item: { id, type, data: {} }, layout: temporaryLayout.data, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, isPlaceholder: true, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), gridLayout: gridLayout }));
|
|
415
415
|
}
|
|
416
416
|
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
|
|
417
|
-
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, } = this.context;
|
|
417
|
+
const { registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, onItemMountChange, onItemRender, onItemFocus, onItemBlur, } = this.context;
|
|
418
418
|
const { currentDraggingElement, draggedOverGroup } = this.state;
|
|
419
419
|
const hasOwnGroupProperties = typeof groupGridProperties === 'function';
|
|
420
420
|
const properties = hasOwnGroupProperties
|
|
@@ -445,7 +445,7 @@ class GridLayout extends React.PureComponent {
|
|
|
445
445
|
const itemNoOverlay = hasOwnGroupProperties && 'noOverlay' in properties
|
|
446
446
|
? properties.noOverlay
|
|
447
447
|
: noOverlay;
|
|
448
|
-
return (React.createElement(GridItem, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: keyId, id: keyId, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: isDragging, isDraggedOut: isDraggedOut, noOverlay: itemNoOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender, gridLayout: properties }));
|
|
448
|
+
return (React.createElement(GridItem, { forwardedPluginRef: this.getMemoForwardRefCallback(offset + i), key: keyId, id: keyId, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: isDragging, isDraggedOut: isDraggedOut, noOverlay: itemNoOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), onItemMountChange: onItemMountChange, onItemRender: onItemRender, gridLayout: properties, onItemFocus: onItemFocus, onItemBlur: onItemBlur }));
|
|
449
449
|
}),
|
|
450
450
|
this.renderTemporaryPlaceholder(properties)));
|
|
451
451
|
}
|
|
@@ -2,6 +2,7 @@ export declare const COPIED_WIDGET_STORE_KEY = "dashCopiedItem";
|
|
|
2
2
|
export declare const DEFAULT_NAMESPACE = "default";
|
|
3
3
|
export declare const OVERLAY_CONTROLS_CLASS_NAME = "dashkit-overlay-controls";
|
|
4
4
|
export declare const OVERLAY_CLASS_NAME = "dashkit-grid-item__overlay";
|
|
5
|
+
export declare const ITEM_CLASS_NAME = "dashkit-grid-item";
|
|
5
6
|
export declare const OVERLAY_ICON_SIZE = 16;
|
|
6
7
|
export declare const TEMPORARY_ITEM_ID = "__dropping-elem__";
|
|
7
8
|
export declare const MenuItems: {
|
|
@@ -2,6 +2,7 @@ export const COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
|
|
|
2
2
|
export const DEFAULT_NAMESPACE = 'default';
|
|
3
3
|
export const OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
|
|
4
4
|
export const OVERLAY_CLASS_NAME = 'dashkit-grid-item__overlay';
|
|
5
|
+
export const ITEM_CLASS_NAME = 'dashkit-grid-item';
|
|
5
6
|
export const OVERLAY_ICON_SIZE = 16;
|
|
6
7
|
export const TEMPORARY_ITEM_ID = '__dropping-elem__';
|
|
7
8
|
export const MenuItems = {
|
|
@@ -340,6 +340,8 @@ function useMemoStateContext(props) {
|
|
|
340
340
|
onDropDragOver,
|
|
341
341
|
outerDnDEnable,
|
|
342
342
|
dragOverPlugin,
|
|
343
|
+
onItemFocus: props.onItemFocus,
|
|
344
|
+
onItemBlur: props.onItemBlur,
|
|
343
345
|
/* default handlers bypass */
|
|
344
346
|
onDragStart: props.onDragStart,
|
|
345
347
|
onDrag: props.onDrag,
|
|
@@ -375,6 +377,8 @@ function useMemoStateContext(props) {
|
|
|
375
377
|
props.draggableHandleClassName,
|
|
376
378
|
outerDnDEnable,
|
|
377
379
|
dragOverPlugin,
|
|
380
|
+
props.onItemFocus,
|
|
381
|
+
props.onItemBlur,
|
|
378
382
|
props.onDragStart,
|
|
379
383
|
props.onDrag,
|
|
380
384
|
props.onDragStop,
|