@gravity-ui/dashkit 8.0.2 → 8.1.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 (54) hide show
  1. package/README.md +1 -0
  2. package/build/cjs/components/ActionPanel/ActionPanel.d.ts +13 -1
  3. package/build/cjs/components/ActionPanel/ActionPanel.js +25 -6
  4. package/build/cjs/components/DashKit/DashKit.d.ts +10 -3
  5. package/build/cjs/components/DashKit/DashKit.js +2 -0
  6. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +6 -0
  7. package/build/cjs/components/DashKitDnDWrapper/DashKitDnDWrapper.js +24 -0
  8. package/build/cjs/components/GridItem/GridItem.css +7 -0
  9. package/build/cjs/components/GridItem/GridItem.d.ts +2 -2
  10. package/build/cjs/components/GridItem/GridItem.js +61 -3
  11. package/build/cjs/components/GridLayout/GridLayout.d.ts +2 -0
  12. package/build/cjs/components/GridLayout/GridLayout.js +75 -6
  13. package/build/cjs/components/Item/Item.css +1 -1
  14. package/build/cjs/components/index.d.ts +1 -0
  15. package/build/cjs/components/index.js +1 -0
  16. package/build/cjs/constants/common.d.ts +2 -0
  17. package/build/cjs/constants/common.js +3 -1
  18. package/build/cjs/context/DashKitContext.d.ts +1 -0
  19. package/build/cjs/context/DashKitContext.js +3 -1
  20. package/build/cjs/hocs/withContext.js +87 -6
  21. package/build/cjs/plugins/Text/Text.js +3 -0
  22. package/build/cjs/shared/constants/common.d.ts +1 -0
  23. package/build/cjs/shared/constants/common.js +2 -1
  24. package/build/cjs/typings/config.d.ts +3 -0
  25. package/build/cjs/typings/plugin.d.ts +1 -0
  26. package/build/cjs/utils/update-manager.d.ts +2 -2
  27. package/build/cjs/utils/update-manager.js +25 -7
  28. package/build/esm/components/ActionPanel/ActionPanel.d.ts +13 -1
  29. package/build/esm/components/ActionPanel/ActionPanel.js +23 -5
  30. package/build/esm/components/DashKit/DashKit.d.ts +10 -3
  31. package/build/esm/components/DashKit/DashKit.js +2 -0
  32. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.d.ts +6 -0
  33. package/build/esm/components/DashKitDnDWrapper/DashKitDnDWrapper.js +19 -0
  34. package/build/esm/components/GridItem/GridItem.css +7 -0
  35. package/build/esm/components/GridItem/GridItem.d.ts +2 -2
  36. package/build/esm/components/GridItem/GridItem.js +61 -3
  37. package/build/esm/components/GridLayout/GridLayout.d.ts +2 -0
  38. package/build/esm/components/GridLayout/GridLayout.js +76 -7
  39. package/build/esm/components/Item/Item.css +1 -1
  40. package/build/esm/components/index.d.ts +1 -0
  41. package/build/esm/components/index.js +1 -0
  42. package/build/esm/constants/common.d.ts +2 -0
  43. package/build/esm/constants/common.js +2 -0
  44. package/build/esm/context/DashKitContext.d.ts +1 -0
  45. package/build/esm/context/DashKitContext.js +2 -1
  46. package/build/esm/hocs/withContext.js +88 -7
  47. package/build/esm/plugins/Text/Text.js +3 -0
  48. package/build/esm/shared/constants/common.d.ts +1 -0
  49. package/build/esm/shared/constants/common.js +1 -0
  50. package/build/esm/typings/config.d.ts +3 -0
  51. package/build/esm/typings/plugin.d.ts +1 -0
  52. package/build/esm/utils/update-manager.d.ts +2 -2
  53. package/build/esm/utils/update-manager.js +25 -7
  54. package/package.json +1 -1
@@ -8,3 +8,6 @@ export type SetConfigItem = ConfigItem | AddConfigItem;
8
8
  export type SetItemOptions = {
9
9
  excludeIds?: string[];
10
10
  };
