@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.
- package/README.md +95 -0
- package/build/cjs/components/ActionPanel/ActionPanel.d.ts +4 -1
- package/build/cjs/components/ActionPanel/ActionPanel.js +10 -6
- package/build/cjs/components/ActionPanel/types.d.ts +3 -1
- package/build/cjs/components/DashKit/DashKit.d.ts +4 -3
- package/build/cjs/components/DashKit/DashKit.js +1 -0
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +10 -0
- package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +35 -0
- package/build/cjs/components/GridItem/GridItem.d.ts +2 -2
- package/build/cjs/components/GridItem/GridItem.js +8 -5
- package/build/cjs/components/GridLayout/GridLayout.d.ts +3 -0
- package/build/cjs/components/GridLayout/GridLayout.js +51 -11
- package/build/cjs/components/GridLayout/ReactGridLayout.d.ts +3 -0
- package/build/cjs/components/GridLayout/ReactGridLayout.js +49 -0
- package/build/cjs/components/Item/Item.css +1 -1
- package/build/cjs/components/Item/Item.d.ts +1 -0
- package/build/cjs/components/Item/Item.js +7 -1
- package/build/cjs/components/OverlayControls/OverlayControls.js +2 -2
- package/build/cjs/components/index.d.ts +1 -0
- package/build/cjs/components/index.js +1 -0
- package/build/cjs/constants/common.d.ts +4 -0
- package/build/cjs/constants/common.js +5 -1
- package/build/cjs/context/DashKitContext.d.ts +1 -0
- package/build/cjs/context/DashKitContext.js +3 -1
- package/build/cjs/hocs/prepareItem.d.ts +1 -0
- package/build/cjs/hocs/prepareItem.js +4 -2
- package/build/cjs/hocs/withContext.js +84 -6
- package/build/cjs/hooks/useDnDItemProps.d.ts +10 -0
- package/build/cjs/hooks/useDnDItemProps.js +30 -0
- package/build/cjs/shared/constants/common.d.ts +1 -0
- package/build/cjs/shared/constants/common.js +2 -1
- package/build/cjs/shared/modules/state-and-params.d.ts +2 -1
- package/build/cjs/shared/modules/state-and-params.js +18 -4
- package/build/cjs/shared/types/common.d.ts +15 -0
- package/build/cjs/typings/config.d.ts +3 -0
- package/build/cjs/typings/plugin.d.ts +1 -0
- package/build/cjs/utils/update-manager.d.ts +10 -3
- package/build/cjs/utils/update-manager.js +52 -20
- package/build/esm/components/ActionPanel/ActionPanel.d.ts +4 -1
- package/build/esm/components/ActionPanel/ActionPanel.js +8 -5
- package/build/esm/components/ActionPanel/types.d.ts +3 -1
- package/build/esm/components/DashKit/DashKit.d.ts +4 -3
- package/build/esm/components/DashKit/DashKit.js +1 -0
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +10 -0
- package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +30 -0
- package/build/esm/components/GridItem/GridItem.d.ts +2 -2
- package/build/esm/components/GridItem/GridItem.js +8 -5
- package/build/esm/components/GridLayout/GridLayout.d.ts +3 -0
- package/build/esm/components/GridLayout/GridLayout.js +52 -12
- package/build/esm/components/GridLayout/ReactGridLayout.d.ts +3 -0
- package/build/esm/components/GridLayout/ReactGridLayout.js +45 -0
- package/build/esm/components/Item/Item.css +1 -1
- package/build/esm/components/Item/Item.d.ts +1 -0
- package/build/esm/components/Item/Item.js +7 -1
- package/build/esm/components/OverlayControls/OverlayControls.js +2 -2
- package/build/esm/components/index.d.ts +1 -0
- package/build/esm/components/index.js +1 -0
- package/build/esm/constants/common.d.ts +4 -0
- package/build/esm/constants/common.js +4 -0
- package/build/esm/context/DashKitContext.d.ts +1 -0
- package/build/esm/context/DashKitContext.js +2 -1
- package/build/esm/hocs/prepareItem.d.ts +1 -0
- package/build/esm/hocs/prepareItem.js +4 -2
- package/build/esm/hocs/withContext.js +85 -7
- package/build/esm/hooks/useDnDItemProps.d.ts +10 -0
- package/build/esm/hooks/useDnDItemProps.js +25 -0
- package/build/esm/shared/constants/common.d.ts +1 -0
- package/build/esm/shared/constants/common.js +1 -0
- package/build/esm/shared/modules/state-and-params.d.ts +2 -1
- package/build/esm/shared/modules/state-and-params.js +18 -4
- package/build/esm/shared/types/common.d.ts +15 -0
- package/build/esm/typings/config.d.ts +3 -0
- package/build/esm/typings/plugin.d.ts +1 -0
- package/build/esm/utils/update-manager.d.ts +10 -3
- package/build/esm/utils/update-manager.js +50 -19
- 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:
|
|
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
|
-
|
|
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 (
|
|
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
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
|
336
|
-
|
|
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]:
|
|
382
|
+
[commandUpdateParams]: changedParams,
|
|
352
383
|
} }, (hasState ? { state: { $set: stateAndParams.state } } : {})),
|
|
353
384
|
},
|
|
354
385
|
[META_KEY]: { $set: meta },
|