@gravity-ui/dashkit 8.11.0-beta.0 → 8.12.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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { Config, ConfigItem, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
2
+ import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
3
3
  import { AddNewItemOptions, ContextProps, DashKitGroup, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
4
4
  import GridLayout from '../GridLayout/GridLayout';
5
5
  import { OverlayControlItem } from '../OverlayControls/OverlayControls';
@@ -54,6 +54,7 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
54
54
  config: Config;
55
55
  itemsStateAndParams: ItemsStateAndParams;
56
56
  };
57
+ static reflowLayout(newLayoutItem: ConfigLayout, layout: ConfigLayout[], groups?: DashKitGroup[]): ConfigLayout[];
57
58
  metaRef: React.RefObject<GridLayout>;
58
59
  render(): JSX.Element;
59
60
  getItemsMeta(): any;
@@ -10,6 +10,19 @@ const utils_1 = require("../../utils");
10
10
  const DashKitView_1 = tslib_1.__importDefault(require("../DashKitView/DashKitView"));
11
11
  const registerManager = new utils_1.RegisterManager();
12
12
  const getReflowProps = (props) => Object.assign({ compactType: 'vertical', cols: 36 }, (0, pick_1.default)(props, 'cols', 'maxRows', 'compactType'));
13
+ const getReflowGroupsConfig = (groups = []) => {
14
+ const defaultGridProps = getReflowProps(registerManager.gridLayout);
15
+ return {
16
+ defaultProps: defaultGridProps,
17
+ groups: groups.reduce((memo, g) => {
18
+ const groupId = g.id || constants_1.DEFAULT_GROUP;
19
+ memo[groupId] = g.gridProperties
20
+ ? getReflowProps(g.gridProperties(defaultGridProps))
21
+ : defaultGridProps;
22
+ return memo;
23
+ }, {}),
24
+ };
25
+ };
13
26
  class DashKit extends react_1.default.PureComponent {
14
27
  constructor() {
15
28
  super(...arguments);
@@ -35,20 +48,7 @@ class DashKit extends react_1.default.PureComponent {
35
48
  else {
36
49
  const item = setItem;
37
50
  const layout = Object.assign({}, registerManager.getItem(item.type).defaultLayout);
38
- const defaultGridProps = getReflowProps(registerManager.gridLayout);
39
- const reflowLayoutOptions = {
40
- defaultProps: defaultGridProps,
41
- groups: groups.reduce((memo, g) => {
42
- const groupId = g.id || constants_1.DEFAULT_GROUP;
43
- if (g.gridProperties) {
44
- memo[groupId] = getReflowProps(g.gridProperties(defaultGridProps));
45
- }
46
- else {
47
- memo[groupId] = defaultGridProps;
48
- }
49
- return memo;
50
- }, {}),
51
- };
51
+ const reflowLayoutOptions = getReflowGroupsConfig(groups);
52
52
  const copyItem = Object.assign({}, item);
53
53
  if (copyItem.layout) {
54
54
  Object.assign(layout, copyItem.layout);
@@ -66,6 +66,9 @@ class DashKit extends react_1.default.PureComponent {
66
66
  static removeItem({ id, config, itemsStateAndParams, }) {
67
67
  return utils_1.UpdateManager.removeItem({ id, config, itemsStateAndParams });
68
68
  }
69
+ static reflowLayout(newLayoutItem, layout, groups) {
70
+ return (0, utils_1.reflowLayout)(newLayoutItem, layout, getReflowGroupsConfig(groups));
71
+ }
69
72
  render() {
70
73
  return react_1.default.createElement(DashKitView_1.default, Object.assign({ registerManager: registerManager, ref: this.metaRef }, this.props));
71
74
  }
@@ -1,5 +1,6 @@
1
+ import { ConfigLayout } from '../shared';
1
2
  import type { Config, ConfigItem, ConfigItemGroup, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
- import type { AddConfigItem, AddNewItemOptions, SetItemOptions, WidgetLayout } from '../typings';
3
+ import type { AddConfigItem, AddNewItemOptions, ReflowLayoutOptions, SetItemOptions, WidgetLayout } from '../typings';
3
4
  import { RegisterManagerPluginLayout } from './register-manager';
4
5
  interface RemoveItemArg {
5
6
  id: string;
@@ -20,6 +21,7 @@ export declare const getChangedParams: ({ initiatorItem, stateAndParams, itemsSt
20
21
  }) => {
21
22
  [x: string]: string | string[];
22
23
  };
24
+ export declare function reflowLayout(newLayoutItem: ConfigLayout, layout: ConfigLayout[], reflowLayoutOptions: ReflowLayoutOptions): ConfigLayout[];
23
25
  export declare class UpdateManager {
24
26
  static addItem({ item, namespace, layout, config, options, }: {
25
27
  item: AddConfigItem;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UpdateManager = exports.getChangedParams = void 0;
3
+ exports.UpdateManager = exports.reflowLayout = exports.getChangedParams = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const immutability_helper_1 = tslib_1.__importStar(require("immutability-helper"));
6
6
  const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
@@ -269,6 +269,7 @@ function reflowLayout(newLayoutItem, layout, reflowLayoutOptions) {
269
269
  }, [])
270
270
  .sort((a, b) => orderById[a.i] - orderById[b.i]);
271
271
  }
272
+ exports.reflowLayout = reflowLayout;
272
273
  class UpdateManager {
273
274
  static addItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, layout, config, options = {}, }) {
274
275
  const salt = config.salt;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { Config, ConfigItem, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
2
+ import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
3
3
  import { AddNewItemOptions, ContextProps, DashKitGroup, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
4
4
  import GridLayout from '../GridLayout/GridLayout';
5
5
  import { OverlayControlItem } from '../OverlayControls/OverlayControls';
@@ -54,6 +54,7 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
54
54
  config: Config;
55
55
  itemsStateAndParams: ItemsStateAndParams;
56
56
  };
57
+ static reflowLayout(newLayoutItem: ConfigLayout, layout: ConfigLayout[], groups?: DashKitGroup[]): ConfigLayout[];
57
58
  metaRef: React.RefObject<GridLayout>;
58
59
  render(): JSX.Element;
59
60
  getItemsMeta(): any;
@@ -2,10 +2,23 @@ import React from 'react';
2
2
  import noop from 'lodash/noop';
3
3
  import pick from 'lodash/pick';
4
4
  import { DEFAULT_GROUP, DEFAULT_NAMESPACE } from '../../constants';
5
- import { RegisterManager, UpdateManager } from '../../utils';
5
+ import { RegisterManager, UpdateManager, reflowLayout } from '../../utils';
6
6
  import DashKitView from '../DashKitView/DashKitView';
7
7
  const registerManager = new RegisterManager();
8
8
  const getReflowProps = (props) => Object.assign({ compactType: 'vertical', cols: 36 }, pick(props, 'cols', 'maxRows', 'compactType'));
9
+ const getReflowGroupsConfig = (groups = []) => {
10
+ const defaultGridProps = getReflowProps(registerManager.gridLayout);
11
+ return {
12
+ defaultProps: defaultGridProps,
13
+ groups: groups.reduce((memo, g) => {
14
+ const groupId = g.id || DEFAULT_GROUP;
15
+ memo[groupId] = g.gridProperties
16
+ ? getReflowProps(g.gridProperties(defaultGridProps))
17
+ : defaultGridProps;
18
+ return memo;
19
+ }, {}),
20
+ };
21
+ };
9
22
  export class DashKit extends React.PureComponent {
10
23
  constructor() {
11
24
  super(...arguments);
@@ -31,20 +44,7 @@ export class DashKit extends React.PureComponent {
31
44
  else {
32
45
  const item = setItem;
33
46
  const layout = Object.assign({}, registerManager.getItem(item.type).defaultLayout);
34
- const defaultGridProps = getReflowProps(registerManager.gridLayout);
35
- const reflowLayoutOptions = {
36
- defaultProps: defaultGridProps,
37
- groups: groups.reduce((memo, g) => {
38
- const groupId = g.id || DEFAULT_GROUP;
39
- if (g.gridProperties) {
40
- memo[groupId] = getReflowProps(g.gridProperties(defaultGridProps));
41
- }
42
- else {
43
- memo[groupId] = defaultGridProps;
44
- }
45
- return memo;
46
- }, {}),
47
- };
47
+ const reflowLayoutOptions = getReflowGroupsConfig(groups);
48
48
  const copyItem = Object.assign({}, item);
49
49
  if (copyItem.layout) {
50
50
  Object.assign(layout, copyItem.layout);
@@ -62,6 +62,9 @@ export class DashKit extends React.PureComponent {
62
62
  static removeItem({ id, config, itemsStateAndParams, }) {
63
63
  return UpdateManager.removeItem({ id, config, itemsStateAndParams });
64
64
  }
65
+ static reflowLayout(newLayoutItem, layout, groups) {
66
+ return reflowLayout(newLayoutItem, layout, getReflowGroupsConfig(groups));
67
+ }
65
68
  render() {
66
69
  return React.createElement(DashKitView, Object.assign({ registerManager: registerManager, ref: this.metaRef }, this.props));
67
70
  }
@@ -1,5 +1,6 @@
1
+ import { ConfigLayout } from '../shared';
1
2
  import type { Config, ConfigItem, ConfigItemGroup, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
- import type { AddConfigItem, AddNewItemOptions, SetItemOptions, WidgetLayout } from '../typings';
3
+ import type { AddConfigItem, AddNewItemOptions, ReflowLayoutOptions, SetItemOptions, WidgetLayout } from '../typings';
3
4
  import { RegisterManagerPluginLayout } from './register-manager';
4
5
  interface RemoveItemArg {
5
6
  id: string;
@@ -20,6 +21,7 @@ export declare const getChangedParams: ({ initiatorItem, stateAndParams, itemsSt
20
21
  }) => {
21
22
  [x: string]: string | string[];
22
23
  };
24
+ export declare function reflowLayout(newLayoutItem: ConfigLayout, layout: ConfigLayout[], reflowLayoutOptions: ReflowLayoutOptions): ConfigLayout[];
23
25
  export declare class UpdateManager {
24
26
  static addItem({ item, namespace, layout, config, options, }: {
25
27
  item: AddConfigItem;
@@ -222,7 +222,7 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
222
222
  };
223
223
  return update(itemsStateAndParams, obj);
224
224
  }
225
- function reflowLayout(newLayoutItem, layout, reflowLayoutOptions) {
225
+ export function reflowLayout(newLayoutItem, layout, reflowLayoutOptions) {
226
226
  const byGroup = {};
227
227
  const reducer = (memo, item, i, _items, isNewItem) => {
228
228
  memo[item.i] = i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.11.0-beta.0",
3
+ "version": "8.12.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {