@gravity-ui/dashkit 8.0.2-beta.1 → 8.0.2-beta.3

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 CHANGED
@@ -49,6 +49,7 @@ interface DashKitProps {
49
49
  - **context**: Object that will be propped up on all widgets.
50
50
  - **overlayControls**: Object that overrides widget controls at the time of editing. If not transmitted, basic controls will be displayed.
51
51
  - **noOverlay**: If `true`, overlay and controls are not displayed while editing.
52
+ - **focusable**: If `true`, grid items will be focusable.
52
53
  - **draggableHandleClassName** : СSS class name of the element that makes the widget draggable.
53
54
 
54
55
  ## Usage
@@ -21,6 +21,7 @@ interface DashKitDefaultProps {
21
21
  settings: SettingsProps;
22
22
  context: ContextProps;
23
23
  noOverlay: boolean;
24
+ focusable?: boolean;
24
25
  }
25
26
  export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
26
27
  }
@@ -68,4 +68,5 @@ DashKit.defaultProps = {
68
68
  },
69
69
  context: {},
70
70
  noOverlay: false,
71
+ focusable: false,
71
72
  };
@@ -1,6 +1,9 @@
1
1
  .dashkit-grid-item {
2
2
  position: relative;
3
3
  }
4
+ .dashkit-grid-item:focus {
5
+ outline: none;
6
+ }
4
7
  .dashkit-grid-item__overlay {
5
8
  --_-dashkit-overlay-color: var(--dashkit-overlay-color, var(--g-color-base-generic));
6
9
  --_-dashkit-overlay-border-color: var(--dashkit-overlay-border-color, rgba(0, 0, 0, 0.1));
@@ -43,12 +43,17 @@ class GridItem extends react_1.default.PureComponent {
43
43
  };
44
44
  this.onFocusHandler = () => {
45
45
  this.setState({ isFocused: true });
46
+ if (this.controller) {
47
+ this.controller.abort();
48
+ }
46
49
  };
47
50
  this.onBlurHandler = () => {
51
+ this.controller = new AbortController();
48
52
  windowFocusObserver.getFocuseState().then((isWindowFocused) => {
49
- if (isWindowFocused) {
53
+ if (!this.controller.signal.aborted && isWindowFocused) {
50
54
  this.setState({ isFocused: false });
51
55
  }
56
+ this.controller = null;
52
57
  });
53
58
  };
54
59
  }
@@ -67,7 +72,7 @@ class GridItem extends react_1.default.PureComponent {
67
72
  render() {
68
73
  // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
69
74
  // https://github.com/STRML/react-grid-layout/issues/721
70
- const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, withCustomHandle, } = this.props;
75
+ const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, focusable, withCustomHandle, } = this.props;
71
76
  const { editMode } = this.context;
72
77
  const width = Number.parseInt(style.width, 10);
73
78
  const height = Number.parseInt(style.height, 10);
@@ -84,7 +89,13 @@ class GridItem extends react_1.default.PureComponent {
84
89
  'is-dragging': isDragging,
85
90
  'is-focused': this.state.isFocused,
86
91
  'with-custom-handle': withCustomHandle,
87
- }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, { onFocus: this.onFocusHandler, onBlur: this.onBlurHandler, tabIndex: -1 }),
92
+ }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, (focusable
93
+ ? {
94
+ onFocus: this.onFocusHandler,
95
+ onBlur: this.onBlurHandler,
96
+ tabIndex: -1,
97
+ }
98
+ : {})),
88
99
  react_1.default.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
89
100
  react_1.default.createElement(Item_1.default, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef })),
90
101
  !noOverlay && this.renderOverlay(),
@@ -105,6 +116,7 @@ GridItem.propTypes = {
105
116
  className: prop_types_1.default.string,
106
117
  style: prop_types_1.default.object,
107
118
  noOverlay: prop_types_1.default.bool,
119
+ focusable: prop_types_1.default.bool,
108
120
  withCustomHandle: prop_types_1.default.bool,
109
121
  onMouseDown: prop_types_1.default.func,
110
122
  onMouseUp: prop_types_1.default.func,
@@ -72,14 +72,14 @@ class GridLayout extends react_1.default.PureComponent {
72
72
  }
73
73
  }
74
74
  render() {
75
- const { layout, config, registerManager, editMode, noOverlay, draggableHandleClassName } = this.context;
75
+ const { layout, config, registerManager, editMode, noOverlay, focusable, draggableHandleClassName, } = this.context;
76
76
  this.pluginsRefs.length = config.items.length;
77
77
  return (react_1.default.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
78
78
  ? { draggableHandle: `.${draggableHandleClassName}` }
79
79
  : null), { draggableCancel: `.${constants_1.OVERLAY_CONTROLS_CLASS_NAME}` }), config.items.map((item, i) => {
80
80
  return (react_1.default.createElement(GridItem_1.default, { forwardedPluginRef: (pluginRef) => {
81
81
  this.pluginsRefs[i] = pluginRef;
82
- }, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
82
+ }, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
83
83
  })));
84
84
  }
85
85
  }
