@atlaskit/editor-plugin-block-controls 1.4.13 → 1.4.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [#110434](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/110434)
8
+ [`fca2ac7c4fb70`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fca2ac7c4fb70) -
9
+ [ux] Show generic drag preview when dragging an embed node
10
+ - Updated dependencies
11
+
12
+ ## 1.4.14
13
+
14
+ ### Patch Changes
15
+
16
+ - [#109040](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/109040)
17
+ [`5c5824e70db23`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5c5824e70db23) -
18
+ ED-23629 Improve performance of mousemoveWrapper hiding on hover
19
+
3
20
  ## 1.4.13
4
21
 
5
22
  ### Patch Changes
@@ -27,10 +27,13 @@ var dragHandleButtonStyles = (0, _react2.css)({
27
27
  flexDirection: 'column',
28
28
  justifyContent: 'center',
29
29
  alignItems: 'center',
30
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
30
31
  height: _consts.DRAG_HANDLE_HEIGHT,
32
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
31
33
  width: _consts.DRAG_HANDLE_WIDTH,
32
34
  border: 'none',
33
35
  background: 'transparent',
36
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
34
37
  borderRadius: _consts.DRAG_HANDLE_BORDER_RADIUS,
35
38
  color: "var(--ds-icon, #44546F)",
36
39
  cursor: 'grab',
@@ -111,7 +114,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
111
114
  if (!dom) {
112
115
  return;
113
116
  }
114
- return (0, _dragPreview.dragPreview)(container, dom);
117
+ return (0, _dragPreview.dragPreview)(container, dom, nodeType);
115
118
  },
116
119
  nativeSetDragImage: nativeSetDragImage
117
120
  });
@@ -159,7 +162,9 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
159
162
  return (0, _react2.jsx)("button", {
160
163
  type: "button",
161
164
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
162
- ref: buttonRef,
165
+ ref: buttonRef
166
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
167
+ ,
163
168
  style: positionStyles,
164
169
  onClick: handleOnClick,
165
170
  onMouseDown: handleMouseDown,
@@ -4,7 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dragPreview = void 0;
7
- var dragPreview = exports.dragPreview = function dragPreview(container, dom) {
7
+ //
8
+ var previewStyle = {
9
+ borderColor: "var(--ds-border-focused, #388BFF)",
10
+ borderStyle: 'solid',
11
+ borderRadius: "var(--ds-border-radius-100, 4px)",
12
+ borderWidth: "var(--ds-border-width-outline, 2px)",
13
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
14
+ };
15
+ var dragPreview = exports.dragPreview = function dragPreview(container, dom, nodeType) {
8
16
  var rect = dom.getBoundingClientRect();
9
17
  container.style.width = "".concat(rect.width, "px");
10
18
  container.style.height = "".concat(rect.height, "px");
@@ -12,15 +20,23 @@ var dragPreview = exports.dragPreview = function dragPreview(container, dom) {
12
20
  var parent = document.createElement('div');
13
21
  // ProseMirror class is required to make sure the cloned dom is styled correctly
14
22
  parent.classList.add('ProseMirror');
15
- parent.style.opacity = '0.3';
23
+ var isEmbedCard = nodeType === 'embedCard';
24
+ if (isEmbedCard) {
25
+ parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
26
+ parent.style.borderRadius = previewStyle.borderRadius;
27
+ parent.style.backgroundColor = previewStyle.backgroundColor;
28
+ parent.style.height = '100%';
29
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
30
+ }
16
31
  var resizer = dom.querySelector('.resizer-item');
17
- var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
32
+ var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
18
33
 
19
34
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
20
35
  clonedDom.style.marginLeft = '0';
21
36
  clonedDom.style.marginTop = '0';
22
37
  clonedDom.style.marginRight = '0';
23
38
  clonedDom.style.marginBottom = '0';
39
+ clonedDom.style.opacity = '0.4';
24
40
  parent.appendChild(clonedDom);
25
41
  container.appendChild(parent);
26
42
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -6,9 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.GlobalStylesWrapper = void 0;
7
7
  var _react = require("@emotion/react");
8
8
  /** @jsx jsx */
9
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
9
10
 
10
11
  var globalStyles = (0, _react.css)({
12
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
11
13
  '.ProseMirror-widget:first-child + *': {
14
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
12
15
  marginTop: '0 !important'
13
16
  }
14
17
  });
@@ -8,7 +8,6 @@ exports.MouseMoveWrapper = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var _react2 = require("@emotion/react");
11
- var _hooks = require("@atlaskit/editor-common/hooks");
12
11
  var _dragHandlePositions = require("../utils/drag-handle-positions");
13
12
  /** @jsx jsx */
14
13
 
@@ -28,39 +27,54 @@ var MouseMoveWrapper = exports.MouseMoveWrapper = function MouseMoveWrapper(_ref
28
27
  anchorName = _ref.anchorName,
29
28
  nodeType = _ref.nodeType,
30
29
  getPos = _ref.getPos;
31
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['blockControls']),
32
- blockControlsState = _useSharedPluginState.blockControlsState;
33
- var activeNode = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.activeNode;
34
- var isDragging = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging;
35
30
  var _useState = (0, _react.useState)(false),
36
31
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
- hideWrapper = _useState2[0],
38
- setHideWrapper = _useState2[1];
39
- var _useState3 = (0, _react.useState)(),
32
+ isDragging = _useState2[0],
33
+ setIsDragging = _useState2[1];
34
+ var _useState3 = (0, _react.useState)(false),
40
35
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
41
- pos = _useState4[0],
42
- setPos = _useState4[1];
36
+ hideWrapper = _useState4[0],
37
+ setHideWrapper = _useState4[1];
38
+ var _useState5 = (0, _react.useState)(),
39
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
40
+ pos = _useState6[0],
41
+ setPos = _useState6[1];
43
42
  var onMouseEnter = (0, _react.useCallback)(function () {
43
+ if (!isDragging) {
44
+ setHideWrapper(true);
45
+ }
44
46
  var pos = getPos();
45
47
  if (pos === undefined) {
46
48
  return;
47
49
  }
48
- if (api && api.blockControls && (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) !== pos && !isDragging) {
50
+ if (api && api.blockControls && !isDragging) {
49
51
  var _api$core;
50
52
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api.blockControls.commands.showDragHandleAt(pos, anchorName, nodeType));
51
53
  }
52
- }, [getPos, api, anchorName, isDragging, activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos, nodeType]);
53
- (0, _react.useLayoutEffect)(function () {
54
- if (!activeNode) {
55
- return;
56
- }
57
- var pos = getPos();
58
- if (activeNode.pos !== pos && !isDragging) {
59
- setHideWrapper(false);
60
- return;
61
- }
62
- setHideWrapper(true);
63
- }, [activeNode, isDragging, getPos]);
54
+ }, [setHideWrapper, isDragging, api, getPos, anchorName, nodeType]);
55
+ (0, _react.useEffect)(function () {
56
+ var _api$blockControls;
57
+ var unbind = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.onChange(function (_ref2) {
58
+ var _nextSharedState$acti;
59
+ var nextSharedState = _ref2.nextSharedState;
60
+ var pos = getPos();
61
+ setIsDragging(Boolean(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging));
62
+ if (!(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.activeNode)) {
63
+ return;
64
+ }
65
+ if ((nextSharedState === null || nextSharedState === void 0 || (_nextSharedState$acti = nextSharedState.activeNode) === null || _nextSharedState$acti === void 0 ? void 0 : _nextSharedState$acti.pos) !== pos && !(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging)) {
66
+ setHideWrapper(false);
67
+ return;
68
+ }
69
+ if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging) {
70
+ setHideWrapper(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging);
71
+ return;
72
+ }
73
+ });
74
+ return function () {
75
+ unbind === null || unbind === void 0 || unbind();
76
+ };
77
+ }, [getPos, api]);
64
78
  (0, _react.useLayoutEffect)(function () {
65
79
  var supportsAnchor = CSS.supports('height', "anchor-size(".concat(anchorName, " height)")) && CSS.supports('top', "anchor(".concat(anchorName, " start)"));
66
80
  if (supportsAnchor) {
@@ -86,7 +100,9 @@ var MouseMoveWrapper = exports.MouseMoveWrapper = function MouseMoveWrapper(_ref
86
100
  }, [view, anchorName]);
87
101
  return (0, _react2.jsx)("div", {
88
102
  onMouseEnter: onMouseEnter,
89
- css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles],
103
+ css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
104
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
105
+ ,
90
106
  style: pos
91
107
  });
92
108
  };
@@ -18,10 +18,13 @@ const dragHandleButtonStyles = css({
18
18
  flexDirection: 'column',
19
19
  justifyContent: 'center',
20
20
  alignItems: 'center',
21
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
21
22
  height: DRAG_HANDLE_HEIGHT,
23
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
22
24
  width: DRAG_HANDLE_WIDTH,
23
25
  border: 'none',
24
26
  background: 'transparent',
27
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
25
28
  borderRadius: DRAG_HANDLE_BORDER_RADIUS,
26
29
  color: "var(--ds-icon, #44546F)",
27
30
  cursor: 'grab',
@@ -105,7 +108,7 @@ export const DragHandle = ({
105
108
  if (!dom) {
106
109
  return;
107
110
  }
108
- return dragPreview(container, dom);
111
+ return dragPreview(container, dom, nodeType);
109
112
  },
110
113
  nativeSetDragImage
111
114
  });
@@ -154,7 +157,9 @@ export const DragHandle = ({
154
157
  return jsx("button", {
155
158
  type: "button",
156
159
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
157
- ref: buttonRef,
160
+ ref: buttonRef
161
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
162
+ ,
158
163
  style: positionStyles,
159
164
  onClick: handleOnClick,
160
165
  onMouseDown: handleMouseDown,
@@ -1,4 +1,12 @@
1
- export const dragPreview = (container, dom) => {
1
+ //
2
+ const previewStyle = {
3
+ borderColor: "var(--ds-border-focused, #388BFF)",
4
+ borderStyle: 'solid',
5
+ borderRadius: "var(--ds-border-radius-100, 4px)",
6
+ borderWidth: "var(--ds-border-width-outline, 2px)",
7
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
8
+ };
9
+ export const dragPreview = (container, dom, nodeType) => {
2
10
  const rect = dom.getBoundingClientRect();
3
11
  container.style.width = `${rect.width}px`;
4
12
  container.style.height = `${rect.height}px`;
@@ -6,15 +14,23 @@ export const dragPreview = (container, dom) => {
6
14
  const parent = document.createElement('div');
7
15
  // ProseMirror class is required to make sure the cloned dom is styled correctly
8
16
  parent.classList.add('ProseMirror');
9
- parent.style.opacity = '0.3';
17
+ const isEmbedCard = nodeType === 'embedCard';
18
+ if (isEmbedCard) {
19
+ parent.style.border = `${previewStyle.borderWidth} ${previewStyle.borderStyle} ${previewStyle.borderColor}`;
20
+ parent.style.borderRadius = previewStyle.borderRadius;
21
+ parent.style.backgroundColor = previewStyle.backgroundColor;
22
+ parent.style.height = '100%';
23
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
24
+ }
10
25
  const resizer = dom.querySelector('.resizer-item');
11
- const clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
26
+ const clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
12
27
 
13
28
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
14
29
  clonedDom.style.marginLeft = '0';
15
30
  clonedDom.style.marginTop = '0';
16
31
  clonedDom.style.marginRight = '0';
17
32
  clonedDom.style.marginBottom = '0';
33
+ clonedDom.style.opacity = '0.4';
18
34
  parent.appendChild(clonedDom);
19
35
  container.appendChild(parent);
20
36
  const scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -1,7 +1,10 @@
1
1
  /** @jsx jsx */
2
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
2
3
  import { css, Global, jsx } from '@emotion/react';
3
4
  const globalStyles = css({
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
4
6
  '.ProseMirror-widget:first-child + *': {
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
5
8
  marginTop: '0 !important'
6
9
  }
7
10
  });
@@ -1,7 +1,6 @@
1
1
  /** @jsx jsx */
2
- import { useCallback, useLayoutEffect, useState } from 'react';
2
+ import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
4
  import { getTopPosition } from '../utils/drag-handle-positions';
6
5
  const basicStyles = css({
7
6
  position: 'absolute',
@@ -20,34 +19,46 @@ export const MouseMoveWrapper = ({
20
19
  nodeType,
21
20
  getPos
22
21
  }) => {
23
- const {
24
- blockControlsState
25
- } = useSharedPluginState(api, ['blockControls']);
26
- const activeNode = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.activeNode;
27
- const isDragging = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging;
22
+ const [isDragging, setIsDragging] = useState(false);
28
23
  const [hideWrapper, setHideWrapper] = useState(false);
29
24
  const [pos, setPos] = useState();
30
25
  const onMouseEnter = useCallback(() => {
26
+ if (!isDragging) {
27
+ setHideWrapper(true);
28
+ }
31
29
  const pos = getPos();
32
30
  if (pos === undefined) {
33
31
  return;
34
32
  }
35
- if (api && api.blockControls && (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) !== pos && !isDragging) {
33
+ if (api && api.blockControls && !isDragging) {
36
34
  var _api$core;
37
35
  api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api.blockControls.commands.showDragHandleAt(pos, anchorName, nodeType));
38
36
  }
39
- }, [getPos, api, anchorName, isDragging, activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos, nodeType]);
40
- useLayoutEffect(() => {
41
- if (!activeNode) {
42
- return;
43
- }
44
- const pos = getPos();
45
- if (activeNode.pos !== pos && !isDragging) {
46
- setHideWrapper(false);
47
- return;
48
- }
49
- setHideWrapper(true);
50
- }, [activeNode, isDragging, getPos]);
37
+ }, [setHideWrapper, isDragging, api, getPos, anchorName, nodeType]);
38
+ useEffect(() => {
39
+ var _api$blockControls;
40
+ const unbind = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.onChange(({
41
+ nextSharedState
42
+ }) => {
43
+ var _nextSharedState$acti;
44
+ const pos = getPos();
45
+ setIsDragging(Boolean(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging));
46
+ if (!(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.activeNode)) {
47
+ return;
48
+ }
49
+ if ((nextSharedState === null || nextSharedState === void 0 ? void 0 : (_nextSharedState$acti = nextSharedState.activeNode) === null || _nextSharedState$acti === void 0 ? void 0 : _nextSharedState$acti.pos) !== pos && !(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging)) {
50
+ setHideWrapper(false);
51
+ return;
52
+ }
53
+ if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging) {
54
+ setHideWrapper(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging);
55
+ return;
56
+ }
57
+ });
58
+ return () => {
59
+ unbind === null || unbind === void 0 ? void 0 : unbind();
60
+ };
61
+ }, [getPos, api]);
51
62
  useLayoutEffect(() => {
52
63
  const supportsAnchor = CSS.supports('height', `anchor-size(${anchorName} height)`) && CSS.supports('top', `anchor(${anchorName} start)`);
53
64
  if (supportsAnchor) {
@@ -71,7 +82,9 @@ export const MouseMoveWrapper = ({
71
82
  }, [view, anchorName]);
72
83
  return jsx("div", {
73
84
  onMouseEnter: onMouseEnter,
74
- css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles],
85
+ css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
86
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
87
+ ,
75
88
  style: pos
76
89
  });
77
90
  };
@@ -19,10 +19,13 @@ var dragHandleButtonStyles = css({
19
19
  flexDirection: 'column',
20
20
  justifyContent: 'center',
21
21
  alignItems: 'center',
22
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
22
23
  height: DRAG_HANDLE_HEIGHT,
24
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
23
25
  width: DRAG_HANDLE_WIDTH,
24
26
  border: 'none',
25
27
  background: 'transparent',
28
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
26
29
  borderRadius: DRAG_HANDLE_BORDER_RADIUS,
27
30
  color: "var(--ds-icon, #44546F)",
28
31
  cursor: 'grab',
@@ -103,7 +106,7 @@ export var DragHandle = function DragHandle(_ref) {
103
106
  if (!dom) {
104
107
  return;
105
108
  }
106
- return dragPreview(container, dom);
109
+ return dragPreview(container, dom, nodeType);
107
110
  },
108
111
  nativeSetDragImage: nativeSetDragImage
109
112
  });
@@ -151,7 +154,9 @@ export var DragHandle = function DragHandle(_ref) {
151
154
  return jsx("button", {
152
155
  type: "button",
153
156
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
154
- ref: buttonRef,
157
+ ref: buttonRef
158
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
159
+ ,
155
160
  style: positionStyles,
156
161
  onClick: handleOnClick,
157
162
  onMouseDown: handleMouseDown,
@@ -1,4 +1,12 @@
1
- export var dragPreview = function dragPreview(container, dom) {
1
+ //
2
+ var previewStyle = {
3
+ borderColor: "var(--ds-border-focused, #388BFF)",
4
+ borderStyle: 'solid',
5
+ borderRadius: "var(--ds-border-radius-100, 4px)",
6
+ borderWidth: "var(--ds-border-width-outline, 2px)",
7
+ backgroundColor: "var(--ds-blanket-selected, #388BFF14)"
8
+ };
9
+ export var dragPreview = function dragPreview(container, dom, nodeType) {
2
10
  var rect = dom.getBoundingClientRect();
3
11
  container.style.width = "".concat(rect.width, "px");
4
12
  container.style.height = "".concat(rect.height, "px");
@@ -6,15 +14,23 @@ export var dragPreview = function dragPreview(container, dom) {
6
14
  var parent = document.createElement('div');
7
15
  // ProseMirror class is required to make sure the cloned dom is styled correctly
8
16
  parent.classList.add('ProseMirror');
9
- parent.style.opacity = '0.3';
17
+ var isEmbedCard = nodeType === 'embedCard';
18
+ if (isEmbedCard) {
19
+ parent.style.border = "".concat(previewStyle.borderWidth, " ").concat(previewStyle.borderStyle, " ").concat(previewStyle.borderColor);
20
+ parent.style.borderRadius = previewStyle.borderRadius;
21
+ parent.style.backgroundColor = previewStyle.backgroundColor;
22
+ parent.style.height = '100%';
23
+ parent.setAttribute('data-testid', 'block-ctrl-generic-drag-preview');
24
+ }
10
25
  var resizer = dom.querySelector('.resizer-item');
11
- var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(true);
26
+ var clonedDom = resizer ? resizer.cloneNode(true) : dom.cloneNode(!isEmbedCard);
12
27
 
13
28
  // Remove any margin from the cloned element to ensure is doesn't position incorrectly
14
29
  clonedDom.style.marginLeft = '0';
15
30
  clonedDom.style.marginTop = '0';
16
31
  clonedDom.style.marginRight = '0';
17
32
  clonedDom.style.marginBottom = '0';
33
+ clonedDom.style.opacity = '0.4';
18
34
  parent.appendChild(clonedDom);
19
35
  container.appendChild(parent);
20
36
  var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -1,7 +1,10 @@
1
1
  /** @jsx jsx */
2
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-global-styles -- Ignored via go/DSP-18766
2
3
  import { css, Global, jsx } from '@emotion/react';
3
4
  var globalStyles = css({
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
4
6
  '.ProseMirror-widget:first-child + *': {
7
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
5
8
  marginTop: '0 !important'
6
9
  }
7
10
  });
@@ -1,8 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
- import { useCallback, useLayoutEffect, useState } from 'react';
3
+ import { useCallback, useEffect, useLayoutEffect, useState } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
5
  import { getTopPosition } from '../utils/drag-handle-positions';
7
6
  var basicStyles = css({
8
7
  position: 'absolute',
@@ -20,39 +19,54 @@ export var MouseMoveWrapper = function MouseMoveWrapper(_ref) {
20
19
  anchorName = _ref.anchorName,
21
20
  nodeType = _ref.nodeType,
22
21
  getPos = _ref.getPos;
23
- var _useSharedPluginState = useSharedPluginState(api, ['blockControls']),
24
- blockControlsState = _useSharedPluginState.blockControlsState;
25
- var activeNode = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.activeNode;
26
- var isDragging = blockControlsState === null || blockControlsState === void 0 ? void 0 : blockControlsState.isDragging;
27
22
  var _useState = useState(false),
28
23
  _useState2 = _slicedToArray(_useState, 2),
29
- hideWrapper = _useState2[0],
30
- setHideWrapper = _useState2[1];
31
- var _useState3 = useState(),
24
+ isDragging = _useState2[0],
25
+ setIsDragging = _useState2[1];
26
+ var _useState3 = useState(false),
32
27
  _useState4 = _slicedToArray(_useState3, 2),
33
- pos = _useState4[0],
34
- setPos = _useState4[1];
28
+ hideWrapper = _useState4[0],
29
+ setHideWrapper = _useState4[1];
30
+ var _useState5 = useState(),
31
+ _useState6 = _slicedToArray(_useState5, 2),
32
+ pos = _useState6[0],
33
+ setPos = _useState6[1];
35
34
  var onMouseEnter = useCallback(function () {
35
+ if (!isDragging) {
36
+ setHideWrapper(true);
37
+ }
36
38
  var pos = getPos();
37
39
  if (pos === undefined) {
38
40
  return;
39
41
  }
40
- if (api && api.blockControls && (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) !== pos && !isDragging) {
42
+ if (api && api.blockControls && !isDragging) {
41
43
  var _api$core;
42
44
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api.blockControls.commands.showDragHandleAt(pos, anchorName, nodeType));
43
45
  }
44
- }, [getPos, api, anchorName, isDragging, activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos, nodeType]);
45
- useLayoutEffect(function () {
46
- if (!activeNode) {
47
- return;
48
- }
49
- var pos = getPos();
50
- if (activeNode.pos !== pos && !isDragging) {
51
- setHideWrapper(false);
52
- return;
53
- }
54
- setHideWrapper(true);
55
- }, [activeNode, isDragging, getPos]);
46
+ }, [setHideWrapper, isDragging, api, getPos, anchorName, nodeType]);
47
+ useEffect(function () {
48
+ var _api$blockControls;
49
+ var unbind = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.onChange(function (_ref2) {
50
+ var _nextSharedState$acti;
51
+ var nextSharedState = _ref2.nextSharedState;
52
+ var pos = getPos();
53
+ setIsDragging(Boolean(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging));
54
+ if (!(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.activeNode)) {
55
+ return;
56
+ }
57
+ if ((nextSharedState === null || nextSharedState === void 0 || (_nextSharedState$acti = nextSharedState.activeNode) === null || _nextSharedState$acti === void 0 ? void 0 : _nextSharedState$acti.pos) !== pos && !(nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging)) {
58
+ setHideWrapper(false);
59
+ return;
60
+ }
61
+ if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging) {
62
+ setHideWrapper(nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging);
63
+ return;
64
+ }
65
+ });
66
+ return function () {
67
+ unbind === null || unbind === void 0 || unbind();
68
+ };
69
+ }, [getPos, api]);
56
70
  useLayoutEffect(function () {
57
71
  var supportsAnchor = CSS.supports('height', "anchor-size(".concat(anchorName, " height)")) && CSS.supports('top', "anchor(".concat(anchorName, " start)"));
58
72
  if (supportsAnchor) {
@@ -78,7 +92,9 @@ export var MouseMoveWrapper = function MouseMoveWrapper(_ref) {
78
92
  }, [view, anchorName]);
79
93
  return jsx("div", {
80
94
  onMouseEnter: onMouseEnter,
81
- css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles],
95
+ css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
96
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
97
+ ,
82
98
  style: pos
83
99
  });
84
100
  };
@@ -1 +1 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement) => () => HTMLElement;
1
+ export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
@@ -1 +1 @@
1
- export declare const dragPreview: (container: HTMLElement, dom: HTMLElement) => () => HTMLElement;
1
+ export declare const dragPreview: (container: HTMLElement, dom: HTMLElement, nodeType: string) => () => HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,7 +31,7 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^82.3.0",
34
+ "@atlaskit/editor-common": "^82.4.0",
35
35
  "@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
36
36
  "@atlaskit/editor-plugin-feature-flags": "^1.1.0",
37
37
  "@atlaskit/editor-plugin-width": "^1.1.0",