@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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 1.5.19
4
+
5
+ ### Patch Changes
6
+
7
+ - [#119849](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/119849)
8
+ [`5178d3ebdd7db`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5178d3ebdd7db) -
9
+ ED-23896 Fix responsiveness of extensions, macros, table alignment
10
+ - Updated dependencies
11
+
12
+ ## 1.5.18
13
+
14
+ ### Patch Changes
15
+
16
+ - [#119419](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/119419)
17
+ [`a8b716b766200`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a8b716b766200) -
18
+ [ux] Add shortcut to show and focus drag handle at selection"
19
+ - [#120359](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/120359)
20
+ [`f18f6e6b7f52c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f18f6e6b7f52c) -
21
+ fix drop targets hiding while dragging
22
+ - [#120426](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/120426)
23
+ [`0aface5be4428`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0aface5be4428) -
24
+ Fix RangeErrors thrown by blocks plugin in prod
25
+ - Updated dependencies
26
+
3
27
  ## 1.5.17
4
28
 
5
29
  ### Patch Changes
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.showDragHandleAtSelection = void 0;
7
+ var showDragHandleAtSelection = exports.showDragHandleAtSelection = function showDragHandleAtSelection(api) {
8
+ return function (state, _, view) {
9
+ var rootPos = state.selection.$from.before(1);
10
+ var dom = view === null || view === void 0 ? void 0 : view.domAtPos(rootPos, 0);
11
+ var rootNode = dom === null || dom === void 0 ? void 0 : dom.node.childNodes[dom === null || dom === void 0 ? void 0 : dom.offset];
12
+ if (rootNode) {
13
+ var anchorName = rootNode.getAttribute('data-drag-handler-anchor-name');
14
+ var nodeType = rootNode.getAttribute('data-drag-handler-node-type');
15
+ if (api && anchorName && nodeType) {
16
+ api.core.actions.execute(api.blockControls.commands.showDragHandleAt(rootPos, anchorName, nodeType, {
17
+ isFocused: true
18
+ }));
19
+ return true;
20
+ }
21
+ }
22
+ return false;
23
+ };
24
+ };
@@ -58,14 +58,15 @@ var blockControlsPlugin = exports.blockControlsPlugin = function blockControlsPl
58
58
  return tr;
59
59
  };
60
60
  },
61
- showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType) {
61
+ showDragHandleAt: function showDragHandleAt(pos, anchorName, nodeType, handleOptions) {
62
62
  return function (_ref4) {
63
63
  var tr = _ref4.tr;
64
64
  tr.setMeta(_main.key, {
65
65
  activeNode: {
66
66
  pos: pos,
67
67
  anchorName: anchorName,
68
- nodeType: nodeType
68
+ nodeType: nodeType,
69
+ handleOptions: handleOptions
69
70
  }
70
71
  });
71
72
  return tr;
@@ -136,13 +136,16 @@ var mouseMoveWrapperDecorations = exports.mouseMoveWrapperDecorations = function
136
136
  });
137
137
  return decs;
138
138
  };
139
- var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(pos, anchorName, nodeType, api, getIntl) {
139
+ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDecoration(api, getIntl, pos, anchorName, nodeType, handleOptions) {
140
140
  return _view.Decoration.widget(pos, function (view, getPos) {
141
141
  var element = document.createElement('div');
142
142
  // Need to set it to inline to avoid text being split when merging two paragraphs
143
143
  element.style.display = 'inline';
144
144
  element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
145
145
  element.setAttribute('data-blocks-drag-handle-container', 'true');
146
+ if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
147
+ unmountDecorations('data-blocks-drag-handle-container');
148
+ }
146
149
  if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
147
150
  // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
148
151
  // due to margins applied to other nodes eg. Headings
@@ -155,14 +158,17 @@ var dragHandleDecoration = exports.dragHandleDecoration = function dragHandleDec
155
158
  api: api,
156
159
  getPos: getPos,
157
160
  anchorName: anchorName,
158
- nodeType: nodeType
161
+ nodeType: nodeType,
162
+ handleOptions: handleOptions
159
163
  })), element);
160
164
  return element;
161
165
  }, {
162
166
  side: -1,
163
167
  id: 'drag-handle',
164
168
  destroy: function destroy(node) {
165
- _reactDom.default.unmountComponentAtNode(node);
169
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
170
+ _reactDom.default.unmountComponentAtNode(node);
171
+ }
166
172
  }
167
173
  });
168
174
  };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.boundKeydownHandler = void 0;
7
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
8
+ var _keymap = require("@atlaskit/editor-prosemirror/keymap");
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _showDragHandle = require("../commands/show-drag-handle");
11
+ function keymapList(api) {
12
+ var keymapList = {};
13
+ if (api && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
14
+ (0, _keymaps.bindKeymapWithCommand)(_keymaps.showElementDragHandle.common, function (state, dispatch, view) {
15
+ (0, _showDragHandle.showDragHandleAtSelection)(api)(state, dispatch, view);
16
+ //we always want to handle this shortcut to prevent default browser special char insert when option + alphabetical key is used
17
+ return true;
18
+ }, keymapList);
19
+ }
20
+ return keymapList;
21
+ }
22
+ var boundKeydownHandler = exports.boundKeydownHandler = function boundKeydownHandler(api) {
23
+ return (0, _keymap.keydownHandler)(keymapList(api));
24
+ };
@@ -19,6 +19,7 @@ var _combine = require("@atlaskit/pragmatic-drag-and-drop/combine");
19
19
  var _adapter = require("@atlaskit/pragmatic-drag-and-drop/element/adapter");
20
20
  var _decorations = require("./decorations");
21
21
  var _handleMouseOver = require("./handle-mouse-over");
22
+ var _keymap = require("./keymap");
22
23
  var key = exports.key = new _state.PluginKey('blockControls');
23
24
  var destroyFn = function destroyFn(api) {
24
25
  var scrollable = document.querySelector('.fabric-editor-popup-scroll-parent');
@@ -92,7 +93,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
92
93
  return initialState;
93
94
  },
94
95
  apply: function apply(tr, currentState, oldState, newState) {
95
- var _meta$activeNode, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
96
+ var _meta$activeNode, _meta$activeNode$hand, _meta$activeNode2, _meta$isDragging, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
96
97
  if (initialState.isDocSizeLimitEnabled === null) {
97
98
  if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-doc-size-limit_7k4vq')) {
98
99
  initialState.isDocSizeLimitEnabled = true;
@@ -125,9 +126,15 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
125
126
  var resizerMeta = tr.getMeta('is-resizer-resizing');
126
127
  isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
127
128
  var nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
129
+ var shouldRemoveHandle = true;
130
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_drag_and_drop_ed_24000')) {
131
+ shouldRemoveHandle = !tr.getMeta('isRemote');
132
+ }
128
133
 
129
- // During resize, remove the drag handle widget
130
- if (isResizerResizing || nodeCountChanged || meta !== null && meta !== void 0 && meta.nodeMoved) {
134
+ // During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
135
+ // Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
136
+ // Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
137
+ if (isResizerResizing || nodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
131
138
  var oldHandle = decorations.find().filter(function (_ref5) {
132
139
  var spec = _ref5.spec;
133
140
  return spec.id === 'drag-handle';
@@ -163,7 +170,15 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
163
170
 
164
171
  // Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
165
172
  if (redrawDecorations && !isResizerResizing && api) {
166
- decorations = _view.DecorationSet.create(newState.doc, []);
173
+ if ((0, _platformFeatureFlags.fg)('platform_editor_elements_drag_and_drop_ed_24000')) {
174
+ var oldNodeDecs = decorations.find().filter(function (_ref8) {
175
+ var spec = _ref8.spec;
176
+ return spec.type !== 'drop-target-decoration';
177
+ });
178
+ decorations = decorations.remove(oldNodeDecs);
179
+ } else {
180
+ decorations = _view.DecorationSet.create(newState.doc, []);
181
+ }
167
182
  var nodeDecs = (0, _decorations.nodeDecorations)(newState);
168
183
  if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
169
184
  decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(nodeDecs));
@@ -180,7 +195,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
180
195
 
181
196
  // When a node type changed to be nested inside another node, the position of the active node is off by 1
182
197
  // This is a workaround to fix the position of the active node when it is nested
183
- if (mappedPosisiton === prevMappedPos + 1) {
198
+
199
+ var shouldUpdateNestedPosition = (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_24049') ? tr.docChanged && !nodeCountChanged : true;
200
+ if (shouldUpdateNestedPosition && mappedPosisiton === prevMappedPos + 1) {
184
201
  mappedPosisiton = prevMappedPos;
185
202
  }
186
203
  var newActiveNode = tr.doc.nodeAt(mappedPosisiton);
@@ -195,31 +212,31 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
195
212
  anchorName: anchorName
196
213
  };
197
214
  }
198
- var draghandleDec = (0, _decorations.dragHandleDecoration)(activeNode.pos, anchorName, nodeType, api, getIntl);
215
+ var draghandleDec = (0, _decorations.dragHandleDecoration)(api, getIntl, activeNode.pos, anchorName, nodeType);
199
216
  decorations = decorations.add(newState.doc, [draghandleDec]);
200
217
  }
201
218
  }
202
219
 
203
220
  // Remove previous drag handle widget and draw new drag handle widget when activeNode changes
204
- if (meta !== null && meta !== void 0 && meta.activeNode && (meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) && api) {
205
- var _oldHandle = decorations.find().filter(function (_ref8) {
206
- var spec = _ref8.spec;
221
+ if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
222
+ var _oldHandle = decorations.find().filter(function (_ref9) {
223
+ var spec = _ref9.spec;
207
224
  return spec.id === 'drag-handle';
208
225
  });
209
226
  decorations = decorations.remove(_oldHandle);
210
- var decs = (0, _decorations.dragHandleDecoration)(meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, api, getIntl);
227
+ var decs = (0, _decorations.dragHandleDecoration)(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
211
228
  decorations = decorations.add(newState.doc, [decs]);
212
229
  }
213
230
  if ((0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-ed-23816')) {
214
231
  var _activeNodeWithNewNod;
215
232
  // Remove previous drag handle widget and draw new drag handle widget when node type changes
216
233
  if (activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
217
- var _oldHandle2 = decorations.find().filter(function (_ref9) {
218
- var spec = _ref9.spec;
234
+ var _oldHandle2 = decorations.find().filter(function (_ref10) {
235
+ var spec = _ref10.spec;
219
236
  return spec.id === 'drag-handle';
220
237
  });
221
238
  decorations = decorations.remove(_oldHandle2);
222
- var _decs = (0, _decorations.dragHandleDecoration)(activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType, api, getIntl);
239
+ var _decs = (0, _decorations.dragHandleDecoration)(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
223
240
  decorations = decorations.add(newState.doc, [_decs]);
224
241
  }
225
242
  }
@@ -235,8 +252,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
235
252
 
236
253
  // Remove drop target decoration when dragging stops
237
254
  if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false && !tr.docChanged) {
238
- var dropTargetDecs = decorations.find().filter(function (_ref10) {
239
- var spec = _ref10.spec;
255
+ var dropTargetDecs = decorations.find().filter(function (_ref11) {
256
+ var spec = _ref11.spec;
240
257
  return spec.type === 'drop-target-decoration';
241
258
  });
242
259
  decorations = decorations.remove(dropTargetDecs);
@@ -244,9 +261,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
244
261
 
245
262
  // Map drop target decoration positions when the document changes
246
263
  if (tr.docChanged && isDragging) {
247
- decorationState = decorationState.map(function (_ref11) {
248
- var index = _ref11.index,
249
- pos = _ref11.pos;
264
+ decorationState = decorationState.map(function (_ref12) {
265
+ var index = _ref12.index,
266
+ pos = _ref12.pos;
250
267
  return {
251
268
  index: index,
252
269
  pos: tr.mapping.map(pos)
@@ -259,8 +276,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
259
276
  decorations = decorations.map(tr.mapping, tr.doc);
260
277
  }
261
278
  var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
262
- var hasNodeDecoration = decorations.find().some(function (_ref12) {
263
- var spec = _ref12.spec;
279
+ var hasNodeDecoration = decorations.find().some(function (_ref13) {
280
+ var spec = _ref13.spec;
264
281
  return spec.type === 'node-decoration';
265
282
  });
266
283
  if (!hasNodeDecoration && isEmptyDoc) {
@@ -379,6 +396,15 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
379
396
  return true;
380
397
  }
381
398
  }
399
+
400
+ //NOTE: altKey === 'option' on MacOS
401
+ if (event.altKey && event.shiftKey && event.ctrlKey && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
402
+ //prevent holding down key combo from firing repeatedly
403
+ if (!event.repeat && (0, _keymap.boundKeydownHandler)(api)(view, event)) {
404
+ event.preventDefault();
405
+ return true;
406
+ }
407
+ }
382
408
  return false;
383
409
  }
384
410
  }
@@ -391,7 +417,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
391
417
  if (!(0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
392
418
  // Use ResizeObserver to observe height changes
393
419
  resizeObserverHeight = new ResizeObserver((0, _rafSchd.default)(function (entries) {
394
- var editorHeight = entries[0].contentBoxSize[0].blockSize;
420
+ var _entries$;
421
+ var editorHeight = (_entries$ = entries[0]) === null || _entries$ === void 0 || (_entries$ = _entries$.contentBoxSize[0]) === null || _entries$ === void 0 ? void 0 : _entries$.blockSize;
395
422
 
396
423
  // Update the plugin state when the height changes
397
424
  var pluginState = key.getState(editorView.state);
@@ -401,7 +428,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
401
428
  if ((pluginState === null || pluginState === void 0 ? void 0 : pluginState.isResizerResizing) !== isResizerResizing) {
402
429
  transaction.setMeta('is-resizer-resizing', isResizerResizing);
403
430
  }
404
- if (!isResizerResizing) {
431
+ if (!isResizerResizing && editorHeight) {
405
432
  transaction.setMeta(key, {
406
433
  editorHeight: editorHeight
407
434
  });
@@ -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 _bindEventListener = require("bind-event-listener");
11
12
  var _reactIntlNext = require("react-intl-next");
12
13
  var _analytics = require("@atlaskit/editor-common/analytics");
13
14
  var _hooks = require("@atlaskit/editor-common/hooks");
@@ -48,11 +49,15 @@ var dragHandleButtonStyles = (0, _react2.css)({
48
49
  cursor: 'grab',
49
50
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
50
51
  zIndex: _consts.DRAG_HANDLE_ZINDEX,
52
+ outline: 'none',
51
53
  '&:hover': {
52
54
  backgroundColor: "var(--ds-background-neutral-subtle-hovered, #091E420F)"
53
55
  },
54
56
  '&:active': {
55
57
  backgroundColor: "var(--ds-background-neutral-subtle-pressed, #091E4224)"
58
+ },
59
+ '&:focus': {
60
+ outline: "2px solid ".concat("var(--ds-border-focused, #388BFF)")
56
61
  }
57
62
  });
58
63
  var selectedStyles = (0, _react2.css)({
@@ -65,7 +70,8 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
65
70
  getPos = _ref.getPos,
66
71
  anchorName = _ref.anchorName,
67
72
  nodeType = _ref.nodeType,
68
- formatMessage = _ref.intl.formatMessage;
73
+ formatMessage = _ref.intl.formatMessage,
74
+ handleOptions = _ref.handleOptions;
69
75
  var start = getPos();
70
76
  var buttonRef = (0, _react.useRef)(null);
71
77
  var _useState = (0, _react.useState)(768),
@@ -168,6 +174,34 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
168
174
  return tr;
169
175
  });
170
176
  }, [start, api]);
177
+ var handleKeyDown = (0, _react.useCallback)(function (e) {
178
+ if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
179
+ // allow user to use spacebar to select the node
180
+ if (!e.repeat && e.key === ' ') {
181
+ var _api$core4;
182
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref5) {
183
+ var tr = _ref5.tr;
184
+ if (start === undefined) {
185
+ return tr;
186
+ }
187
+ var node = tr.doc.nodeAt(start);
188
+ if (!node) {
189
+ return tr;
190
+ }
191
+ var $startPos = tr.doc.resolve(start + node.nodeSize);
192
+ var selection = new _state.TextSelection($startPos);
193
+ tr.setSelection(selection);
194
+ tr.setMeta(_main.key, {
195
+ pos: start
196
+ });
197
+ return tr;
198
+ });
199
+ } else {
200
+ // return focus to editor to resume editing from caret positon
201
+ view.focus();
202
+ }
203
+ }
204
+ }, [start, api, view]);
171
205
  (0, _react.useEffect)(function () {
172
206
  var element = buttonRef.current;
173
207
  if (!element) {
@@ -181,11 +215,11 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
181
215
  start: start
182
216
  };
183
217
  },
184
- onGenerateDragPreview: function onGenerateDragPreview(_ref5) {
185
- var nativeSetDragImage = _ref5.nativeSetDragImage;
218
+ onGenerateDragPreview: function onGenerateDragPreview(_ref6) {
219
+ var nativeSetDragImage = _ref6.nativeSetDragImage;
186
220
  (0, _setCustomNativeDragPreview.setCustomNativeDragPreview)({
187
- render: function render(_ref6) {
188
- var container = _ref6.container;
221
+ render: function render(_ref7) {
222
+ var container = _ref7.container;
189
223
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
190
224
  if (!dom) {
191
225
  return;
@@ -196,13 +230,13 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
196
230
  });
197
231
  },
198
232
  onDragStart: function onDragStart() {
199
- var _api$core4;
233
+ var _api$core5;
200
234
  if (start === undefined) {
201
235
  return;
202
236
  }
203
- api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref7) {
237
+ api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref8) {
204
238
  var _api$blockControls, _api$analytics2;
205
- var tr = _ref7.tr;
239
+ var tr = _ref8.tr;
206
240
  api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
207
241
  tr: tr
208
242
  });
@@ -226,7 +260,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
226
260
  });
227
261
  }, [anchorName, api, nodeType, view, start]);
228
262
  var macroInteractionUpdates = featureFlagsState === null || featureFlagsState === void 0 ? void 0 : featureFlagsState.macroInteractionUpdates;
229
- var positionStyles = (0, _react.useMemo)(function () {
263
+ var calculatePosition = (0, _react.useCallback)(function () {
230
264
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
231
265
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
232
266
  var hasResizer = nodeType === 'table' || nodeType === 'mediaSingle';
@@ -248,18 +282,71 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
248
282
  }
249
283
  if (supportsAnchor) {
250
284
  return (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? {
251
- left: hasResizer || isExtension || isEmbedCard ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
285
+ left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
252
286
  top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _consts.topPositionAdjustment)(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(_consts.DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
253
287
  } : {
254
288
  left: hasResizer || isExtension || isBlockCard || isEmbedCard ? (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(_consts.DRAG_HANDLE_WIDTH, "px - ").concat((0, _consts.dragHandleGap)(nodeType), "px)"),
255
289
  top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat((0, _consts.topPositionAdjustment)(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(_consts.DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
256
290
  };
257
291
  }
258
- return {
292
+ return (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? {
293
+ left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat((0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates),
294
+ top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? (0, _dragHandlePositions.getTopPosition)(dom, nodeType) : (0, _dragHandlePositions.getTopPosition)(dom)
295
+ } : {
259
296
  left: (0, _dragHandlePositions.getLeftPosition)(dom, nodeType, innerContainer, macroInteractionUpdates),
260
297
  top: (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_ed_23674') ? (0, _dragHandlePositions.getTopPosition)(dom, nodeType) : (0, _dragHandlePositions.getTopPosition)(dom)
261
298
  };
262
299
  }, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
300
+ var _useState5 = (0, _react.useState)({
301
+ display: 'none'
302
+ }),
303
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
304
+ newPositionStyles = _useState6[0],
305
+ setNewPositionStyles = _useState6[1];
306
+ (0, _react.useEffect)(function () {
307
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
308
+ return;
309
+ }
310
+ var cleanUpTransitionListener;
311
+ if (nodeType === 'extension' || nodeType === 'embedCard') {
312
+ var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
313
+ if (!dom) {
314
+ return;
315
+ }
316
+ cleanUpTransitionListener = (0, _bindEventListener.bind)(dom, {
317
+ type: 'transitionend',
318
+ listener: function listener() {
319
+ setNewPositionStyles(calculatePosition());
320
+ }
321
+ });
322
+ }
323
+ var calcPos = requestAnimationFrame(function () {
324
+ setNewPositionStyles(calculatePosition());
325
+ });
326
+ return function () {
327
+ var _cleanUpTransitionLis;
328
+ cancelAnimationFrame(calcPos);
329
+ (_cleanUpTransitionLis = cleanUpTransitionListener) === null || _cleanUpTransitionLis === void 0 || _cleanUpTransitionLis();
330
+ };
331
+ }, [calculatePosition, view.dom, anchorName, nodeType]);
332
+ var positionStyles = (0, _react.useMemo)(function () {
333
+ if ((0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896')) {
334
+ return newPositionStyles;
335
+ }
336
+ return calculatePosition();
337
+ }, [calculatePosition, newPositionStyles]);
338
+ (0, _react.useEffect)(function () {
339
+ if (handleOptions !== null && handleOptions !== void 0 && handleOptions.isFocused && buttonRef.current && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
340
+ var id = requestAnimationFrame(function () {
341
+ var _buttonRef$current;
342
+ (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 || _buttonRef$current.focus();
343
+ });
344
+ return function () {
345
+ cancelAnimationFrame(id);
346
+ view.focus();
347
+ };
348
+ }
349
+ }, [buttonRef, handleOptions === null || handleOptions === void 0 ? void 0 : handleOptions.isFocused, view]);
263
350
  var helpDescriptors = [{
264
351
  description: formatMessage(_messages.blockControlsMessages.dragToMove)
265
352
  }, {
@@ -276,9 +363,10 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
276
363
  ref: buttonRef
277
364
  // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
278
365
  ,
279
- style: positionStyles,
366
+ style: (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23896') ? newPositionStyles : positionStyles,
280
367
  onClick: handleOnClick,
281
368
  onMouseDown: (0, _platformFeatureFlags.fg)('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2') ? handleMouseDownWrapperRemoved : handleMouseDown,
369
+ onKeyDown: handleKeyDown,
282
370
  "data-testid": "block-ctrl-drag-handle"
283
371
  }, (0, _react2.jsx)(_dragHandler.default, {
284
372
  label: "",
@@ -0,0 +1,16 @@
1
+ export const showDragHandleAtSelection = api => (state, _, view) => {
2
+ const rootPos = state.selection.$from.before(1);
3
+ const dom = view === null || view === void 0 ? void 0 : view.domAtPos(rootPos, 0);
4
+ const rootNode = dom === null || dom === void 0 ? void 0 : dom.node.childNodes[dom === null || dom === void 0 ? void 0 : dom.offset];
5
+ if (rootNode) {
6
+ const anchorName = rootNode.getAttribute('data-drag-handler-anchor-name');
7
+ const nodeType = rootNode.getAttribute('data-drag-handler-node-type');
8
+ if (api && anchorName && nodeType) {
9
+ api.core.actions.execute(api.blockControls.commands.showDragHandleAt(rootPos, anchorName, nodeType, {
10
+ isFocused: true
11
+ }));
12
+ return true;
13
+ }
14
+ }
15
+ return false;
16
+ };
@@ -49,14 +49,15 @@ export const blockControlsPlugin = ({
49
49
  })(tr);
50
50
  return tr;
51
51
  },
52
- showDragHandleAt: (pos, anchorName, nodeType) => ({
52
+ showDragHandleAt: (pos, anchorName, nodeType, handleOptions) => ({
53
53
  tr
54
54
  }) => {
55
55
  tr.setMeta(key, {
56
56
  activeNode: {
57
57
  pos,
58
58
  anchorName,
59
- nodeType
59
+ nodeType,
60
+ handleOptions
60
61
  }
61
62
  });
62
63
  return tr;
@@ -130,13 +130,16 @@ export const mouseMoveWrapperDecorations = (newState, api) => {
130
130
  });
131
131
  return decs;
132
132
  };
133
- export const dragHandleDecoration = (pos, anchorName, nodeType, api, getIntl) => {
133
+ export const dragHandleDecoration = (api, getIntl, pos, anchorName, nodeType, handleOptions) => {
134
134
  return Decoration.widget(pos, (view, getPos) => {
135
135
  const element = document.createElement('div');
136
136
  // Need to set it to inline to avoid text being split when merging two paragraphs
137
137
  element.style.display = 'inline';
138
138
  element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
139
139
  element.setAttribute('data-blocks-drag-handle-container', 'true');
140
+ if (fg('platform_editor_element_drag_and_drop_ed_23896')) {
141
+ unmountDecorations('data-blocks-drag-handle-container');
142
+ }
140
143
  if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
141
144
  // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
142
145
  // due to margins applied to other nodes eg. Headings
@@ -149,14 +152,17 @@ export const dragHandleDecoration = (pos, anchorName, nodeType, api, getIntl) =>
149
152
  api,
150
153
  getPos,
151
154
  anchorName,
152
- nodeType
155
+ nodeType,
156
+ handleOptions
153
157
  })), element);
154
158
  return element;
155
159
  }, {
156
160
  side: -1,
157
161
  id: 'drag-handle',
158
162
  destroy: node => {
159
- ReactDOM.unmountComponentAtNode(node);
163
+ if (!fg('platform_editor_element_drag_and_drop_ed_23896')) {
164
+ ReactDOM.unmountComponentAtNode(node);
165
+ }
160
166
  }
161
167
  });
162
168
  };
@@ -0,0 +1,16 @@
1
+ import { bindKeymapWithCommand, showElementDragHandle } from '@atlaskit/editor-common/keymaps';
2
+ import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { showDragHandleAtSelection } from '../commands/show-drag-handle';
5
+ function keymapList(api) {
6
+ let keymapList = {};
7
+ if (api && fg('platform_editor_element_drag_and_drop_ed_23873')) {
8
+ bindKeymapWithCommand(showElementDragHandle.common, (state, dispatch, view) => {
9
+ showDragHandleAtSelection(api)(state, dispatch, view);
10
+ //we always want to handle this shortcut to prevent default browser special char insert when option + alphabetical key is used
11
+ return true;
12
+ }, keymapList);
13
+ }
14
+ return keymapList;
15
+ }
16
+ export const boundKeydownHandler = api => keydownHandler(keymapList(api));