@gravity-ui/dashkit 8.1.0 → 8.2.0-beta.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.
Files changed (76) hide show
  1. package/README.md +95 -0
  2. package/build/cjs/components/ActionPanel/ActionPanel.d.ts +4 -1
  3. package/build/cjs/components/ActionPanel/ActionPanel.js +10 -6
  4. package/build/cjs/components/ActionPanel/types.d.ts +3 -1
  5. package/build/cjs/components/DashKit/DashKit.d.ts +4 -3
  6. package/build/cjs/components/DashKit/DashKit.js +1 -0
  7. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +10 -0
  8. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +35 -0
  9. package/build/cjs/components/GridItem/GridItem.d.ts +2 -2
  10. package/build/cjs/components/GridItem/GridItem.js +8 -5
  11. package/build/cjs/components/GridLayout/GridLayout.d.ts +3 -0
  12. package/build/cjs/components/GridLayout/GridLayout.js +51 -11
  13. package/build/cjs/components/GridLayout/ReactGridLayout.d.ts +3 -0
  14. package/build/cjs/components/GridLayout/ReactGridLayout.js +49 -0
  15. package/build/cjs/components/Item/Item.css +1 -1
  16. package/build/cjs/components/Item/Item.d.ts +1 -0
  17. package/build/cjs/components/Item/Item.js +7 -1
  18. package/build/cjs/components/OverlayControls/OverlayControls.js +2 -2
  19. package/build/cjs/components/index.d.ts +1 -0
  20. package/build/cjs/components/index.js +1 -0
  21. package/build/cjs/constants/common.d.ts +4 -0
  22. package/build/cjs/constants/common.js +5 -1
  23. package/build/cjs/context/DashKitContext.d.ts +1 -0
  24. package/build/cjs/context/DashKitContext.js +3 -1
  25. package/build/cjs/hocs/prepareItem.d.ts +1 -0
  26. package/build/cjs/hocs/prepareItem.js +4 -2
  27. package/build/cjs/hocs/withContext.js +84 -6
  28. package/build/cjs/hooks/useDnDItemProps.d.ts +10 -0
  29. package/build/cjs/hooks/useDnDItemProps.js +30 -0
  30. package/build/cjs/shared/constants/common.d.ts +1 -0
  31. package/build/cjs/shared/constants/common.js +2 -1
  32. package/build/cjs/shared/modules/state-and-params.d.ts +2 -1
  33. package/build/cjs/shared/modules/state-and-params.js +18 -4
  34. package/build/cjs/shared/types/common.d.ts +15 -0
  35. package/build/cjs/typings/config.d.ts +3 -0
  36. package/build/cjs/typings/plugin.d.ts +1 -0
  37. package/build/cjs/utils/update-manager.d.ts +10 -3
  38. package/build/cjs/utils/update-manager.js +52 -20
  39. package/build/esm/components/ActionPanel/ActionPanel.d.ts +4 -1
  40. package/build/esm/components/ActionPanel/ActionPanel.js +8 -5
  41. package/build/esm/components/ActionPanel/types.d.ts +3 -1
  42. package/build/esm/components/DashKit/DashKit.d.ts +4 -3
  43. package/build/esm/components/DashKit/DashKit.js +1 -0
  44. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +10 -0
  45. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +30 -0
  46. package/build/esm/components/GridItem/GridItem.d.ts +2 -2
  47. package/build/esm/components/GridItem/GridItem.js +8 -5
  48. package/build/esm/components/GridLayout/GridLayout.d.ts +3 -0
  49. package/build/esm/components/GridLayout/GridLayout.js +52 -12
  50. package/build/esm/components/GridLayout/ReactGridLayout.d.ts +3 -0
  51. package/build/esm/components/GridLayout/ReactGridLayout.js +45 -0
  52. package/build/esm/components/Item/Item.css +1 -1
  53. package/build/esm/components/Item/Item.d.ts +1 -0
  54. package/build/esm/components/Item/Item.js +7 -1
  55. package/build/esm/components/OverlayControls/OverlayControls.js +2 -2
  56. package/build/esm/components/index.d.ts +1 -0
  57. package/build/esm/components/index.js +1 -0
  58. package/build/esm/constants/common.d.ts +4 -0
  59. package/build/esm/constants/common.js +4 -0
  60. package/build/esm/context/DashKitContext.d.ts +1 -0
  61. package/build/esm/context/DashKitContext.js +2 -1
  62. package/build/esm/hocs/prepareItem.d.ts +1 -0
  63. package/build/esm/hocs/prepareItem.js +4 -2
  64. package/build/esm/hocs/withContext.js +85 -7
  65. package/build/esm/hooks/useDnDItemProps.d.ts +10 -0
  66. package/build/esm/hooks/useDnDItemProps.js +25 -0
  67. package/build/esm/shared/constants/common.d.ts +1 -0
  68. package/build/esm/shared/constants/common.js +1 -0
  69. package/build/esm/shared/modules/state-and-params.d.ts +2 -1
  70. package/build/esm/shared/modules/state-and-params.js +18 -4
  71. package/build/esm/shared/types/common.d.ts +15 -0
  72. package/build/esm/typings/config.d.ts +3 -0
  73. package/build/esm/typings/plugin.d.ts +1 -0
  74. package/build/esm/utils/update-manager.d.ts +10 -3
  75. package/build/esm/utils/update-manager.js +50 -19
  76. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import type { Config, ConfigItem, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
- import type { AddConfigItem, SetItemOptions, WidgetLayout } from '../typings';
1
+ import type { Config, ConfigItem, ConfigItemGroup, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
+ import type { AddConfigItem, SetItemOptions, SetNewItemOptions, WidgetLayout } from '../typings';
3
3
  import { RegisterManagerPluginLayout } from './register-manager';
4
4
  interface RemoveItemArg {
5
5
  id: string;
@@ -13,13 +13,20 @@ interface ChangeStateAndParamsArg {
13
13
  stateAndParams: ItemStateAndParams;
14
14
  options?: ItemStateAndParamsChangeOptions;
15
15
  }
16
+ export declare const getChangedParams: ({ initiatorItem, stateAndParams, itemsStateAndParams, }: {
17
+ initiatorItem: ConfigItem | ConfigItemGroup;
18
+ stateAndParams: ItemStateAndParams;
19
+ itemsStateAndParams: ItemsStateAndParams;
20
+ }) => {
21
+ [x: string]: string | string[];
22
+ };
16
23
  export declare class UpdateManager {
17
24
  static addItem({ item, namespace, layout, config, options, }: {
18
25
  item: AddConfigItem;
19
26
  namespace: string;
20
27
  layout: RegisterManagerPluginLayout;
21
28
  config: Config;
22
- options: SetItemOptions;
29
+ options: SetNewItemOptions;
23
30
  }): Config;
24
31
  static editItem({ item, namespace, config, options, }: {
25
32
  item: ConfigItem;
@@ -74,6 +74,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
74
74
  : allowedParams;
75
75
  }
76
76
  const stateParamsConf = stateAndParams.params;
77
+ // check if structure is StringParams or Record<string, StringParams>
78
+ // if it's Record<string, StringParams>, then this is a group application of params
79
+ // and checking for comparison of allowedParams and stateParamsConf is not necessary
80
+ const isGroupParamsApply = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
81
+ !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]);
77
82
  if (isItemWithTabs(item)) {
78
83
  let tab;
79
84
  if ('state' in stateAndParams && ((_a = stateAndParams.state) === null || _a === void 0 ? void 0 : _a.tabId)) {
@@ -86,14 +91,11 @@ function getAllowableChangedParams(item, stateAndParams, itemsStateAndParams, pa
86
91
  allowedParams = pick(stateParamsConf, Object.keys((tab === null || tab === void 0 ? void 0 : tab.params) || {}));
87
92
  }
88
93
  else {
89
- // check if structure is StringParams or Record<string, StringParams>
90
- const paramsConf = typeof (stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id]) === 'object' &&
91
- !Array.isArray(stateParamsConf === null || stateParamsConf === void 0 ? void 0 : stateParamsConf[item.id])
92
- ? stateParamsConf[item.id]
93
- : stateParamsConf;
94
+ const paramsConf = isGroupParamsApply ? stateParamsConf[item.id] : stateParamsConf;
94
95
  allowedParams = pick(paramsConf, Object.keys(item.defaults || {}));
95
96
  }
96
- if (Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
97
+ if (!isGroupParamsApply &&
98
+ Object.keys(allowedParams || {}).length !== Object.keys(stateParamsConf || {}).length) {
97
99
  console.warn('Параметры, которых нет в defaults, будут проигнорированы!');
98
100
  }
99
101
  return allowedParams;
@@ -176,6 +178,11 @@ function getNewItemData({ item, config, counter: argsCounter, salt, options }) {
176
178
  }
177
179
  return { data, counter, excludeIds };
178
180
  }
181
+ export const getChangedParams = ({ initiatorItem, stateAndParams, itemsStateAndParams, }) => {
182
+ const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
183
+ const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
184
+ return Object.assign(Object.assign({}, allowableParams), allowableActionParams);
185
+ };
179
186
  function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStateAndParams, stateAndParams, config, unusedIds, }) {
180
187
  var _a;
181
188
  const meta = addGroupToQueue({
@@ -188,9 +195,12 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
188
195
  const currentItemParams = (_a = itemsStateAndParams[initiatorId]) === null || _a === void 0 ? void 0 : _a.params;
189
196
  for (const groupItem of initiatorItem.data.group) {
190
197
  if (groupItemIds.includes(groupItem.id)) {
191
- const allowableParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams);
192
- const allowableActionParams = getAllowableChangedParams(groupItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
193
- updatedItems[groupItem.id] = Object.assign(Object.assign({}, allowableParams), allowableActionParams);
198
+ const changedParams = getChangedParams({
199
+ initiatorItem: groupItem,
200
+ stateAndParams,
201
+ itemsStateAndParams,
202
+ });
203
+ updatedItems[groupItem.id] = changedParams;
194
204
  continue;
195
205
  }
196
206
  if (currentItemParams && currentItemParams[groupItem.id]) {
@@ -212,19 +222,37 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
212
222
  }
213
223
  export class UpdateManager {
214
224
  static addItem({ item, namespace = DEFAULT_NAMESPACE, layout, config, options, }) {
215
- const layoutY = Math.max(0, ...config.layout.map(({ h, y }) => h + y));
216
- const saveDefaultLayout = pick(layout, ['h', 'w', 'x', 'y']);
217
225
  const salt = config.salt;
218
226
  const newItemData = getNewItemData({ item, config, salt, counter: config.counter, options });
219
227
  let counter = newItemData.counter;
220
228
  const newIdData = getNewId({ config, salt, counter, excludeIds: newItemData.excludeIds });
221
229
  counter = newIdData.counter;
222
230
  const newItem = Object.assign(Object.assign({}, item), { id: newIdData.id, data: newItemData.data, namespace });
223
- return update(config, {
224
- items: { $push: [newItem] },
225
- layout: { $push: [Object.assign(Object.assign({}, saveDefaultLayout), { y: layoutY, i: newItem.id })] },
226
- counter: { $set: counter },
227
- });
231
+ const saveDefaultLayout = pick(layout, ['h', 'w', 'x', 'y']);
232
+ if (options.updateLayout) {
233
+ const byId = options.updateLayout.reduce((memo, t) => {
234
+ memo[t.i] = t;
235
+ return memo;
236
+ }, {});
237
+ const newLayout = [
238
+ ...config.layout.map((t) => (Object.assign(Object.assign({}, t), (byId[t.i] || {})))),
239
+ Object.assign(Object.assign({}, saveDefaultLayout), { i: newItem.id }),
240
+ ];
241
+ return update(config, {
242
+ items: { $push: [newItem] },
243
+ layout: { $set: newLayout },
244
+ counter: { $set: counter },
245
+ });
246
+ }
247
+ else {
248
+ const layoutY = Math.max(0, ...config.layout.map(({ h, y }) => h + y));
249
+ const newLayoutItem = Object.assign(Object.assign({}, saveDefaultLayout), { y: layoutY, i: newItem.id });
250
+ return update(config, {
251
+ items: { $push: [newItem] },
252
+ layout: { $push: [newLayoutItem] },
253
+ counter: { $set: counter },
254
+ });
255
+ }
228
256
  }
229
257
  static editItem({ item, namespace = DEFAULT_NAMESPACE, config, options, }) {
230
258
  const itemIndex = config.items.findIndex(({ id }) => item.id === id);
@@ -332,8 +360,11 @@ export class UpdateManager {
332
360
  });
333
361
  }
334
362
  if ('params' in stateAndParams) {
335
- const allowableParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams);
336
- const allowableActionParams = getAllowableChangedParams(initiatorItem, stateAndParams, itemsStateAndParams, { type: 'actionParams', returnPrefix: true });
363
+ const changedParams = getChangedParams({
364
+ initiatorItem,
365
+ stateAndParams,
366
+ itemsStateAndParams,
367
+ });
337
368
  const tabId = isItemWithTabs(initiatorItem)
338
369
  ? newTabId || resolveItemInnerId({ item: initiatorItem, itemsStateAndParams })
339
370
  : undefined;
@@ -348,7 +379,7 @@ export class UpdateManager {
348
379
  $unset: unusedIds,
349
380
  [initiatorId]: {
350
381
  $auto: Object.assign({ params: {
351
- [commandUpdateParams]: Object.assign(Object.assign({}, allowableParams), allowableActionParams),
382
+ [commandUpdateParams]: changedParams,
352
383
  } }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
353
384
  },
354
385
  [META_KEY]: { $set: meta },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/dashkit",
3
- "version": "8.1.0",
3
+ "version": "8.2.0-beta.0",
4
4
  "description": "Library for rendering dashboard grid layout",
5
5
  "license": "MIT",
6
6
  "repository": {