@@ -129,6 +129,7 @@ function useMemoStateContext(props) {
129
129
  config: props.config,
130
130
  context: props.context,
131
131
  noOverlay: props.noOverlay,
132
+ focusable: props.focusable,
132
133
  defaultGlobalParams: props.globalParams,
133
134
  globalParams: props.globalParams,
134
135
  editMode: props.editMode,
@@ -151,6 +152,7 @@ function useMemoStateContext(props) {
151
152
  props.config,
152
153
  props.context,
153
154
  props.noOverlay,
155
+ props.focusable,
154
156
  props.globalParams,
155
157
  props.editMode,
156
158
  props.settings,
@@ -21,6 +21,7 @@ interface DashKitDefaultProps {
21
21
  settings: SettingsProps;
22
22
  context: ContextProps;
23
23
  noOverlay: boolean;
24
+ focusable?: boolean;
24
25
  }
25
26
  export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
26
27
  }
@@ -63,4 +63,5 @@ DashKit.defaultProps = {
63
63
  },
64
64
  context: {},
65
65
  noOverlay: false,
66
+ focusable: false,
66
67
  };
@@ -1,6 +1,9 @@
1
1
  .dashkit-grid-item {
2
2
  position: relative;
3
3
  }
4
+ .dashkit-grid-item:focus {
5
+ outline: none;
6
+ }
4
7
  .dashkit-grid-item__overlay {
5
8
  --_-dashkit-overlay-color: var(--dashkit-overlay-color, var(--g-color-base-generic));
6
9
  --_-dashkit-overlay-border-color: var(--dashkit-overlay-border-color, rgba(0, 0, 0, 0.1));
@@ -41,12 +41,17 @@ class GridItem extends React.PureComponent {
41
41
  };
42
42
  this.onFocusHandler = () => {
43
43
  this.setState({ isFocused: true });
44
+ if (this.controller) {
45
+ this.controller.abort();
46
+ }
44
47
  };
45
48
  this.onBlurHandler = () => {
49
+ this.controller = new AbortController();
46
50
  windowFocusObserver.getFocuseState().then((isWindowFocused) => {
47
- if (isWindowFocused) {
51
+ if (!this.controller.signal.aborted && isWindowFocused) {
48
52
  this.setState({ isFocused: false });
49
53
  }
54
+ this.controller = null;
50
55
  });
51
56
  };
52
57
  }
@@ -65,7 +70,7 @@ class GridItem extends React.PureComponent {
65
70
  render() {
66
71
  // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
67
72
  // https://github.com/STRML/react-grid-layout/issues/721
68
- const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, withCustomHandle, } = this.props;
73
+ const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, focusable, withCustomHandle, } = this.props;
69
74
  const { editMode } = this.context;
70
75
  const width = Number.parseInt(style.width, 10);
71
76
  const height = Number.parseInt(style.height, 10);
@@ -82,7 +87,13 @@ class GridItem extends React.PureComponent {
82
87
  'is-dragging': isDragging,
83
88
  'is-focused': this.state.isFocused,
84
89
  'with-custom-handle': withCustomHandle,
85
- }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, { onFocus: this.onFocusHandler, onBlur: this.onBlurHandler, tabIndex: -1 }),
90
+ }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, (focusable
91
+ ? {
92
+ onFocus: this.onFocusHandler,
93
+ onBlur: this.onBlurHandler,
94
+ tabIndex: -1,
95
+ }
96
+ : {})),
86
97
  React.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
87
98
  React.createElement(Item, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef })),
88
99
  !noOverlay && this.renderOverlay(),
@@ -103,6 +114,7 @@ GridItem.propTypes = {
103
114
  className: PropTypes.string,
104
115
  style: PropTypes.object,
105
116
  noOverlay: PropTypes.bool,
117
+ focusable: PropTypes.bool,
106
118
  withCustomHandle: PropTypes.bool,
107
119
  onMouseDown: PropTypes.func,
108
120
  onMouseUp: PropTypes.func,
@@ -69,14 +69,14 @@ class GridLayout extends React.PureComponent {
69
69
  }
70
70
  }
71
71
  render() {
72
- const { layout, config, registerManager, editMode, noOverlay, draggableHandleClassName } = this.context;
72
+ const { layout, config, registerManager, editMode, noOverlay, focusable, draggableHandleClassName, } = this.context;
73
73
  this.pluginsRefs.length = config.items.length;
74
74
  return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
75
75
  ? { draggableHandle: `.${draggableHandleClassName}` }
76
76
  : null), { draggableCancel: `.${OVERLAY_CONTROLS_CLASS_NAME}` }), config.items.map((item, i) => {
77
77
  return (React.createElement(GridItem, { forwardedPluginRef: (pluginRef) => {
78
78
  this.pluginsRefs[i] = pluginRef;
79
- }, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
79
+ }, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
80
80
  })));
81
81
  }
82
82
  }
@@ -125,6 +125,7 @@ function useMemoStateContext(props) {
125
125
  config: props.config,
126
126
  context: props.context,
127
127
  noOverlay: props.noOverlay,
128
+ focusable: props.focusable,
128
129
  defaultGlobalParams: props.globalParams,
129
130
  globalParams: props.globalParams,
130
131
  editMode: props.editMode,
@@ -147,6 +148,7 @@ function useMemoStateContext(props) {
147
148
  props.config,
148
149
  props.context,
149
150
  props.noOverlay,
151
+ props.focusable,
150
152
  props.globalParams,
151
153
  props.editMode,
152
154
  props.settings,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.0.2-beta.1",
3
+ "version": "8.0.2-beta.3",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {