@gravity-ui/dashkit 5.4.0 → 5.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.6.0](https://github.com/gravity-ui/dashkit/compare/v5.5.0...v5.6.0) (2023-04-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * add item state to overlay dropdown menu action handler ([#57](https://github.com/gravity-ui/dashkit/issues/57)) ([78b13fa](https://github.com/gravity-ui/dashkit/commit/78b13fa4107e94abd93c6e469a36840b61b6a10a))
9
+
10
+ ## [5.5.0](https://github.com/gravity-ui/dashkit/compare/v5.4.0...v5.5.0) (2023-04-17)
11
+
12
+
13
+ ### Features
14
+
15
+ * support all props from react-grid-layout ([#54](https://github.com/gravity-ui/dashkit/issues/54)) ([7e3d316](https://github.com/gravity-ui/dashkit/commit/7e3d316a4cc0fbbf24a23f52408c4fa10f69a4b5))
16
+
3
17
  ## [5.4.0](https://github.com/gravity-ui/dashkit/compare/v5.3.0...v5.4.0) (2023-04-13)
4
18
 
5
19
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonView, ButtonSize, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import { ConfigItem, PluginBase, StringParams, Config } from '../../shared';
3
+ import { ConfigItem, PluginBase, StringParams, Config, ItemState } from '../../shared';
4
4
  import type { RegisterManager } from '../../utils/register-manager';
5
5
  export declare enum OverlayControlsPosition {
6
6
  TopRight = "top_right",
@@ -23,7 +23,7 @@ export interface OverlayCustomControlItem {
23
23
  title?: string;
24
24
  icon?: MenuItemProps['icon'];
25
25
  iconSize?: number | string;
26
- handler?: (item: ConfigItem, params: StringParams) => void;
26
+ handler?: (item: ConfigItem, params: StringParams, state: ItemState) => void;
27
27
  visible?: (item: ConfigItem) => boolean;
28
28
  className?: string;
29
29
  qa?: string;
@@ -41,6 +41,7 @@ interface OverlayControlsProps extends OverlayControlsDefaultProps {
41
41
  type DashKitCtx = React.Context<{
42
42
  registerManager: RegisterManager;
43
43
  itemsParams: Record<string, StringParams>;
44
+ itemsState: Record<string, ItemState>;
44
45
  editItem: (item: ConfigItem) => void;
45
46
  removeItem: (id: string) => void;
46
47
  config: Config;
@@ -143,9 +143,10 @@ class OverlayControls extends react_1.default.Component {
143
143
  }
144
144
  renderDropdownMenu() {
145
145
  const { view, size } = this.props;
146
- const { registerManager, itemsParams } = this.context;
146
+ const { registerManager, itemsParams, itemsState } = this.context;
147
147
  const configItem = this.props.configItem;
148
148
  const itemParams = itemsParams[configItem.id];
149
+ const itemState = itemsState[configItem.id];
149
150
  let menu = registerManager.settings.menu;
150
151
  if (!menu.length) {
151
152
  menu = DEFAULT_DROPDOWN_MENU;
@@ -164,7 +165,7 @@ class OverlayControls extends react_1.default.Component {
164
165
  }
165
166
  const itemHandler = item.handler;
166
167
  const itemAction = typeof itemHandler === 'function'
167
- ? () => itemHandler(configItem, itemParams)
168
+ ? () => itemHandler(configItem, itemParams, itemState)
168
169
  : ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { });
169
170
  return {
170
171
  text: item.title || (0, i18n_1.default)(item.id),
@@ -1,12 +1,8 @@
1
1
  import { OverlayCustomControlItem } from '../components/OverlayControls/OverlayControls';
2
2
  import { MenuItems } from '../constants';
3
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
3
4
  export interface Settings {
4
- gridLayout?: {
5
- margin?: [number, number];
6
- rowHeight?: number;
7
- cols?: number;
8
- containerPadding?: [number, number];
9
- };
5
+ gridLayout?: ReactGridLayoutProps;
10
6
  theme?: string;
11
7
  isMobile?: boolean;
12
8
  menu?: Array<MenuItem>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ContextProps, SettingsProps, WidgetLayout } from './common';
3
3
  import { StringParams, ConfigItem, ItemState, ItemStateAndParams, PluginBase } from '../shared';
4
- import { RegisterManagerGridLayout } from '../utils/register-manager';
4
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
5
5
  export interface PluginWidgetProps {
6
6
  id: string;
7
7
  editMode: boolean;
@@ -16,7 +16,7 @@ export interface PluginWidgetProps {
16
16
  settings: SettingsProps;
17
17
  context: ContextProps;
18
18
  layout: WidgetLayout[];
19
- gridLayout: RegisterManagerGridLayout;
19
+ gridLayout: ReactGridLayoutProps;
20
20
  adjustWidgetLayout: (data: {
21
21
  widgetId: string;
22
22
  needSetDefault?: boolean;
@@ -1,4 +1,5 @@
1
1
  import { Plugin, PluginDefaultLayout, Settings } from '../typings';
2
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
2
3
  interface RegisterManagerDefaultLayout {
3
4
  x: number;
4
5
  y: number;
@@ -11,12 +12,6 @@ export type RegisterManagerPluginLayout = RegisterManagerDefaultLayout & PluginD
11
12
  export interface RegisterManagerPlugin extends Omit<Plugin, 'defaultLayout'> {
12
13
  defaultLayout: RegisterManagerDefaultLayout & Plugin['defaultLayout'];
13
14
  }
14
- export type RegisterManagerGridLayout = {
15
- margin: [number, number];
16
- rowHeight: number;
17
- cols: number;
18
- containerPadding: [number, number];
19
- } & Settings['gridLayout'];
20
15
  export type RegisterManagerSettings = {
21
16
  theme: string;
22
17
  } & Settings;
@@ -28,17 +23,7 @@ export declare class RegisterManager {
28
23
  registerPlugin(plugin: Plugin): void;
29
24
  setSettings(settings?: Settings): void;
30
25
  get settings(): RegisterManagerSettings;
31
- get gridLayout(): {
32
- margin: [number, number];
33
- rowHeight: number;
34
- cols: number;
35
- containerPadding: [number, number];
36
- } & {
37
- margin?: [number, number] | undefined;
38
- rowHeight?: number | undefined;
39
- cols?: number | undefined;
40
- containerPadding?: [number, number] | undefined;
41
- };
26
+ get gridLayout(): ReactGridLayoutProps;
42
27
  getPlugins(): RegisterManagerPlugin[];
43
28
  getItem(type: string): RegisterManagerPlugin;
44
29
  check(type: string): boolean;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ButtonView, ButtonSize, IconProps, MenuItemProps } from '@gravity-ui/uikit';
3
- import { ConfigItem, PluginBase, StringParams, Config } from '../../shared';
3
+ import { ConfigItem, PluginBase, StringParams, Config, ItemState } from '../../shared';
4
4
  import type { RegisterManager } from '../../utils/register-manager';
5
5
  import './OverlayControls.css';
6
6
  export declare enum OverlayControlsPosition {
@@ -24,7 +24,7 @@ export interface OverlayCustomControlItem {
24
24
  title?: string;
25
25
  icon?: MenuItemProps['icon'];
26
26
  iconSize?: number | string;
27
- handler?: (item: ConfigItem, params: StringParams) => void;
27
+ handler?: (item: ConfigItem, params: StringParams, state: ItemState) => void;
28
28
  visible?: (item: ConfigItem) => boolean;
29
29
  className?: string;
30
30
  qa?: string;
@@ -42,6 +42,7 @@ interface OverlayControlsProps extends OverlayControlsDefaultProps {
42
42
  type DashKitCtx = React.Context<{
43
43
  registerManager: RegisterManager;
44
44
  itemsParams: Record<string, StringParams>;
45
+ itemsState: Record<string, ItemState>;
45
46
  editItem: (item: ConfigItem) => void;
46
47
  removeItem: (id: string) => void;
47
48
  config: Config;
@@ -140,9 +140,10 @@ class OverlayControls extends React.Component {
140
140
  }
141
141
  renderDropdownMenu() {
142
142
  const { view, size } = this.props;
143
- const { registerManager, itemsParams } = this.context;
143
+ const { registerManager, itemsParams, itemsState } = this.context;
144
144
  const configItem = this.props.configItem;
145
145
  const itemParams = itemsParams[configItem.id];
146
+ const itemState = itemsState[configItem.id];
146
147
  let menu = registerManager.settings.menu;
147
148
  if (!menu.length) {
148
149
  menu = DEFAULT_DROPDOWN_MENU;
@@ -161,7 +162,7 @@ class OverlayControls extends React.Component {
161
162
  }
162
163
  const itemHandler = item.handler;
163
164
  const itemAction = typeof itemHandler === 'function'
164
- ? () => itemHandler(configItem, itemParams)
165
+ ? () => itemHandler(configItem, itemParams, itemState)
165
166
  : ((_a = this.getDropDownMenuItemConfig(item.id)) === null || _a === void 0 ? void 0 : _a.action) || (() => { });
166
167
  return {
167
168
  text: item.title || i18n(item.id),
@@ -1,12 +1,8 @@
1
1
  import { OverlayCustomControlItem } from '../components/OverlayControls/OverlayControls';
2
2
  import { MenuItems } from '../constants';
3
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
3
4
  export interface Settings {
4
- gridLayout?: {
5
- margin?: [number, number];
6
- rowHeight?: number;
7
- cols?: number;
8
- containerPadding?: [number, number];
9
- };
5
+ gridLayout?: ReactGridLayoutProps;
10
6
  theme?: string;
11
7
  isMobile?: boolean;
12
8
  menu?: Array<MenuItem>;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { ContextProps, SettingsProps, WidgetLayout } from './common';
3
3
  import { StringParams, ConfigItem, ItemState, ItemStateAndParams, PluginBase } from '../shared';
4
- import { RegisterManagerGridLayout } from '../utils/register-manager';
4
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
5
5
  export interface PluginWidgetProps {
6
6
  id: string;
7
7
  editMode: boolean;
@@ -16,7 +16,7 @@ export interface PluginWidgetProps {
16
16
  settings: SettingsProps;
17
17
  context: ContextProps;
18
18
  layout: WidgetLayout[];
19
- gridLayout: RegisterManagerGridLayout;
19
+ gridLayout: ReactGridLayoutProps;
20
20
  adjustWidgetLayout: (data: {
21
21
  widgetId: string;
22
22
  needSetDefault?: boolean;
@@ -1,4 +1,5 @@
1
1
  import { Plugin, PluginDefaultLayout, Settings } from '../typings';
2
+ import type { ReactGridLayoutProps } from 'react-grid-layout';
2
3
  interface RegisterManagerDefaultLayout {
3
4
  x: number;
4
5
  y: number;
@@ -11,12 +12,6 @@ export type RegisterManagerPluginLayout = RegisterManagerDefaultLayout & PluginD
11
12
  export interface RegisterManagerPlugin extends Omit<Plugin, 'defaultLayout'> {
12
13
  defaultLayout: RegisterManagerDefaultLayout & Plugin['defaultLayout'];
13
14
  }
14
- export type RegisterManagerGridLayout = {
15
- margin: [number, number];
16
- rowHeight: number;
17
- cols: number;
18
- containerPadding: [number, number];
19
- } & Settings['gridLayout'];
20
15
  export type RegisterManagerSettings = {
21
16
  theme: string;
22
17
  } & Settings;
@@ -28,17 +23,7 @@ export declare class RegisterManager {
28
23
  registerPlugin(plugin: Plugin): void;
29
24
  setSettings(settings?: Settings): void;
30
25
  get settings(): RegisterManagerSettings;
31
- get gridLayout(): {
32
- margin: [number, number];
33
- rowHeight: number;
34
- cols: number;
35
- containerPadding: [number, number];
36
- } & {
37
- margin?: [number, number] | undefined;
38
- rowHeight?: number | undefined;
39
- cols?: number | undefined;
40
- containerPadding?: [number, number] | undefined;
41
- };
26
+ get gridLayout(): ReactGridLayoutProps;
42
27
  getPlugins(): RegisterManagerPlugin[];
43
28
  getItem(type: string): RegisterManagerPlugin;
44
29
  check(type: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "5.4.0",
3
+ "version": "5.6.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -60,6 +60,7 @@
60
60
  "@types/jest": "^26.0.20",
61
61
  "@types/lodash": "^4.14.170",
62
62
  "@types/react": "^18.0.27",
63
+ "@types/react-grid-layout": "^1.3.2",
63
64
  "babel-jest": "^26.6.3",
64
65
  "bem-cn-lite": "^4.0.0",
65
66
  "copyfiles": "^2.4.1",