@gravity-ui/dashkit 8.22.1 → 8.24.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 (77) hide show
  1. package/build/cjs/components/DashKit/DashKit.d.ts +14 -12
  2. package/build/cjs/components/DashKit/DashKit.js +2 -2
  3. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +2 -2
  4. package/build/cjs/components/DashKitView/DashKitView.js +2 -2
  5. package/build/cjs/components/GridItem/GridItem.js +2 -2
  6. package/build/cjs/components/GridLayout/GridLayout.d.ts +1 -1
  7. package/build/cjs/components/GridLayout/GridLayout.js +3 -2
  8. package/build/cjs/components/Item/Item.d.ts +2 -1
  9. package/build/cjs/components/MobileLayout/MobileLayout.d.ts +28 -21
  10. package/build/cjs/components/MobileLayout/MobileLayout.js +60 -47
  11. package/build/cjs/components/OverlayControls/OverlayControls.d.ts +4 -16
  12. package/build/cjs/components/OverlayControls/OverlayControls.js +8 -9
  13. package/build/cjs/context/DashKitContext.d.ts +30 -3
  14. package/build/cjs/context/DashKitContext.js +2 -6
  15. package/build/cjs/context/DashKitDnDContext.d.ts +10 -0
  16. package/build/cjs/context/DashKitDnDContext.js +6 -0
  17. package/build/cjs/context/DashkitOverlayControlsContext.d.ts +13 -0
  18. package/build/cjs/context/DashkitOverlayControlsContext.js +6 -0
  19. package/build/cjs/context/index.d.ts +3 -0
  20. package/build/cjs/context/index.js +6 -0
  21. package/build/cjs/hocs/prepareItem.d.ts +2 -1
  22. package/build/cjs/hocs/prepareItem.js +2 -2
  23. package/build/cjs/hocs/withContext.js +23 -20
  24. package/build/cjs/hooks/useDnDItemProps.js +2 -2
  25. package/build/cjs/plugins/Title/Title.d.ts +3 -5
  26. package/build/cjs/plugins/Title/Title.js +17 -11
  27. package/build/cjs/plugins/Title/constants.d.ts +3 -0
  28. package/build/cjs/plugins/Title/constants.js +26 -0
  29. package/build/cjs/plugins/Title/index.d.ts +2 -0
  30. package/build/cjs/plugins/Title/index.js +3 -1
  31. package/build/cjs/plugins/Title/types.d.ts +5 -0
  32. package/build/cjs/plugins/Title/types.js +2 -0
  33. package/build/cjs/plugins/Title/utils.d.ts +2 -0
  34. package/build/cjs/plugins/Title/utils.js +7 -0
  35. package/build/cjs/shared/modules/helpers.d.ts +1 -1
  36. package/build/cjs/shared/modules/helpers.js +1 -1
  37. package/build/cjs/shared/types/state-and-params.d.ts +2 -1
  38. package/build/cjs/typings/config.d.ts +1 -0
  39. package/build/esm/components/DashKit/DashKit.d.ts +14 -12
  40. package/build/esm/components/DashKit/DashKit.js +1 -1
  41. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +1 -1
  42. package/build/esm/components/DashKitView/DashKitView.js +1 -1
  43. package/build/esm/components/GridItem/GridItem.js +1 -1
  44. package/build/esm/components/GridLayout/GridLayout.d.ts +1 -1
  45. package/build/esm/components/GridLayout/GridLayout.js +2 -1
  46. package/build/esm/components/Item/Item.d.ts +2 -1
  47. package/build/esm/components/MobileLayout/MobileLayout.d.ts +29 -21
  48. package/build/esm/components/MobileLayout/MobileLayout.js +59 -46
  49. package/build/esm/components/OverlayControls/OverlayControls.d.ts +4 -16
  50. package/build/esm/components/OverlayControls/OverlayControls.js +7 -8
  51. package/build/esm/context/DashKitContext.d.ts +30 -3
  52. package/build/esm/context/DashKitContext.js +2 -4
  53. package/build/esm/context/DashKitDnDContext.d.ts +10 -0
  54. package/build/esm/context/DashKitDnDContext.js +2 -0
  55. package/build/esm/context/DashkitOverlayControlsContext.d.ts +13 -0
  56. package/build/esm/context/DashkitOverlayControlsContext.js +2 -0
  57. package/build/esm/context/index.d.ts +3 -0
  58. package/build/esm/context/index.js +3 -0
  59. package/build/esm/hocs/prepareItem.d.ts +2 -1
  60. package/build/esm/hocs/prepareItem.js +1 -1
  61. package/build/esm/hocs/withContext.js +20 -17
  62. package/build/esm/hooks/useDnDItemProps.js +1 -1
  63. package/build/esm/plugins/Title/Title.d.ts +3 -5
  64. package/build/esm/plugins/Title/Title.js +16 -9
  65. package/build/esm/plugins/Title/constants.d.ts +3 -0
  66. package/build/esm/plugins/Title/constants.js +23 -0
  67. package/build/esm/plugins/Title/index.d.ts +2 -0
  68. package/build/esm/plugins/Title/index.js +1 -0
  69. package/build/esm/plugins/Title/types.d.ts +5 -0
  70. package/build/esm/plugins/Title/types.js +1 -0
  71. package/build/esm/plugins/Title/utils.d.ts +2 -0
  72. package/build/esm/plugins/Title/utils.js +3 -0
  73. package/build/esm/shared/modules/helpers.d.ts +1 -1
  74. package/build/esm/shared/modules/helpers.js +1 -1
  75. package/build/esm/shared/types/state-and-params.d.ts +2 -1
  76. package/build/esm/typings/config.d.ts +1 -0
  77. package/package.json +1 -1
@@ -6,7 +6,7 @@ const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const isEqual_1 = tslib_1.__importDefault(require("lodash/isEqual"));
7
7
  const pick_1 = tslib_1.__importDefault(require("lodash/pick"));
8
8
  const common_1 = require("../constants/common");
9
- const DashKitContext_1 = require("../context/DashKitContext");
9
+ const context_1 = require("../context");
10
10
  const useDeepEqualMemo_1 = require("../hooks/useDeepEqualMemo");
11
11
  const shared_1 = require("../shared");
12
12
  const utils_1 = require("../utils");
@@ -22,7 +22,7 @@ function useMemoStateContext(props) {
22
22
  const nowrapAdjustedLayouts = react_1.default.useRef({});
23
23
  const [temporaryLayout, setTemporaryLayout] = react_1.default.useState(null);
24
24
  const resetTemporaryLayout = react_1.default.useCallback(() => setTemporaryLayout(null), [setTemporaryLayout]);
25
- const dndContext = react_1.default.useContext(DashKitContext_1.DashKitDnDContext);
25
+ const dndContext = react_1.default.useContext(context_1.DashKitDnDContext);
26
26
  const outerDnDEnable = Boolean(dndContext);
27
27
  // TODO: need move originalLayouts, adjustedLayouts to state
28
28
  const [layoutUpdateCounter, forceUpdateLayout] = react_1.default.useState(0);
@@ -286,6 +286,7 @@ function useMemoStateContext(props) {
286
286
  }
287
287
  return itemLayout;
288
288
  }, [
289
+ props.registerManager,
289
290
  resetTemporaryLayout,
290
291
  temporaryLayout,
291
292
  dragOverPlugin,
@@ -314,8 +315,6 @@ function useMemoStateContext(props) {
314
315
  });
315
316
  }, [dragPropsContext, onDropProp, setTemporaryLayout, resetTemporaryLayout]);