11
+ export type SetNewItemOptions = SetItemOptions & {
12
+ updateLayout?: ConfigLayout[];
13
+ };
@@ -36,4 +36,5 @@ export interface PluginDefaultLayout {
36
36
  export interface Plugin<P extends PluginWidgetProps<T> = any, T = StringParams> extends PluginBase {
37
37
  defaultLayout?: PluginDefaultLayout;
38
38
  renderer: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
39
+ placeholderRenderer?: (props: P, forwardedRef: React.RefObject<any>) => React.ReactNode;
39
40
  }
@@ -1,5 +1,5 @@
1
1
  import type { Config, ConfigItem, ItemStateAndParams, ItemStateAndParamsChangeOptions, ItemsStateAndParams } from '../shared';
2
- import type { AddConfigItem, SetItemOptions, WidgetLayout } from '../typings';
2
+ import type { AddConfigItem, SetItemOptions, SetNewItemOptions, WidgetLayout } from '../typings';
3
3
  import { RegisterManagerPluginLayout } from './register-manager';
4
4
  interface RemoveItemArg {
5
5
  id: string;
@@ -19,7 +19,7 @@ export declare class UpdateManager {
19
19
  namespace: string;
20
20
  layout: RegisterManagerPluginLayout;
21
21
  config: Config;
22
- options: SetItemOptions;
22
+ options: SetNewItemOptions;
23
23
  }): Config;
24
24
  static editItem({ item, namespace, config, options, }: {
25
25
  item: ConfigItem;
@@ -216,19 +216,37 @@ function changeGroupParams({ groupItemIds, initiatorId, initiatorItem, itemsStat
216
216
  }
217
217
  class UpdateManager {
218
218
  static addItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, layout, config, options, }) {
219
- const layoutY = Math.max(0, ...config.layout.map(({ h, y }) => h + y));
220
- const saveDefaultLayout = (0, pick_1.default)(layout, ['h', 'w', 'x', 'y']);
221
219
  const salt = config.salt;
222
220
  const newItemData = getNewItemData({ item, config, salt, counter: config.counter, options });
223
221
  let counter = newItemData.counter;
224
222
  const newIdData = (0, get_new_id_1.getNewId)({ config, salt, counter, excludeIds: newItemData.excludeIds });
225
223
  counter = newIdData.counter;
226
224
  const newItem = Object.assign(Object.assign({}, item), { id: newIdData.id, data: newItemData.data, namespace });
227
- return (0, immutability_helper_1.default)(config, {
228
- items: { $push: [newItem] },
229
- layout: { $push: [Object.assign(Object.assign({}, saveDefaultLayout), { y: layoutY, i: newItem.id })] },
230
- counter: { $set: counter },
231
- });
225
+ const saveDefaultLayout = (0, pick_1.default)(layout, ['h', 'w', 'x', 'y']);
226
+ if (options.updateLayout) {
227
+ const byId = options.updateLayout.reduce((memo, t) => {
228
+ memo[t.i] = t;
229
+ return memo;
230
+ }, {});
231
+ const newLayout = [
232
+ ...config.layout.map((t) => (Object.assign(Object.assign({}, t), (byId[t.i] || {})))),
233
+ Object.assign(Object.assign({}, saveDefaultLayout), { i: newItem.id }),
234
+ ];
235
+ return (0, immutability_helper_1.default)(config, {
236
+ items: { $push: [newItem] },
237
+ layout: { $set: newLayout },
238
+ counter: { $set: counter },
239
+ });
240
+ }
241
+ else {
242
+ const layoutY = Math.max(0, ...config.layout.map(({ h, y }) => h + y));
243
+ const newLayoutItem = Object.assign(Object.assign({}, saveDefaultLayout), { y: layoutY, i: newItem.id });
244
+ return (0, immutability_helper_1.default)(config, {
245
+ items: { $push: [newItem] },
246
+ layout: { $push: [newLayoutItem] },
247
+ counter: { $set: counter },
248
+ });
249
+ }
232
250
  }
233
251
  static editItem({ item, namespace = constants_1.DEFAULT_NAMESPACE, config, options, }) {
234
252
  const itemIndex = config.items.findIndex(({ id }) => item.id === id);
@@ -1,4 +1,16 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { ActionPanelProps } from './types';
3
3
  import './ActionPanel.css';
4
+ export type ActionPanelItem = {
5
+ id: string;
6
+ icon: React.ReactNode;
7
+ title: string;
8
+ onClick?: () => void;
9
+ className?: string;
10
+ qa?: string;
11
+ pluginType?: string;
12
+ };
13
+ export declare const ActionPanelItemContainer: ({ item }: {
14
+ item: ActionPanelItem;
15
+ }) => JSX.Element;
4
16
  export declare const ActionPanel: (props: ActionPanelProps) => JSX.Element | null;
@@ -1,18 +1,36 @@
1
1
  import React from 'react';
2
2
  import { CSSTransition } from 'react-transition-group';
3
+ import { DashKitDnDContext } from '../../context/DashKitContext';
3
4
  import { cn } from '../../utils/cn';
4
5
  import './ActionPanel.css';
5
6
  const b = cn('dashkit-action-panel');
7
+ export const ActionPanelItemContainer = ({ item }) => {
8
+ const dragContext = React.useContext(DashKitDnDContext);
9
+ const onDragStart = React.useCallback((e) => {
10
+ dragContext.onDragStart(e, item.pluginType);
11
+ }, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragStart, item.pluginType]);
12
+ const onDragEnd = React.useCallback((e) => {
13
+ dragContext.onDragEnd(e);
14
+ }, [dragContext === null || dragContext === void 0 ? void 0 : dragContext.onDragEnd]);
15
+ let dndProps = {};
16
+ if (item.pluginType) {
17
+ dndProps = {
18
+ draggable: true,
19
+ unselectable: 'on',
20
+ onDragStart,
21
+ onDragEnd,
22
+ };
23
+ }
24
+ return (React.createElement("div", Object.assign({ role: "button", className: b('item', item.className), key: `dk-action-panel-${item.id}`, onClick: item.onClick, "data-qa": item.qa }, dndProps),
25
+ React.createElement("div", { className: b('icon') }, item.icon),
26
+ React.createElement("div", { className: b('title'), title: item.title }, item.title)));
27
+ };
6
28
  export const ActionPanel = (props) => {
7
29
  var _a, _b;
8
30
  const isDisabled = (_a = props.disable) !== null && _a !== void 0 ? _a : false;
9
31
  const isAnimated = (_b = props.toggleAnimation) !== null && _b !== void 0 ? _b : false;
10
32
  const nodeRef = React.useRef(null);
11
- const content = (React.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item) => {
12
- return (React.createElement("div", { role: "button", className: b('item', item.className), key: `dk-action-panel-${item.id}`, onClick: item.onClick, "data-qa": item.qa },
13
- React.createElement("div", { className: b('icon') }, item.icon),
14
- React.createElement("div", { className: b('title'), title: item.title }, item.title)));
15
- })));
33
+ const content = (React.createElement("div", { ref: nodeRef, className: b(null, props.className) }, props.items.map((item, i) => (React.createElement(ActionPanelItemContainer, { key: `item_${i}`, item: item })))));
16
34
  if (isAnimated) {
17
35
  return (React.createElement(CSSTransition, { in: !isDisabled, nodeRef: nodeRef, classNames: b(null), timeout: 300, unmountOnExit: true }, content));
18
36
  }
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import type { Config, ConfigItem, GlobalParams, ItemsStateAndParams } from '../../shared';
3
- import { ContextProps, Plugin, SetConfigItem, SetItemOptions, Settings, SettingsProps } from '../../typings';
2
+ import type { Config, ConfigItem, ConfigLayout, GlobalParams, ItemsStateAndParams } from '../../shared';
3
+ import { ContextProps, Plugin, SetConfigItem, SetNewItemOptions, Settings, SettingsProps } from '../../typings';
4
4
  import GridLayout from '../GridLayout/GridLayout';
5
5
  import { OverlayControlItem } from '../OverlayControls/OverlayControls';
6
6
  interface DashKitGeneralProps {
@@ -15,12 +15,19 @@ interface DashKitDefaultProps {
15
15
  config: Config;
16
16
  itemsStateAndParams: ItemsStateAndParams;
17
17
  }) => void;
18
+ onDrop: (dropProps: {
19
+ commit: () => void;
20
+ pluginType: string;
21
+ itemLayout: ConfigLayout;
22
+ newLayout: ConfigLayout[];
23
+ }) => void;
18
24
  defaultGlobalParams: GlobalParams;
19
25
  globalParams: GlobalParams;
20
26
  itemsStateAndParams: ItemsStateAndParams;
21
27
  settings: SettingsProps;
22
28
  context: ContextProps;
23
29
  noOverlay: boolean;
30
+ focusable?: boolean;
24
31
  }
25
32
  export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {
26
33
  }
@@ -33,7 +40,7 @@ export declare class DashKit extends React.PureComponent<DashKitInnerProps> {
33
40
  item: SetConfigItem;
34
41
  namespace?: string;
35
42
  config: Config;
36
- options?: SetItemOptions;
43
+ options?: SetNewItemOptions;
37
44
  }): Config;
38
45
  static removeItem({ id, config, itemsStateAndParams, }: {
39
46
  id: string;
@@ -54,6 +54,7 @@ export class DashKit extends React.PureComponent {
54
54
  DashKit.defaultProps = {
55
55
  onItemEdit: noop,
56
56
  onChange: noop,
57
+ onDrop: noop,
57
58
  defaultGlobalParams: {},
58
59
  globalParams: {},
59
60
  itemsStateAndParams: {},
@@ -63,4 +64,5 @@ DashKit.defaultProps = {
63
64
  },
64
65
  context: {},
65
66
  noOverlay: false,
67
+ focusable: false,
66
68
  };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type DashKitDnDWrapperProps = {
3
+ children: React.ReactElement;
4
+ };
5
+ export declare const DashKitDnDWrapper: React.FC<DashKitDnDWrapperProps>;
6
+ export {};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { DashKitDnDContext } from '../../context/DashKitContext';
3
+ export const DashKitDnDWrapper = (props) => {
4
+ const [dragPluginType, setDragPluginType] = React.useState(null);
5
+ const onDragStart = React.useCallback((_, type) => {
6
+ setDragPluginType(type);
7
+ }, [setDragPluginType]);
8
+ const onDragEnd = React.useCallback((_) => {
9
+ setDragPluginType(null);
10
+ }, [setDragPluginType]);
11
+ const contextValue = React.useMemo(() => {
12
+ return {
13
+ dragPluginType,
14
+ onDragStart,
15
+ onDragEnd,
16
+ };
17
+ }, [dragPluginType, onDragStart, onDragEnd]);
18
+ return (React.createElement(DashKitDnDContext.Provider, { value: contextValue }, props.children));
19
+ };
@@ -1,6 +1,9 @@
1
1
  .dashkit-grid-item {
2
2
  position: relative;
3
3
  }
4
+ .dashkit-grid-item:focus {
5
+ outline: none;
6
+ }
4
7
  .dashkit-grid-item__overlay {
5
8
  --_-dashkit-overlay-color: var(--dashkit-overlay-color, var(--g-color-base-generic));
6
9
  --_-dashkit-overlay-border-color: var(--dashkit-overlay-border-color, rgba(0, 0, 0, 0.1));
@@ -56,6 +59,10 @@
56
59
  will-change: transform;
57
60
  }
58
61
 
62
+ .react-grid-item.dashkit-grid-item_is-focused {
63
+ z-index: 2;
64
+ }
65
+
59
66
  .react-grid-item.react-grid-placeholder {
60
67
  --_-dashkit-placeholder-color: var(--dashkit-placeholder-color, #fc0);
61
68
  --_-dashkit-placeholder-opacity: var(--dashkit-placeholder-opacity, 0.2);
@@ -1,3 +1,3 @@
1
- declare const _default: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
2
- export default _default;
1
+ export default GridItemForwarderRef;
2
+ declare const GridItemForwarderRef: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
3
3
  import React from 'react';
@@ -6,7 +6,55 @@ import Item from '../Item/Item';
6
6
  import OverlayControls from '../OverlayControls/OverlayControls';
7
7
  import './GridItem.css';
8
8
  const b = cn('dashkit-grid-item');
9
+ class WindowFocusObserver {
10
+ constructor() {
11
+ this.blurHandler = (e) => {
12
+ if (e.target === window) {
13
+ this.isFocused = false;
14
+ }
15
+ };
16
+ this.focusHandler = (e) => {
17
+ if (e.target === window) {
18
+ this.isFocused = true;
19
+ }
20
+ };
21
+ this.subscribers = 0;
22
+ this.isFocused = !document.hidden;
23
+ window.addEventListener('blur', this.blurHandler, true);
24
+ window.addEventListener('focus', this.focusHandler, true);
25
+ }
26
+ // Method to get state after all blur\focus events in document are triggered
27
+ async getFocuseState() {
28
+ return new Promise((resolve) => {
29
+ requestAnimationFrame(() => {
30
+ resolve(this.isFocused);
31
+ });
32
+ });
33
+ }
34
+ }
35
+ const windowFocusObserver = new WindowFocusObserver();
9
36
  class GridItem extends React.PureComponent {
37
+ constructor() {
38
+ super(...arguments);
39
+ this.state = {
40
+ isFocused: false,
41
+ };
42
+ this.onFocusHandler = () => {
43
+ this.setState({ isFocused: true });
44
+ if (this.controller) {
45
+ this.controller.abort();
46
+ }
47
+ };
48
+ this.onBlurHandler = () => {
49
+ this.controller = new AbortController();
50
+ windowFocusObserver.getFocuseState().then((isWindowFocused) => {
51
+ if (!this.controller.signal.aborted && isWindowFocused) {
52
+ this.setState({ isFocused: false });
53
+ }
54
+ this.controller = null;
55
+ });
56
+ };
57
+ }
10
58
  renderOverlay() {
11
59
  const { overlayControls } = this.props;
12
60
  const { editMode } = this.context;
@@ -22,7 +70,7 @@ class GridItem extends React.PureComponent {
22
70
  render() {
23
71
  // из-за бага, что Grid Items unmounts при изменении static, isDraggable, isResaizable
24
72
  // https://github.com/STRML/react-grid-layout/issues/721
25
- const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, withCustomHandle, } = this.props;
73
+ const { style, onMouseDown, onMouseUp, onTouchEnd, onTouchStart, children, className, isDragging, noOverlay, focusable, withCustomHandle, } = this.props;
26
74
  const { editMode } = this.context;
27
75
  const width = Number.parseInt(style.width, 10);
28
76
  const height = Number.parseInt(style.height, 10);
@@ -37,8 +85,15 @@ class GridItem extends React.PureComponent {
37
85
  const { _editActive } = this.props.item.data;
38
86
  return (React.createElement("div", Object.assign({ className: b({
39
87
  'is-dragging': isDragging,
88
+ 'is-focused': this.state.isFocused,
40
89
  'with-custom-handle': withCustomHandle,
41
- }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps),
90
+ }, preparedClassName), "data-qa": "dashkit-grid-item", style: style, ref: this.props.forwardedRef }, reactGridLayoutProps, (focusable
91
+ ? {
92
+ onFocus: this.onFocusHandler,
93
+ onBlur: this.onBlurHandler,
94
+ tabIndex: -1,
95
+ }
96
+ : {})),
42
97
  React.createElement("div", { className: b('item', { editMode: editMode && !_editActive && !noOverlay }) },
43
98
  React.createElement(Item, { id: this.props.id, item: this.props.item, shouldItemUpdate: !isDragging, width: width, height: height, transform: transform, adjustWidgetLayout: this.props.adjustWidgetLayout, layout: this.props.layout, forwardedPluginRef: this.props.forwardedPluginRef })),
44
99
  !noOverlay && this.renderOverlay(),
@@ -59,6 +114,7 @@ GridItem.propTypes = {
59
114
  className: PropTypes.string,
60
115
  style: PropTypes.object,
61
116
  noOverlay: PropTypes.bool,
117
+ focusable: PropTypes.bool,
62
118
  withCustomHandle: PropTypes.bool,
63
119
  onMouseDown: PropTypes.func,
64
120
  onMouseUp: PropTypes.func,
@@ -66,6 +122,8 @@ GridItem.propTypes = {
66
122
  onTouchStart: PropTypes.func,
67
123
  };
68
124
  GridItem.contextType = DashKitContext;
69
- export default React.forwardRef((props, ref) => {
125
+ const GridItemForwarderRef = React.forwardRef((props, ref) => {
70
126
  return React.createElement(GridItem, Object.assign({}, props, { forwardedRef: ref }));
71
127
  });
128
+ GridItemForwarderRef.displayName = 'forwardRef(GridItem)';
129
+ export default GridItemForwarderRef;
@@ -21,6 +21,8 @@ export default class GridLayout extends React.PureComponent<any, any, any> {
21
21
  reloadItems(): void;
22
22
  _onStart: () => void;
23
23
  _onStop: (newLayout: any) => void;
24
+ _onDropDragOver: (e: any) => any;
25
+ _onDrop: (layout: any, item: any, e: any) => false | undefined;
24
26
  render(): JSX.Element;
25
27
  }
26
28
  import React from 'react';
@@ -1,9 +1,47 @@
1
1
  import React from 'react';
2
2
  import ReactGridLayout, { WidthProvider } from 'react-grid-layout';
3
- import { OVERLAY_CONTROLS_CLASS_NAME } from '../../constants';
3
+ import { OVERLAY_CLASS_NAME, OVERLAY_CONTROLS_CLASS_NAME, TEMPORARY_ITEM_ID } from '../../constants';
4
4
  import { DashKitContext } from '../../context/DashKitContext';
5
5
  import GridItem from '../GridItem/GridItem';
6
- const Layout = WidthProvider(ReactGridLayout); // eslint-disable-line new-cap
6
+ class DragOverLayout extends ReactGridLayout {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.dragReset = () => {
10
+ if (this.dragEnterCounter) {
11
+ this.dragEnterCounter = 0;
12
+ this.removeDroppingPlaceholder();
13
+ }
14
+ };
15
+ }
16
+ componentDidMount() {
17
+ super.componentDidMount();
18
+ window.addEventListener('dragend', this.dragReset);
19
+ }
20
+ componentWillUnmount() {
21
+ window.removeEventListener('dragend', this.dragReset);
22
+ }
23
+ processGridItem(child, isDroppingItem) {
24
+ if (isDroppingItem) {
25
+ // Drop item from outside gets 0,0 droppingPosition
26
+ // centering cursor on newly creted grid item
27
+ // And cause grid-layout using it's own GridItem to make it look
28
+ // like overlay adding className
29
+ const gridItem = super.processGridItem(child, isDroppingItem);
30
+ if (!gridItem)
31
+ return null;
32
+ const { props } = gridItem;
33
+ const { containerWidth, cols, w, h, rowHeight, margin, transformScale } = props;
34
+ const leftOffset = (((containerWidth / cols) * w) / 2 || 0) * transformScale;
35
+ const topOffset = ((h * rowHeight + (h - 1) * margin[1]) / 2 || 0) * transformScale;
36
+ return React.cloneElement(gridItem, {
37
+ className: OVERLAY_CLASS_NAME,
38
+ droppingPosition: Object.assign(Object.assign({}, props.droppingPosition), { left: props.droppingPosition.left - leftOffset, top: props.droppingPosition.top - topOffset }),
39
+ });
40
+ }
41
+ return super.processGridItem(child, isDroppingItem);
42
+ }
43
+ }
44
+ const Layout = WidthProvider(DragOverLayout); // eslint-disable-line new-cap
7
45
  class GridLayout extends React.PureComponent {
8
46
  constructor(props, context) {
9
47
  super(props, context);
@@ -29,13 +67,38 @@ class GridLayout extends React.PureComponent {
29
67
  return getItemsMeta(this.pluginsRefs);
30
68
  };
31
69
  this._onStart = () => {
70
+ if (this.temporaryLayout)
71
+ return;
32
72
  this.setState({ isDragging: true });
33
73
  };
34
74
  this._onStop = (newLayout) => {
35
- const { layoutChange } = this.context;
36
- layoutChange(newLayout);
75
+ const { layoutChange, onDrop, temporaryLayout } = this.context;
76
+ if (temporaryLayout) {
77
+ onDrop === null || onDrop === void 0 ? void 0 : onDrop(newLayout, newLayout.find(({ i }) => i === TEMPORARY_ITEM_ID));
78
+ }
79
+ else {
80
+ layoutChange(newLayout);
81
+ }
37
82
  this.setState({ isDragging: false });
38
83
  };
84
+ this._onDropDragOver = (e) => {
85
+ const { editMode, onDropDragOver, temporaryLayout } = this.context;
86
+ if (!editMode) {
87
+ return false;
88
+ }
89
+ const result = onDropDragOver(e);
90
+ if (temporaryLayout) {
91
+ return false;
92
+ }
93
+ return result;
94
+ };
95
+ this._onDrop = (layout, item, e) => {
96
+ const { editMode, temporaryLayout, onDrop } = this.context;
97
+ if (!editMode && temporaryLayout) {
98
+ return false;
99
+ }
100
+ onDrop === null || onDrop === void 0 ? void 0 : onDrop(layout, item, e);
101
+ };
39
102
  this.pluginsRefs = [];
40
103
  this.state = {
41
104
  isDragging: false,
@@ -69,14 +132,20 @@ class GridLayout extends React.PureComponent {
69
132
  }
70
133
  }
71
134
  render() {
72
- const { layout, config, registerManager, editMode, noOverlay, draggableHandleClassName } = this.context;
135
+ const { layout, temporaryLayout, config, registerManager, editMode, noOverlay, focusable, draggableHandleClassName, outerDnDEnable, } = this.context;
73
136
  this.pluginsRefs.length = config.items.length;
74
- return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
137
+ return (React.createElement(Layout, Object.assign({}, registerManager.gridLayout, { layout: temporaryLayout || layout, isDraggable: editMode, isResizable: editMode, onDragStart: this._onStart, onDragStop: this._onStop, onResizeStart: this._onStart, onResizeStop: this._onStop }, (draggableHandleClassName
75
138
  ? { draggableHandle: `.${draggableHandleClassName}` }
139
+ : null), (outerDnDEnable
140
+ ? {
141
+ isDroppable: true,
142
+ onDropDragOver: this._onDropDragOver,
143
+ onDrop: this._onDrop,
144
+ }
76
145
  : null), { draggableCancel: `.${OVERLAY_CONTROLS_CLASS_NAME}` }), config.items.map((item, i) => {
77
146
  return (React.createElement(GridItem, { forwardedPluginRef: (pluginRef) => {
78
147
  this.pluginsRefs[i] = pluginRef;
79
- }, key: item.id, id: item.id, item: item, layout: layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
148
+ }, key: item.id, id: item.id, item: item, layout: temporaryLayout || layout, adjustWidgetLayout: this.adjustWidgetLayout, isDragging: this.state.isDragging, noOverlay: noOverlay, focusable: focusable, withCustomHandle: Boolean(draggableHandleClassName), overlayControls: this.props.overlayControls }));
80
149
  })));
81
150
  }
82
151
  }
@@ -1,4 +1,4 @@
1
- .dashkit-item__renderer {
1
+ .dashkit-item__placeholder, .dashkit-item__renderer {
2
2
  position: absolute;
3
3
  inset: 0;
4
4
  }
@@ -2,3 +2,4 @@ export * from './DashKit';
2
2
  export type { OverlayControlItem, PreparedCopyItemOptions } from './OverlayControls/OverlayControls';
3
3
  export * from './ActionPanel/ActionPanel';
4
4
  export type { ActionPanelItem, ActionPanelProps } from './ActionPanel/types';
5
+ export * from './DashKitDnDWrapper/DashKitDnDWrapper';
@@ -1,2 +1,3 @@
1
1
  export * from './DashKit';
2
2
  export * from './ActionPanel/ActionPanel';
3
+ export * from './DashKitDnDWrapper/DashKitDnDWrapper';
@@ -1,6 +1,8 @@
1
1
  export declare const COPIED_WIDGET_STORE_KEY = "dashCopiedItem";
2
2
  export declare const DEFAULT_NAMESPACE = "default";
3
3
  export declare const OVERLAY_CONTROLS_CLASS_NAME = "dashkit-overlay-controls";
4
+ export declare const OVERLAY_CLASS_NAME = "dashkit-grid-item__overlay";
5
+ export declare const TEMPORARY_ITEM_ID = "__dropping-elem__";
4
6
  export declare const MenuItems: {
5
7
  readonly Copy: "copy";
6
8
  readonly Delete: "delete";
@@ -1,6 +1,8 @@
1
1
  export const COPIED_WIDGET_STORE_KEY = 'dashCopiedItem';
2
2
  export const DEFAULT_NAMESPACE = 'default';
3
3
  export const OVERLAY_CONTROLS_CLASS_NAME = 'dashkit-overlay-controls';
4
+ export const OVERLAY_CLASS_NAME = 'dashkit-grid-item__overlay';
5
+ export const TEMPORARY_ITEM_ID = '__dropping-elem__';
4
6
  export const MenuItems = {
5
7
  Copy: 'copy',
6
8
  Delete: 'delete',
@@ -1,2 +1,3 @@
1
1
  export const DashKitContext: React.Context<any>;
2
+ export const DashKitDnDContext: React.Context<any>;
2
3
  import React from 'react';
@@ -1,3 +1,4 @@
1
1
  import React from 'react';
2
2
  const DashKitContext = React.createContext();
3
- export { DashKitContext };
3
+ const DashKitDnDContext = React.createContext();
4
+ export { DashKitContext, DashKitDnDContext };