@atlaskit/editor-plugin-block-controls 1.5.17 → 1.5.19

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.
@@ -1,9 +1,9 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  /** @jsx jsx */
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
4
-
5
4
  // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
5
  import { css, jsx } from '@emotion/react';
6
+ import { bind } from 'bind-event-listener';
7
7
  import { injectIntl } from 'react-intl-next';
8
8
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
9
9
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
@@ -40,11 +40,15 @@ var dragHandleButtonStyles = css({
40
40
  cursor: 'grab',
41
41
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
42
42
  zIndex: DRAG_HANDLE_ZINDEX,
43
+ outline: 'none',
43
44
  '&:hover': {
44
45
  backgroundColor: "var(--ds-background-neutral-subtle-hovered, #091E420F)"
45
46
  },
46
47
  '&:active': {
47
48
  backgroundColor: "var(--ds-background-neutral-subtle-pressed, #091E4224)"
49
+ },
50
+ '&:focus': {
51
+ outline: "2px solid ".concat("var(--ds-border-focused, #388BFF)")
48
52
  }
49
53
  });
50
54
  var selectedStyles = css({
@@ -57,7 +61,8 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
57
61
  getPos = _ref.getPos,
58
62
  anchorName = _ref.anchorName,
59
63
  nodeType = _ref.nodeType,
60
- formatMessage = _ref.intl.formatMessage;
64
+ formatMessage = _ref.intl.formatMessage,
65
+ handleOptions = _ref.handleOptions;
61
66
  var start = getPos();
62
67
  var buttonRef = useRef(null);
63
68
  var _useState = useState(768),
@@ -160,6 +165,34 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
160
165
  return tr;
161
166
  });
162
167
  }, [start, api]);
168
+ var handleKeyDown = useCallback(function (e) {
169
+ if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
170
+ // allow user to use spacebar to select the node
171
+ if (!e.repeat && e.key === ' ') {
172
+ var _api$core4;
173
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref5) {
174
+ var tr = _ref5.tr;
175
+ if (start === undefined) {
176
+ return tr;
177
+ }
178
+ var node = tr.doc.nodeAt(start);
179
+ if (!node) {
180
+ return tr;
181
+ }
182
+ var $startPos = tr.doc.resolve(start + node.nodeSize);
183
+ var selection = new TextSelection($startPos);
184
+ tr.setSelection(selection);
185
+ tr.setMeta(key, {
186
+ pos: start
187
+ });
188
+ return tr;
189
+ });
190
+ } else {
191
+ // return focus to editor to resume editing from caret positon
192
+ view.focus();
193
+ }
194
+ }
195
+ }, [start, api, view]);
163
196
  useEffect(function () {
164
197
  var element = buttonRef.current;
165
198
  if (!element) {
@@ -173,11 +206,11 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
173
206
  start: start
174
207
  };
175
208
  },
176
- onGenerateDragPreview: function onGenerateDragPreview(_ref5) {
177
- var nativeSetDragImage = _ref5.nativeSetDragImage;
209
+ onGenerateDragPreview: function onGenerateDragPreview(_ref6) {
210
+ var nativeSetDragImage = _ref6.nativeSetDragImage;
178
211
  setCustomNativeDragPreview({
179
- render: function render(_ref6) {
180
- var container = _ref6.container;
212
+ render: function render(_ref7) {
213
+ var container = _ref7.container;
181
214
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
182
215
  if (!dom) {
183
216
  return;
@@ -188,13 +221,13 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
188
221
  });
189
222
  },
190
223
  onDragStart: function onDragStart() {
191
- var _api$core4;
224
+ var _api$core5;
192
225
  if (start === undefined) {
193
226
  return;
194
227
  }
195
- api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref7) {
228
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref8) {
196
229
  var _api$blockControls, _api$analytics2;
197
- var tr = _ref7.tr;
230
+ var tr = _ref8.tr;
198
231
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
199
232
  tr: tr
200
233
  });
@@ -218,7 +251,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
218
251
  });
219
252
  }, [anchorName, api, nodeType, view, start]);
220
253
  var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