316
317
  const dashkitContextValue = react_1.default.useMemo(() => ({
317
- layout: resultLayout,
318
- temporaryLayout,
319
318
  config: props.config,
320
319
  groups: props.groups,
321
320
  context: props.context,
@@ -325,24 +324,26 @@ function useMemoStateContext(props) {
325
324
  globalParams: props.globalParams,
326
325
  editMode: props.editMode,
327
326
  settings: props.settings,
328
- itemsState,
329
- itemsParams,
330
- registerManager: props.registerManager,
331
- onItemStateAndParamsChange,
332
- onDrop,
333
- onDropDragOver,
334
327
  onItemMountChange: props.onItemMountChange,
335
328
  onItemRender: props.onItemRender,
329
+ draggableHandleClassName: props.draggableHandleClassName,
330
+ registerManager: props.registerManager,
331
+ forwardedMetaRef: props.forwardedMetaRef,
332
+ layout: resultLayout,
333
+ temporaryLayout,
336
334
  layoutChange: onLayoutChange,
337
- getItemsMeta,
338
- reloadItems,
339
335
  memorizeOriginalLayout,
340
336
  revertToOriginalLayout,
341
- forwardedMetaRef: props.forwardedMetaRef,
342
- draggableHandleClassName: props.draggableHandleClassName,
337
+ itemsState,
338
+ itemsParams,
339
+ onItemStateAndParamsChange,
340
+ getItemsMeta,
341
+ reloadItems,
342
+ onDrop,
343
+ onDropDragOver,
343
344
  outerDnDEnable,
344
345
  dragOverPlugin,
345
- /* default bypassing handlers */
346
+ /* default handlers bypass */
346
347
  onDragStart: props.onDragStart,
347
348
  onDrag: props.onDrag,
348
349
  onDragStop: props.onDragStop,
@@ -388,14 +389,15 @@ function useMemoStateContext(props) {
388
389
  const controlsContextValue = react_1.default.useMemo(() => ({
389
390
  overlayControls: props.overlayControls,
390
391
  context: props.context,
391
- menu: overlayMenuItems,
392
392
  itemsStateAndParams: props.itemsStateAndParams,
393
+ itemsState,
393
394
  itemsParams,
395
+ getPreparedCopyItemOptions: props.getPreparedCopyItemOptions,
396
+ onCopyFulfill: props.onCopyFulfill,
397
+ menu: overlayMenuItems,
394
398
  editItem: props.onItemEdit,
395
399
  removeItem: onItemRemove,
396
400
  getLayoutItem: getLayoutItem,
397
- getPreparedCopyItemOptions: props.getPreparedCopyItemOptions,
398
- onCopyFulfill: props.onCopyFulfill,
399
401
  }), [
400
402
  props.overlayControls,
401
403
  props.context,
@@ -404,6 +406,7 @@ function useMemoStateContext(props) {
404
406
  props.getPreparedCopyItemOptions,
405
407
  props.onCopyFulfill,
406
408
  overlayMenuItems,
409
+ itemsState,
407
410
  itemsParams,
408
411
  onItemRemove,
409
412
  getLayoutItem,
@@ -413,8 +416,8 @@ function useMemoStateContext(props) {
413
416
  function withContext(Component) {
414
417
  const WithContext = (props) => {
415
418
  const { dashkitContextValue, controlsContextValue } = useMemoStateContext(props);
416
- return (react_1.default.createElement(DashKitContext_1.DashKitContext.Provider, { value: dashkitContextValue },
417
- react_1.default.createElement(DashKitContext_1.DashkitOvelayControlsContext.Provider, { value: controlsContextValue },
419
+ return (react_1.default.createElement(context_1.DashKitContext.Provider, { value: dashkitContextValue },
420
+ react_1.default.createElement(context_1.DashkitOvelayControlsContext.Provider, { value: controlsContextValue },
418
421
  react_1.default.createElement(Component, null))));
419
422
  };
420
423
  WithContext.displayName = `withContext(${Component.displayName || Component.name || 'Component'}`;
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useDnDItemProps = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
- const DashKitContext_1 = require("../context/DashKitContext");
6
+ const context_1 = require("../context");
7
7
  const useDnDItemProps = (item) => {
8
- const dragContext = react_1.default.useContext(DashKitContext_1.DashKitDnDContext);
8
+ const dragContext = react_1.default.useContext(context_1.DashKitDnDContext);
9
9
  const onDragStart = react_1.default.useCallback((e) => {
10
10
  if (dragContext && item.dragProps) {
11
11
  dragContext.onDragStart(e, item.dragProps);
@@ -1,15 +1,13 @@
1
1
  import React from 'react';
2
2
  import { Plugin, PluginWidgetProps } from '../../typings';
3
- export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
3
+ import type { PluginTitleSize, TitleFontParams } from './types';
4
4
  export interface PluginTitleProps extends PluginWidgetProps {
5
5
  data: {
6
- size: PluginTitleSize;
6
+ size: PluginTitleSize | TitleFontParams;
7
7
  text: string;
8
8
  showInTOC: boolean;
9
9
  } & PluginWidgetProps['data'];
10
10
  }
11
- export declare class PluginTitle extends React.Component<PluginTitleProps> {
12
- render(): JSX.Element;
13
- }
11
+ export declare const PluginTitle: React.ForwardRefExoticComponent<PluginTitleProps & React.RefAttributes<HTMLDivElement>>;
14
12
  declare const plugin: Plugin<PluginTitleProps>;
15
13
  export default plugin;
@@ -5,22 +5,28 @@ const tslib_1 = require("tslib");
5
5
  const react_1 = tslib_1.__importDefault(require("react"));
6
6
  const cn_1 = require("../../utils/cn");
7
7
  const constants_1 = require("../constants");
8
+ const constants_2 = require("./constants");
9
+ const utils_1 = require("./utils");
8
10
  const b = (0, cn_1.cn)('dashkit-plugin-title');
9
- class PluginTitle extends react_1.default.Component {
10
- render() {
11
- const { data } = this.props;
12
- const text = data.text ? data.text : '';
13
- const size = data.size ? data.size : false;
14
- const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
15
- return (react_1.default.createElement("div", { id: id, className: b({ size }), [constants_1.PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
16
- }
17
- }
18
- exports.PluginTitle = PluginTitle;
11
+ exports.PluginTitle = react_1.default.forwardRef(function PluginTitleForwardRef(props, ref) {
12
+ var _a, _b;
13
+ const { data } = props;
14
+ const text = data.text ? data.text : '';
15
+ const size = (0, utils_1.isCustomSize)(data.size) ? false : data.size;
16
+ const styles = (0, utils_1.isCustomSize)(data.size) && ((_a = data.size) === null || _a === void 0 ? void 0 : _a.fontSize)
17
+ ? {
18
+ fontSize: data.size.fontSize,
19
+ lineHeight: (_b = data.size.lineHeight) !== null && _b !== void 0 ? _b : constants_2.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER,
20
+ }
21
+ : undefined;
22
+ const id = data.showInTOC && text ? encodeURIComponent(text) : undefined;
23
+ return (react_1.default.createElement("div", { ref: ref, id: id, style: styles, className: b({ size }), [constants_1.PLUGIN_ROOT_ATTR_NAME]: 'title' }, text));
24
+ });
19
25
  const plugin = {
20
26
  type: 'title',
21
27
  defaultLayout: { w: 36, h: 2 },
22
28
  renderer(props, forwardedRef) {
23
- return react_1.default.createElement(PluginTitle, Object.assign({}, props, { ref: forwardedRef }));
29
+ return react_1.default.createElement(exports.PluginTitle, Object.assign({}, props, { ref: forwardedRef }));
24
30
  },
25
31
  };
26
32
  exports.default = plugin;
@@ -0,0 +1,3 @@
1
+ import { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare const TITLE_DEFAULT_SIZES: Record<PluginTitleSize, TitleFontParams>;
3
+ export declare const RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = exports.TITLE_DEFAULT_SIZES = void 0;
4
+ exports.TITLE_DEFAULT_SIZES = {
5
+ xl: {
6
+ fontSize: '32px',
7
+ lineHeight: '40px',
8
+ },
9
+ l: {
10
+ fontSize: '24px',
11
+ lineHeight: '28px',
12
+ },
13
+ m: {
14
+ fontSize: '20px',
15
+ lineHeight: '24px',
16
+ },
17
+ s: {
18
+ fontSize: '17px',
19
+ lineHeight: '24px',
20
+ },
21
+ xs: {
22
+ fontSize: '15px',
23
+ lineHeight: '20px',
24
+ },
25
+ };
26
+ exports.RECCOMMENDED_LINE_HEIGHT_MULTIPLIER = 1.25;
@@ -1,2 +1,4 @@
1
1
  export * from './Title';
2
2
  export { default as pluginTitle } from './Title';
3
+ export { PluginTitleSize, TitleFontParams } from './types';
4
+ export { TITLE_DEFAULT_SIZES } from './constants';
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pluginTitle = void 0;
3
+ exports.TITLE_DEFAULT_SIZES = exports.pluginTitle = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  tslib_1.__exportStar(require("./Title"), exports);
6
6
  var Title_1 = require("./Title");
7
7
  Object.defineProperty(exports, "pluginTitle", { enumerable: true, get: function () { return tslib_1.__importDefault(Title_1).default; } });
8
+ var constants_1 = require("./constants");
9
+ Object.defineProperty(exports, "TITLE_DEFAULT_SIZES", { enumerable: true, get: function () { return constants_1.TITLE_DEFAULT_SIZES; } });
@@ -0,0 +1,5 @@
1
+ export type PluginTitleSize = 'xl' | 'l' | 'm' | 's' | 'xs';
2
+ export interface TitleFontParams {
3
+ fontSize: string;
4
+ lineHeight?: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import type { PluginTitleSize, TitleFontParams } from './types';
2
+ export declare function isCustomSize(size: PluginTitleSize | TitleFontParams): size is TitleFontParams;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCustomSize = void 0;
4
+ function isCustomSize(size) {
5
+ return typeof size === 'object';
6
+ }
7
+ exports.isCustomSize = isCustomSize;
@@ -18,7 +18,7 @@ export declare function formQueueData({ items, itemsStateAndParams, }: {
18
18
  }): FormedQueueData[];
19
19
  export declare function resolveItemInnerId({ item, itemsStateAndParams, }: {
20
20
  item: Pick<ConfigItemWithTabs, 'data' | 'id'>;
21
- itemsStateAndParams: ItemsStateAndParams;
21
+ itemsStateAndParams?: ItemsStateAndParams;
22
22
  }): string;
23
23
  export declare function getMapItemsIgnores({ items, ignores, itemsStateAndParams, isFirstVersion, }: {
24
24
  items: (ConfigItem | ConfigItemGroup)[];
@@ -118,7 +118,7 @@ exports.formQueueData = formQueueData;
118
118
  function resolveItemInnerId({ item, itemsStateAndParams, }) {
119
119
  var _a, _b;
120
120
  const { id } = item;
121
- const stateTabId = (_b = (_a = itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.tabId;
121
+ const stateTabId = (_b = (_a = itemsStateAndParams === null || itemsStateAndParams === void 0 ? void 0 : itemsStateAndParams[id]) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.tabId;
122
122
  const { tabs } = item.data;
123
123
  if (stateTabId && tabs.some((tab) => tab.id === stateTabId)) {
124
124
  return stateTabId;
@@ -3,6 +3,7 @@ import { StringParams } from './common';
3
3
  export interface ItemState {
4
4
  [key: string]: any;
5
5
  }
6
+ export type ItemParams = StringParams | Record<string, StringParams>;
6
7
  export interface QueueItem {
7
8
  id: string;
8
9
  tabId?: string;
@@ -16,7 +17,7 @@ export type StateAndParamsMeta = {
16
17
  [META_KEY]: StateAndParamsMetaData;
17
18
  };
18
19
  export type ItemStateAndParams = {
19
- params?: StringParams | Record<string, StringParams>;
20
+ params?: ItemParams;
20
21
  state?: ItemState;
21
22
  };
22
23
  export type ItemStateAndParamsChangeOptions = {
@@ -28,6 +28,7 @@ export type AddNewItemOptions = SetItemOptions & {
28
28
  export interface DashkitGroupRenderProps {
29
29
  config: Config;
30
30
  editMode: boolean;
31
+ isMobile: boolean;
31
32
  items: ConfigItem[];
32
33
  layout: ConfigLayout[];
33
34
  context: any;
@@ -1,9 +1,9 @@
1
1
  import React from 'react';
2
2
  import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemDropProps, ItemsStateAndParams } from '../../shared';
3
- import { AddNewItemOptions, ContextProps, DashKitGroup, ItemManipulationCallback, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
3
+ import type { AddNewItemOptions, ContextProps, DashKitGroup, ItemManipulationCallback, MenuItem, Plugin, SetConfigItem, Settings, SettingsProps } from '../../typings';
4
4
  import GridLayout from '../GridLayout/GridLayout';
5
- import { OverlayControlItem, OverlayControlsCtxShape } from '../OverlayControls/OverlayControls';
6
- interface DashKitGeneralProps extends Pick<OverlayControlsCtxShape, 'getPreparedCopyItemOptions' | 'onCopyFulfill'> {
5
+ import type { OverlayControlItem, PreparedCopyItemOptions } from '../OverlayControls/OverlayControls';
6
+ interface DashKitGeneralProps {
7
7
  config: Config;
8
8
  editMode: boolean;
9
9
  draggableHandleClassName?: string;
@@ -11,6 +11,14 @@ interface DashKitGeneralProps extends Pick<OverlayControlsCtxShape, 'getPrepared
11
11
  overlayMenuItems?: MenuItem[] | null;
12
12
  }
13
13
  interface DashKitDefaultProps {
14
+ defaultGlobalParams: GlobalParams;
15
+ globalParams: GlobalParams;
16
+ itemsStateAndParams: ItemsStateAndParams;
17
+ settings: SettingsProps;
18
+ context: ContextProps;
19
+ noOverlay: boolean;
20
+ focusable?: boolean;
21
+ groups?: DashKitGroup[];
14
22
  onItemEdit: (item: ConfigItem) => void;
15
23
  onChange: (data: {
16
24
  config: Config;
@@ -23,27 +31,21 @@ interface DashKitDefaultProps {
23
31
  isMounted: boolean;
24
32
  }) => void;
25
33
  onItemRender?: (item: ConfigItem) => void;
34
+ getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
35
+ onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;
26
36
  onDragStart?: ItemManipulationCallback;
27
37
  onDrag?: ItemManipulationCallback;
28
38
  onDragStop?: ItemManipulationCallback;
29
39
  onResizeStart?: ItemManipulationCallback;
30
40
  onResize?: ItemManipulationCallback;
31
41
  onResizeStop?: ItemManipulationCallback;
32
- defaultGlobalParams: GlobalParams;
33
- globalParams: GlobalParams;
34
- itemsStateAndParams: ItemsStateAndParams;
35
- settings: SettingsProps;
36
- context: ContextProps;
37
- noOverlay: boolean;
38
- focusable?: boolean;
39
- groups?: DashKitGroup[];
40
42
  }
41
43
  export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
42
44
  }
43
45
  type DashKitInnerProps = DashKitGeneralProps & DashKitDefaultProps;
44
46
  export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
45
47
  static defaultProps: DashKitDefaultProps;
46
- static contextType: React.Context<any>;
48
+ static contextType: React.Context<void | import("../../context").DashKitDnDCtxShape>;
47
49
  static registerPlugins(...plugins: Plugin[]): void;
48
50
  static reloadPlugins(...plugins: Plugin[]): void;
49
51
  static setSettings(settings: Settings): void;
@@ -2,7 +2,7 @@ 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 { DashKitDnDContext } from '../../context/DashKitContext';
5
+ import { DashKitDnDContext } from '../../context';
6
6
  import { RegisterManager, UpdateManager, reflowLayout } from '../../utils';
7
7
  import { DashKitDnDWrapper } from '../DashKitDnDWrapper/DashKitDnDWrapper';
8
8
  import DashKitView from '../DashKitView/DashKitView';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { DashKitDnDContext } from '../../context/DashKitContext';
2
+ import { DashKitDnDContext } from '../../context';
3
3
  const defaultImageSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=';
4
4
  export const DashKitDnDWrapper = (props) => {
5
5
  const [dragProps, setDragProps] = React.useState(null);
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { DashKitContext } from '../../context/DashKitContext';
2
+ import { DashKitContext } from '../../context';
3
3
  import { withContext } from '../../hocs/withContext';
4
4
  import { useCalcPropsLayout } from '../../hooks/useCalcLayout';
5
5
  import { cn } from '../../utils/cn';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { FOCUSED_CLASS_NAME } from '../../constants';
4
- import { DashKitContext } from '../../context/DashKitContext';
4
+ import { DashKitContext } from '../../context';
5
5
  import { cn } from '../../utils/cn';
6
6
  import Item from '../Item/Item';
7
7
  import OverlayControls from '../OverlayControls/OverlayControls';
@@ -1,5 +1,5 @@
1
1
  export default class GridLayout extends React.PureComponent<any, any, any> {
2
- static contextType: React.Context<any>;
2
+ static contextType: React.Context<import("../../context").DashKitCtxShape>;
3
3
  constructor(props: any, context: any);
4
4
  pluginsRefs: any[];
5
5
  state: {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { COMPACT_TYPE_HORIZONTAL_NOWRAP, DEFAULT_GROUP, DRAGGABLE_CANCEL_CLASS_NAME, TEMPORARY_ITEM_ID, } from '../../constants';
3
- import { DashKitContext } from '../../context/DashKitContext';
3
+ import { DashKitContext } from '../../context';
4
4
  import { resolveLayoutGroup } from '../../utils';
5
5
  import GridItem from '../GridItem/GridItem';
6
6
  import { Layout } from './ReactGridLayout';
@@ -498,6 +498,7 @@ class GridLayout extends React.PureComponent {
498
498
  offset += items.length;
499
499
  if (group.render) {
500
500
  const groupContext = {
501
+ isMobile: false,
501
502
  config,
502
503
  editMode,
503
504
  items,
@@ -66,7 +66,8 @@ declare const _default: {
66
66
  onItemMountChange: PropTypes.Requireable<(...args: any[]) => any>;
67
67
  forwardedPluginRef: PropTypes.Requireable<any>;
68
68
  };
69
- contextType: React.Context<any>;
69
+ contextType: React.Context<import("../../context").DashKitCtxShape>;
70
70
  };
71
71
  export default _default;
72
72
  import React from 'react';
73
+ import PropTypes from 'prop-types';
@@ -1,23 +1,31 @@
1
- export default class MobileLayout extends React.PureComponent<any, any, any> {
2
- static contextType: React.Context<any>;
3
- constructor(props: any);
4
- constructor(props: any, context: any);
5
- pluginsRefs: any[];
6
- sortedLayoutItems: any;
7
- _memoLayout: any;
8
- _memoForwardedPluginRef: any[];
9
- _memoAdjustWidgetLayout: any[];
10
- state: {
11
- activeTabId: null;
12
- indexesOfItemsWithActiveAutoheight: {};
13
- };
14
- componentDidUpdate(prevProps: any, prevState: any): void;
15
- getSortedLayoutItems(): any;
16
- getMemoForwardRefCallback: (refIndex: any) => any;
17
- adjustWidgetLayout: (index: any, { needSetDefault }: {
18
- needSetDefault: any;
19
- }) => void;
20
- getMemoAdjustWidgetLayout: (index: any) => any;
1
+ import React from 'react';
2
+ import { DashKitContext } from '../../context';
3
+ import { getSortedConfigItems } from './helpers';
4
+ import './MobileLayout.css';
5
+ type MobileLayoutProps = {};
6
+ type MobileLayoutState = {
7
+ itemsWithActiveAutoheight: Record<string, boolean>;
8
+ };
9
+ type PlugibRefObject = React.RefObject<any>;
10
+ export default class MobileLayout extends React.PureComponent<MobileLayoutProps, MobileLayoutState> {
11
+ static contextType: React.Context<import("../../context").DashKitCtxShape>;
12
+ context: React.ContextType<typeof DashKitContext>;
13
+ pluginsRefs: PlugibRefObject[];
14
+ sortedLayoutItems: Record<string, ReturnType<typeof getSortedConfigItems>> | null;
15
+ _memoLayout: import("../..").ConfigLayout[];
16
+ _memoForwardedPluginRef: Array<(refObject: PlugibRefObject) => void>;
17
+ _memoAdjustWidgetLayout: Record<string, (props: {
18
+ needSetDefault: boolean;
19
+ }) => void>;
20
+ state: MobileLayoutState;
21
21
  render(): JSX.Element;
22
+ getSortedLayoutItems(): Record<string, (import("../..").ConfigItem & import("../..").ConfigLayout)[]>;
23
+ getMemoForwardRefCallback(refIndex: number): (refObject: PlugibRefObject) => void;
24
+ adjustWidgetLayout(id: string, { needSetDefault }: {
25
+ needSetDefault: boolean;
26
+ }): void;
27
+ getMemoAdjustWidgetLayout(id: string): (props: {
28
+ needSetDefault: boolean;
29
+ }) => void;
22
30
  }
23
- import React from 'react';
31
+ export {};
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
- import { DashKitContext } from '../../context/DashKitContext';
2
+ import groupBy from 'lodash/groupBy';
3
+ import { DEFAULT_GROUP } from '../../constants';
4
+ import { DashKitContext } from '../../context';
3
5
  import { cn } from '../../utils/cn';
4
6
  import Item from '../Item/Item';
5
7
  import { getSortedConfigItems } from './helpers';
@@ -9,47 +11,40 @@ class MobileLayout extends React.PureComponent {
9
11
  constructor() {
10
12
  super(...arguments);
11
13
  this.pluginsRefs = [];
14
+ this.sortedLayoutItems = null;
12
15
  this._memoLayout = this.context.layout;
13
16
  this._memoForwardedPluginRef = [];
14
- this._memoAdjustWidgetLayout = [];
17
+ this._memoAdjustWidgetLayout = {};
15
18
  this.state = {
16
- activeTabId: null,
17
- indexesOfItemsWithActiveAutoheight: {},
18
- };
19
- this.getMemoForwardRefCallback = (refIndex) => {
20
- if (!this._memoForwardedPluginRef[refIndex]) {
21
- this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
22
- this.pluginsRefs[refIndex] = pluginRef;
23
- };
24
- }
25
- return this._memoForwardedPluginRef[refIndex];
26
- };
27
- this.adjustWidgetLayout = (index, { needSetDefault }) => {
28
- if (needSetDefault) {
29
- const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight);
30
- delete indexesOfItemsWithActiveAutoheight[index];
31
- this.setState({ indexesOfItemsWithActiveAutoheight });
32
- }
33
- else {
34
- this.setState({
35
- indexesOfItemsWithActiveAutoheight: Object.assign({}, this.state.indexesOfItemsWithActiveAutoheight, { [index]: true }),
36
- });
37
- }
38
- };
39
- this.getMemoAdjustWidgetLayout = (index) => {
40
- if (!this._memoAdjustWidgetLayout[index]) {
41
- this._memoAdjustWidgetLayout[index] = this.adjustWidgetLayout.bind(this, index);
42
- }
43
- return this._memoAdjustWidgetLayout[index];
19
+ itemsWithActiveAutoheight: {},
44
20
  };
45
21
  }
46
- componentDidUpdate(prevProps, prevState) {
47
- if (prevState.activeTabId !== this.context.config.id) {
48
- this.setState({
49
- activeTabId: this.context.config.id,
50
- indexesOfItemsWithActiveAutoheight: {},
22
+ render() {
23
+ const { config, layout, groups = [{ id: DEFAULT_GROUP }], context, editMode } = this.context;
24
+ this.pluginsRefs.length = config.items.length;
25
+ const sortedItems = this.getSortedLayoutItems();
26
+ let indexOffset = 0;
27
+ return (React.createElement("div", { className: b() }, groups.map((group) => {
28
+ const groupId = group.id || DEFAULT_GROUP;
29
+ const items = sortedItems[groupId] || [];
30
+ const children = items.map((item, index) => {
31
+ const isItemWithActiveAutoheight = item.id in this.state.itemsWithActiveAutoheight;
32
+ return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
33
+ React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(item.id), forwardedPluginRef: this.getMemoForwardRefCallback(indexOffset + index), onItemMountChange: this.context.onItemMountChange, onItemRender: this.context.onItemRender })));
51
34
  });
52
- }
35
+ indexOffset += items.length;
36
+ if (group.render) {
37
+ return group.render(groupId, children, {
38
+ isMobile: true,
39
+ config,
40
+ context,
41
+ editMode,
42
+ items,
43
+ layout,
44
+ });
45
+ }
46
+ return children;
47
+ })));
53
48
  }
54
49
  getSortedLayoutItems() {
55
50
  if (this.sortedLayoutItems && this.context.layout === this._memoLayout) {
@@ -57,18 +52,36 @@ class MobileLayout extends React.PureComponent {
57
52
  }
58
53
  this._memoLayout = this.context.layout;
59
54
  const hasOrderId = Boolean(this.context.config.items.find((item) => item.orderId));
60
- this.sortedLayoutItems = getSortedConfigItems(this.context.config, hasOrderId);
55
+ this.sortedLayoutItems = groupBy(getSortedConfigItems(this.context.config, hasOrderId), (item) => item.parent || DEFAULT_GROUP);
61
56
  return this.sortedLayoutItems;
62
57
  }
63
- render() {
64
- const { config, layout } = this.context;
65
- this.pluginsRefs.length = config.items.length;
66
- const sortedItems = this.getSortedLayoutItems();
67
- return (React.createElement("div", { className: b() }, sortedItems.map((item, index) => {
68
- const isItemWithActiveAutoheight = index in this.state.indexesOfItemsWithActiveAutoheight;
69
- return (React.createElement("div", { className: b('item', { autoheight: isItemWithActiveAutoheight }), key: item.id },
70
- React.createElement(Item, { id: item.id, item: item, layout: layout, shouldItemUpdate: false, adjustWidgetLayout: this.getMemoAdjustWidgetLayout(index), forwardedPluginRef: this.getMemoForwardRefCallback(index), onMountChange: this.onMountChange, onItemMountChange: this.context.onItemMountChange, onItemRender: this.context.onItemRender })));
71
- })));
58
+ getMemoForwardRefCallback(refIndex) {
59
+ if (!this._memoForwardedPluginRef[refIndex]) {
60
+ this._memoForwardedPluginRef[refIndex] = (pluginRef) => {
61
+ this.pluginsRefs[refIndex] = pluginRef;
62
+ };
63
+ }
64
+ return this._memoForwardedPluginRef[refIndex];
65
+ }
66
+ adjustWidgetLayout(id, { needSetDefault }) {
67
+ if (needSetDefault) {
68
+ const indexesOfItemsWithActiveAutoheight = Object.assign({}, this.state.itemsWithActiveAutoheight);
69
+ delete indexesOfItemsWithActiveAutoheight[id];
70
+ this.setState({ itemsWithActiveAutoheight: indexesOfItemsWithActiveAutoheight });
71
+ }
72
+ else {
73
+ this.setState({
74
+ itemsWithActiveAutoheight: Object.assign({}, this.state.itemsWithActiveAutoheight, {
75
+ [id]: true,
76
+ }),
77
+ });
78
+ }
79
+ }
80
+ getMemoAdjustWidgetLayout(id) {
81
+ if (!this._memoAdjustWidgetLayout[id]) {
82
+ this._memoAdjustWidgetLayout[id] = this.adjustWidgetLayout.bind(this, id);
83
+ }
84
+ return this._memoAdjustWidgetLayout[id];
72
85
  }
73
86
  }
74
87
  MobileLayout.contextType = DashKitContext;