@atlaskit/editor-plugin-block-controls 1.4.11 → 1.4.12

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,13 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.4.12
4
+
5
+ ### Patch Changes
6
+
7
+ - [#108853](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108853)
8
+ [`390f442689fd6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/390f442689fd6) -
9
+ Fix position of drag handle for extension/ bodiedExtension nodes in wide or fullWidth layout
10
+
3
11
  ## 1.4.11
4
12
 
5
13
  ### Patch Changes
@@ -8,6 +8,7 @@ exports.DragHandle = 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");
11
12
  var _dragHandler = _interopRequireDefault(require("@atlaskit/icon/glyph/drag-handler"));
12
13
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
13
14
  var _setCustomNativeDragPreview = require("@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview");
@@ -57,6 +58,8 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
57
58
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
58
59
  dragHandleSelected = _useState2[0],
59
60
  setDragHandleSelected = _useState2[1];
61
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['featureFlags']),
62
+ featureFlagsState = _useSharedPluginState.featureFlagsState;
60
63
  var handleClick = (0, _react.useCallback)(function () {
61
64
  var _api$core, _api$core2;
62
65
  setDragHandleSelected(!dragHandleSelected);
@@ -113,24 +116,27 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
113
116
  }
114
117
  });
115
118
  }, [api, start, view, anchorName, nodeType]);
119
+ var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
116
120
  var positionStyles = (0, _react.useMemo)(function () {
117
121
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
118
122
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
123
+ if (!dom) {
124
+ return;
125
+ }
126
+ var hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
127
+ var isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
128
+ var innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
119
129
  if (supportsAnchor) {
120
- var hasResizer = (anchorName.includes('table') || anchorName.includes('mediaSingle')) && dom;
121
130
  return {
122
- left: hasResizer ? (0, _dragHandlePositions.getLeftPosition)(dom, nodeType) : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
131
+ left: hasResizer || isExtension ? (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
123
132
  top: anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(_consts.DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
124
133
  };
125
134
  }
126
- if (!dom) {
127
- return;
128
- }
129
135
  return {
130
- left: (0, _dragHandlePositions.getLeftPosition)(dom, nodeType),
136
+ left: (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates),
131
137
  top: (0, _dragHandlePositions.getTopPosition)(dom)
132
138
  };
133
- }, [anchorName, view, nodeType]);
139
+ }, [anchorName, view, nodeType, macroInteractionUpdates]);
134
140
  return (0, _react2.jsx)("button", {
135
141
  type: "button",
136
142
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
@@ -13,11 +13,14 @@ var getTopPosition = exports.getTopPosition = function getTopPosition(dom) {
13
13
  return "".concat(dom.offsetTop, "px");
14
14
  }
15
15
  };
16
- var getLeftPosition = exports.getLeftPosition = function getLeftPosition(dom, type) {
17
- var resizer = ['table', 'mediaSingle'].includes(type) ? dom.querySelector('.resizer-item') : null;
18
- var left = "".concat(dom.offsetLeft - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
19
- if (resizer) {
20
- left = getComputedStyle(resizer).transform === 'none' ? "".concat(resizer.offsetLeft - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px") : "".concat(resizer.offsetLeft - resizer.offsetWidth / 2 - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
16
+ var getLeftPosition = exports.getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates) {
17
+ if (!innerContainer) {
18
+ return "".concat(dom.offsetLeft - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
21
19
  }
22
- return left;
20
+
21
+ // There is a showMacroInteractionDesignUpdates prop in extension node wrapper that can add a relative span under the top level div
22
+ // We need to adjust the left offset position of the drag handle to account for the relative span
23
+ var relativeSpan = macroInteractionUpdates ? dom.querySelector('span.relative') : null;
24
+ var leftAdjustment = relativeSpan ? relativeSpan.offsetLeft : 0;
25
+ return getComputedStyle(innerContainer).transform === 'none' ? "".concat(innerContainer.offsetLeft + leftAdjustment - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px") : "".concat(innerContainer.offsetLeft + leftAdjustment - innerContainer.offsetWidth / 2 - (0, _consts.dragHandleGap)(type) - _consts.DRAG_HANDLE_WIDTH, "px");
23
26
  };
@@ -1,6 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { css, jsx } from '@emotion/react';
4
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
5
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
5
6
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
6
7
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
@@ -46,6 +47,9 @@ export const DragHandle = ({
46
47
  const start = getPos();
47
48
  const buttonRef = useRef(null);
48
49
  const [dragHandleSelected, setDragHandleSelected] = useState(false);
50
+ const {
51
+ featureFlagsState
52
+ } = useSharedPluginState(api, ['featureFlags']);
49
53
  const handleClick = useCallback(() => {
50
54
  var _api$core, _api$core2;
51
55
  setDragHandleSelected(!dragHandleSelected);
@@ -106,24 +110,27 @@ export const DragHandle = ({
106
110
  }
107
111
  });
108
112
  }, [api, start, view, anchorName, nodeType]);
113
+ const macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
109
114
  const positionStyles = useMemo(() => {
110
115
  const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
111
116
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
117
+ if (!dom) {
118
+ return;
119
+ }
120
+ const hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
121
+ const isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
122
+ const innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
112
123
  if (supportsAnchor) {
113
- const hasResizer = (anchorName.includes('table') || anchorName.includes('mediaSingle')) && dom;
114
124
  return {
115
- left: hasResizer ? getLeftPosition(dom, nodeType) : `calc(anchor(${anchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType)}px)`,
125
+ left: hasResizer || isExtension ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : `calc(anchor(${anchorName} start) - ${DRAG_HANDLE_WIDTH}px - ${dragHandleGap(nodeType)}px)`,
116
126
  top: anchorName.includes('table') ? `calc(anchor(${anchorName} start) + ${DRAG_HANDLE_HEIGHT}px)` : `anchor(${anchorName} start)`
117
127
  };
118
128
  }
119
- if (!dom) {
120
- return;
121
- }
122
129
  return {
123
- left: getLeftPosition(dom, nodeType),
130
+ left: getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
124
131
  top: getTopPosition(dom)
125
132
  };
126
- }, [anchorName, view, nodeType]);
133
+ }, [anchorName, view, nodeType, macroInteractionUpdates]);
127
134
  return jsx("button", {
128
135
  type: "button",
129
136
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
@@ -7,11 +7,14 @@ export const getTopPosition = dom => {
7
7
  return `${dom.offsetTop}px`;
8
8
  }
9
9
  };
10
- export const getLeftPosition = (dom, type) => {
11
- const resizer = ['table', 'mediaSingle'].includes(type) ? dom.querySelector('.resizer-item') : null;
12
- let left = `${dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px`;
13
- if (resizer) {
14
- left = getComputedStyle(resizer).transform === 'none' ? `${resizer.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px` : `${resizer.offsetLeft - resizer.offsetWidth / 2 - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px`;
10
+ export const getLeftPosition = (dom, type, innerContainer, macroInteractionUpdates) => {
11
+ if (!innerContainer) {
12
+ return `${dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px`;
15
13
  }
16
- return left;
14
+
15
+ // There is a showMacroInteractionDesignUpdates prop in extension node wrapper that can add a relative span under the top level div
16
+ // We need to adjust the left offset position of the drag handle to account for the relative span
17
+ const relativeSpan = macroInteractionUpdates ? dom.querySelector('span.relative') : null;
18
+ const leftAdjustment = relativeSpan ? relativeSpan.offsetLeft : 0;
19
+ return getComputedStyle(innerContainer).transform === 'none' ? `${innerContainer.offsetLeft + leftAdjustment - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px` : `${innerContainer.offsetLeft + leftAdjustment - innerContainer.offsetWidth / 2 - dragHandleGap(type) - DRAG_HANDLE_WIDTH}px`;
17
20
  };
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
4
  import { css, jsx } from '@emotion/react';
5
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
5
6
  import DragHandlerIcon from '@atlaskit/icon/glyph/drag-handler';
6
7
  import { draggable } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
7
8
  import { setCustomNativeDragPreview } from '@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview';
@@ -49,6 +50,8 @@ export var DragHandle = function DragHandle(_ref) {
49
50
  _useState2 = _slicedToArray(_useState, 2),
50
51
  dragHandleSelected = _useState2[0],
51
52
  setDragHandleSelected = _useState2[1];
53
+ var _useSharedPluginState = useSharedPluginState(api, ['featureFlags']),
54
+ featureFlagsState = _useSharedPluginState.featureFlagsState;
52
55
  var handleClick = useCallback(function () {
53
56
  var _api$core, _api$core2;
54
57
  setDragHandleSelected(!dragHandleSelected);
@@ -105,24 +108,27 @@ export var DragHandle = function DragHandle(_ref) {
105
108
  }
106
109
  });
107
110
  }, [api, start, view, anchorName, nodeType]);
111
+ var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
108
112
  var positionStyles = useMemo(function () {
109
113
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
110
114
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
115
+ if (!dom) {
116
+ return;
117
+ }
118
+ var hasResizer = anchorName.includes('table') || anchorName.includes('mediaSingle');
119
+ var isExtension = anchorName.includes('extension') || anchorName.includes('bodiedExtension');
120
+ var innerContainer = hasResizer ? dom.querySelector('.resizer-item') : isExtension ? dom.querySelector('.extension-container[data-layout]') : null;
111
121
  if (supportsAnchor) {
112
- var hasResizer = (anchorName.includes('table') || anchorName.includes('mediaSingle')) && dom;
113
122
  return {
114
- left: hasResizer ? getLeftPosition(dom, nodeType) : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
123
+ left: hasResizer || isExtension ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
115
124
  top: anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
116
125
  };
117
126
  }
118
- if (!dom) {
119
- return;
120
- }
121
127
  return {
122
- left: getLeftPosition(dom, nodeType),
128
+ left: getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
123
129
  top: getTopPosition(dom)
124
130
  };
125
- }, [anchorName, view, nodeType]);
131
+ }, [anchorName, view, nodeType, macroInteractionUpdates]);
126
132
  return jsx("button", {
127
133
  type: "button",
128
134
  css: [dragHandleButtonStyles, dragHandleSelected && selectedStyles],
@@ -7,11 +7,14 @@ export var getTopPosition = function getTopPosition(dom) {
7
7
  return "".concat(dom.offsetTop, "px");
8
8
  }
9
9
  };
10
- export var getLeftPosition = function getLeftPosition(dom, type) {
11
- var resizer = ['table', 'mediaSingle'].includes(type) ? dom.querySelector('.resizer-item') : null;
12
- var left = "".concat(dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px");
13
- if (resizer) {
14
- left = getComputedStyle(resizer).transform === 'none' ? "".concat(resizer.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px") : "".concat(resizer.offsetLeft - resizer.offsetWidth / 2 - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px");
10
+ export var getLeftPosition = function getLeftPosition(dom, type, innerContainer, macroInteractionUpdates) {
11
+ if (!innerContainer) {
12
+ return "".concat(dom.offsetLeft - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px");
15
13
  }
16
- return left;
14
+
15
+ // There is a showMacroInteractionDesignUpdates prop in extension node wrapper that can add a relative span under the top level div
16
+ // We need to adjust the left offset position of the drag handle to account for the relative span
17
+ var relativeSpan = macroInteractionUpdates ? dom.querySelector('span.relative') : null;
18
+ var leftAdjustment = relativeSpan ? relativeSpan.offsetLeft : 0;
19
+ return getComputedStyle(innerContainer).transform === 'none' ? "".concat(innerContainer.offsetLeft + leftAdjustment - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px") : "".concat(innerContainer.offsetLeft + leftAdjustment - innerContainer.offsetWidth / 2 - dragHandleGap(type) - DRAG_HANDLE_WIDTH, "px");
17
20
  };
@@ -1,4 +1,5 @@
1
1
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
2
3
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
3
4
  import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
5
  export interface PluginState {
@@ -15,7 +16,7 @@ export interface PluginState {
15
16
  }
16
17
  export type ReleaseHiddenDecoration = () => boolean | undefined;
17
18
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
18
- dependencies: [OptionalPlugin<WidthPlugin>];
19
+ dependencies: [OptionalPlugin<WidthPlugin>, OptionalPlugin<FeatureFlagsPlugin>];
19
20
  sharedState: {
20
21
  isMenuOpen: boolean;
21
22
  activeNode: {
@@ -1,2 +1,2 @@
1
1
  export declare const getTopPosition: (dom: HTMLElement) => string;
2
- export declare const getLeftPosition: (dom: HTMLElement, type: string) => string;
2
+ export declare const getLeftPosition: (dom: HTMLElement, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
@@ -1,4 +1,5 @@
1
1
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
+ import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
2
3
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
3
4
  import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
5
  export interface PluginState {
@@ -16,7 +17,8 @@ export interface PluginState {
16
17
  export type ReleaseHiddenDecoration = () => boolean | undefined;
17
18
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
18
19
  dependencies: [
19
- OptionalPlugin<WidthPlugin>
20
+ OptionalPlugin<WidthPlugin>,
21
+ OptionalPlugin<FeatureFlagsPlugin>
20
22
  ];
21
23
  sharedState: {
22
24
  isMenuOpen: boolean;
@@ -1,2 +1,2 @@
1
1
  export declare const getTopPosition: (dom: HTMLElement) => string;
2
- export declare const getLeftPosition: (dom: HTMLElement, type: string) => string;
2
+ export declare const getLeftPosition: (dom: HTMLElement, type: string, innerContainer?: HTMLElement | null, macroInteractionUpdates?: boolean) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.4.11",
3
+ "version": "1.4.12",
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,8 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^82.1.0",
34
+ "@atlaskit/editor-common": "^82.2.0",
35
+ "@atlaskit/editor-plugin-feature-flags": "^1.1.0",
35
36
  "@atlaskit/editor-plugin-width": "^1.1.0",
36
37
  "@atlaskit/editor-prosemirror": "4.0.1",
37
38
  "@atlaskit/editor-tables": "^2.7.0",