221
- var positionStyles = useMemo(function () {
254
+ var calculatePosition = useCallback(function () {
222
255
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
223
256
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
224
257
  var hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
@@ -240,18 +273,71 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
240
273
  }
241
274
  if (supportsAnchor) {
242
275
  return fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? {
243
- left: hasResizer || isExtension || isEmbedCard ? "calc(anchor(".concat(anchorName, " start) + ").concat(getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
276
+ left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(anchor(".concat(anchorName, " start) + ").concat(getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
244
277
  top: fg('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat(topPositionAdjustment(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
245
278
  } : {
246
279
  left: hasResizer || isExtension || isBlockCard || isEmbedCard ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
247
280
  top: fg('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat(topPositionAdjustment(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
248
281
  };
249
282
  }
250
- return {
283
+ return fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? {
284
+ left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat(getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
285
+ top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
286
+ } : {
251
287
  left: getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
252
288
  top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
253
289
  };
254
290
  }, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
291
+ var _useState5 = useState({
292
+ display: 'none'
293
+ }),
294
+ _useState6 = _slicedToArray(_useState5, 2),
295
+ newPositionStyles = _useState6[0],
296
+ setNewPositionStyles = _useState6[1];
297
+ useEffect(function () {
298
+ if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
299
+ return;
300
+ }
301
+ var cleanUpTransitionListener;
302
+ if (nodeType === 'extension' || nodeType === 'embedCard') {
303
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
304
+ if (!dom) {
305
+ return;
306
+ }
307
+ cleanUpTransitionListener = bind(dom, {
308
+ type: 'transitionend',
309
+ listener: function listener() {
310
+ setNewPositionStyles(calculatePosition());
311
+ }
312
+ });
313
+ }
314
+ var calcPos = requestAnimationFrame(function () {
315
+ setNewPositionStyles(calculatePosition());
316
+ });
317
+ return function () {
318
+ var _cleanUpTransitionLis;
319
+ cancelAnimationFrame(calcPos);
320
+ (_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 || _cleanUpTransitionLis();
321
+ };
322
+ }, [calculatePosition, view.dom, anchorName, nodeType]);
323
+ var positionStyles = useMemo(function () {
324
+ if (fg('platform_editor_element_drag_and_drop_ed_23896')) {
325
+ return newPositionStyles;
326
+ }
327
+ return calculatePosition();
328
+ }, [calculatePosition, newPositionStyles]);
329
+ useEffect(function () {
330
+ if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && fg('platform_editor_element_drag_and_drop_ed_23873')) {
331
+ var id = requestAnimationFrame(function () {
332
+ var _buttonRef$current;
333
+ (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 || _buttonRef$current.focus();
334
+ });
335
+ return function () {
336
+ cancelAnimationFrame(id);
337
+ view.focus();
338
+ };
339
+ }
340
+ }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
255
341
  var helpDescriptors = [{
256
342
  description: formatMessage(blockControlsMessages.dragToMove)
257
343
  }, {
@@ -268,9 +354,10 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
268
354
  ref: buttonRef
269
355
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
270
356
  ,
271
- style: positionStyles,
357
+ style: fg('platform_editor_element_drag_and_drop_ed_23896') ? newPositionStyles : positionStyles,
272
358
  onClick: handleOnClick,
273
359
  onMouseDown: fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? handleMouseDownWrapperRemoved : handleMouseDown,
360
+ onKeyDown: handleKeyDown,
274
361
  "data-testid": "block-ctrl-drag-handle"
275
362
  }, jsx(DragHandlerIcon, {
276
363
  label: "",
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockControlsPlugin } from '../types';
3
+ export declare const showDragHandleAtSelection: (api?: ExtractInjectionAPI<BlockControlsPlugin>) => Command;
@@ -1,2 +1,2 @@
1
1
  export { blockControlsPlugin } from './plugin';
2
- export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
2
+ export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState, HandleOptions, } from './types';
@@ -2,7 +2,7 @@ import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
- import type { BlockControlsPlugin } from '../types';
5
+ import type { BlockControlsPlugin, HandleOptions } from '../types';
6
6
  export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
7
7
  decs: Decoration[];
8
8
  decorationState: {
@@ -18,4 +18,4 @@ export declare const nodeDecorations: (newState: EditorState) => Decoration[];
18
18
  * And show the drag handle
19
19
  */
20
20
  export declare const mouseMoveWrapperDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
21
- export declare const dragHandleDecoration: (pos: number, anchorName: string, nodeType: string, api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape) => Decoration;
21
+ export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -0,0 +1,3 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockControlsPlugin } from '../types';
3
+ export declare const boundKeydownHandler: (api?: ExtractInjectionAPI<BlockControlsPlugin>) => (view: import("prosemirror-view").EditorView, event: KeyboardEvent) => boolean;
@@ -35,6 +35,9 @@ export type BlockControlsSharedState = {
35
35
  isDragging: boolean;
36
36
  isPMDragging: boolean;
37
37
  } | undefined;
38
+ export type HandleOptions = {
39
+ isFocused: boolean;
40
+ } | undefined;
38
41
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
39
42
  dependencies: [
40
43
  OptionalPlugin<EditorDisabledPlugin>,
@@ -45,7 +48,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
45
48
  sharedState: BlockControlsSharedState;
46
49
  commands: {
47
50
  moveNode: (start: number, to: number) => EditorCommand;
48
- showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
51
+ showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
49
52
  setNodeDragged: (posNumber: number, anchorName: string, nodeType: string) => EditorCommand;
50
53
  };
51
54
  }>;
@@ -2,13 +2,14 @@
2
2
  import { type WrappedComponentProps } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { BlockControlsPlugin } from '../types';
5
+ import type { BlockControlsPlugin, HandleOptions } from '../types';
6
6
  export declare const DragHandle: import("react").FC<import("react-intl-next").WithIntlProps<{
7
7
  view: EditorView;
8
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
9
  getPos: () => number | undefined;
10
10
  anchorName: string;
11
11
  nodeType: string;
12
+ handleOptions?: HandleOptions;
12
13
  } & WrappedComponentProps>> & {
13
14
  WrappedComponent: import("react").ComponentType<{
14
15
  view: EditorView;
@@ -16,5 +17,6 @@ export declare const DragHandle: import("react").FC<import("react-intl-next").Wi
16
17
  getPos: () => number | undefined;
17
18
  anchorName: string;
18
19
  nodeType: string;
20
+ handleOptions?: HandleOptions;
19
21
  } & WrappedComponentProps>;
20
22
  };
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockControlsPlugin } from '../types';
3
+ export declare const showDragHandleAtSelection: (api?: ExtractInjectionAPI<BlockControlsPlugin>) => Command;
@@ -1,2 +1,2 @@
1
1
  export { blockControlsPlugin } from './plugin';
2
- export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState } from './types';
2
+ export type { BlockControlsPlugin, DecorationState, BlockControlsSharedState, HandleOptions, } from './types';
@@ -2,7 +2,7 @@ import { type IntlShape } from 'react-intl-next';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
- import type { BlockControlsPlugin } from '../types';
5
+ import type { BlockControlsPlugin, HandleOptions } from '../types';
6
6
  export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
7
7
  decs: Decoration[];
8
8
  decorationState: {
@@ -18,4 +18,4 @@ export declare const nodeDecorations: (newState: EditorState) => Decoration[];
18
18
  * And show the drag handle
19
19
  */
20
20
  export declare const mouseMoveWrapperDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
21
- export declare const dragHandleDecoration: (pos: number, anchorName: string, nodeType: string, api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape) => Decoration;
21
+ export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -0,0 +1,3 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { BlockControlsPlugin } from '../types';
3
+ export declare const boundKeydownHandler: (api?: ExtractInjectionAPI<BlockControlsPlugin>) => (view: import("prosemirror-view").EditorView, event: KeyboardEvent) => boolean;
@@ -35,6 +35,9 @@ export type BlockControlsSharedState = {
35
35
  isDragging: boolean;
36
36
  isPMDragging: boolean;
37
37
  } | undefined;
38
+ export type HandleOptions = {
39
+ isFocused: boolean;
40
+ } | undefined;
38
41
  export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
39
42
  dependencies: [
40
43
  OptionalPlugin<EditorDisabledPlugin>,
@@ -45,7 +48,7 @@ export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
45
48
  sharedState: BlockControlsSharedState;
46
49
  commands: {
47
50
  moveNode: (start: number, to: number) => EditorCommand;
48
- showDragHandleAt: (pos: number, anchorName: string, nodeType: string) => EditorCommand;
51
+ showDragHandleAt: (pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => EditorCommand;
49
52
  setNodeDragged: (posNumber: number, anchorName: string, nodeType: string) => EditorCommand;
50
53
  };
51
54
  }>;
@@ -2,13 +2,14 @@
2
2
  import { type WrappedComponentProps } from 'react-intl-next';
3
3
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
4
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
- import type { BlockControlsPlugin } from '../types';
5
+ import type { BlockControlsPlugin, HandleOptions } from '../types';
6
6
  export declare const DragHandle: import("react").FC<import("react-intl-next").WithIntlProps<{
7
7
  view: EditorView;
8
8
  api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
9
  getPos: () => number | undefined;
10
10
  anchorName: string;
11
11
  nodeType: string;
12
+ handleOptions?: HandleOptions;
12
13
  } & WrappedComponentProps>> & {
13
14
  WrappedComponent: import("react").ComponentType<{
14
15
  view: EditorView;
@@ -16,5 +17,6 @@ export declare const DragHandle: import("react").FC<import("react-intl-next").Wi
16
17
  getPos: () => number | undefined;
17
18
  anchorName: string;
18
19
  nodeType: string;
20
+ handleOptions?: HandleOptions;
19
21
  } & WrappedComponentProps>;
20
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "1.5.17",
3
+ "version": "1.5.19",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@atlaskit/adf-schema": "^39.0.3",
35
- "@atlaskit/editor-common": "^85.0.0",
35
+ "@atlaskit/editor-common": "^85.2.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^1.4.0",
37
37
  "@atlaskit/editor-plugin-editor-disabled": "^1.1.5",
38
38
  "@atlaskit/editor-plugin-feature-flags": "^1.1.0",
@@ -113,6 +113,9 @@
113
113
  "platform.editor.elements.drag-and-drop-ed-23892": {
114
114
  "type": "boolean"
115
115
  },
116
+ "platform_editor_elements_drag_and_drop_ed_24000": {
117
+ "type": "boolean"
118
+ },
116
119
  "platform.editor.elements.drag-and-drop-ed-23816": {
117
120
  "type": "boolean"
118
121
  },
@@ -136,6 +139,12 @@
136
139
  },
137
140
  "platform_editor_elements_drag_and_drop_ed_23394": {
138
141
  "type": "boolean"
142
+ },
143
+ "platform_editor_element_drag_and_drop_ed_24049": {
144
+ "type": "boolean"
145
+ },
146
+ "platform_editor_element_drag_and_drop_ed_23896": {
147
+ "type": "boolean"
139
148
  }
140
149
  }
141
150
  }