@atlaskit/editor-plugin-block-controls 2.9.0 → 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/commands/move-to-layout.js +16 -1
  3. package/dist/cjs/pm-plugins/decorations-anchor.js +99 -0
  4. package/dist/cjs/pm-plugins/decorations-common.js +49 -0
  5. package/dist/cjs/pm-plugins/decorations-drag-handle.js +88 -0
  6. package/dist/cjs/pm-plugins/{decorations.js → decorations-drop-target.js} +11 -208
  7. package/dist/cjs/pm-plugins/main.js +21 -19
  8. package/dist/cjs/ui/drop-target-v2.js +3 -3
  9. package/dist/cjs/ui/inline-drop-target.js +79 -20
  10. package/dist/cjs/utils/check-media-layout.js +14 -0
  11. package/dist/cjs/utils/inline-drop-target.js +4 -0
  12. package/dist/es2019/commands/move-to-layout.js +16 -1
  13. package/dist/es2019/pm-plugins/decorations-anchor.js +91 -0
  14. package/dist/es2019/pm-plugins/decorations-common.js +31 -0
  15. package/dist/es2019/pm-plugins/decorations-drag-handle.js +79 -0
  16. package/dist/es2019/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -192
  17. package/dist/es2019/pm-plugins/main.js +3 -1
  18. package/dist/es2019/ui/drop-target-v2.js +1 -1
  19. package/dist/es2019/ui/inline-drop-target.js +77 -18
  20. package/dist/es2019/utils/check-media-layout.js +8 -0
  21. package/dist/es2019/utils/inline-drop-target.js +4 -0
  22. package/dist/esm/commands/move-to-layout.js +16 -1
  23. package/dist/esm/pm-plugins/decorations-anchor.js +92 -0
  24. package/dist/esm/pm-plugins/decorations-common.js +42 -0
  25. package/dist/esm/pm-plugins/decorations-drag-handle.js +81 -0
  26. package/dist/esm/pm-plugins/{decorations.js → decorations-drop-target.js} +6 -203
  27. package/dist/esm/pm-plugins/main.js +3 -1
  28. package/dist/esm/ui/drop-target-v2.js +1 -1
  29. package/dist/esm/ui/inline-drop-target.js +77 -18
  30. package/dist/esm/utils/check-media-layout.js +8 -0
  31. package/dist/esm/utils/inline-drop-target.js +4 -0
  32. package/dist/types/pm-plugins/decorations-anchor.d.ts +13 -0
  33. package/dist/types/pm-plugins/decorations-common.d.ts +7 -0
  34. package/dist/types/pm-plugins/decorations-drag-handle.d.ts +7 -0
  35. package/dist/types/pm-plugins/decorations-drop-target.d.ts +17 -0
  36. package/dist/types/ui/inline-drop-target.d.ts +6 -1
  37. package/dist/types/utils/check-media-layout.d.ts +2 -0
  38. package/dist/types-ts4.5/pm-plugins/decorations-anchor.d.ts +13 -0
  39. package/dist/types-ts4.5/pm-plugins/decorations-common.d.ts +7 -0
  40. package/dist/types-ts4.5/pm-plugins/decorations-drag-handle.d.ts +7 -0
  41. package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +17 -0
  42. package/dist/types-ts4.5/ui/inline-drop-target.d.ts +6 -1
  43. package/dist/types-ts4.5/utils/check-media-layout.d.ts +2 -0
  44. package/package.json +6 -6
  45. package/dist/types/pm-plugins/decorations.d.ts +0 -35
  46. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -35
@@ -0,0 +1,81 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { createElement } from 'react';
3
+ import { bind } from 'bind-event-listener';
4
+ import ReactDOM from 'react-dom';
5
+ import uuid from 'uuid';
6
+ import { Decoration } from '@atlaskit/editor-prosemirror/view';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
9
+ import { DragHandle } from '../ui/drag-handle';
10
+ import { TYPE_HANDLE_DEC, TYPE_NODE_DEC, unmountDecorations } from './decorations-common';
11
+ export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
12
+ var anchorName = "--node-anchor-paragraph-0";
13
+ var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
14
+ return Decoration.node(0, 2, _defineProperty({
15
+ style: style
16
+ }, 'data-drag-handler-anchor-name', anchorName), {
17
+ type: TYPE_NODE_DEC
18
+ });
19
+ };
20
+ export var findHandleDec = function findHandleDec(decorations, from, to) {
21
+ return decorations.find(from, to, function (spec) {
22
+ return spec.type === TYPE_HANDLE_DEC;
23
+ });
24
+ };
25
+ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
26
+ unmountDecorations('data-blocks-drag-handle-container');
27
+ var unbind;
28
+ return Decoration.widget(pos, function (view, getPos) {
29
+ var element = document.createElement('span');
30
+ // Need to set it to inline to avoid text being split when merging two paragraphs
31
+ // platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
32
+ element.style.display = fg('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
33
+ element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
34
+ element.setAttribute('data-blocks-drag-handle-container', 'true');
35
+ var isTopLevelNode = true;
36
+ if (editorExperiment('nested-dnd', true)) {
37
+ var newPos = fg('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
38
+ if (typeof newPos === 'number') {
39
+ var $pos = view.state.doc.resolve(newPos);
40
+ isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
41
+ }
42
+ /*
43
+ * We disable mouseover event to fix flickering issue on hover
44
+ * However, the tooltip for nested drag handle is no long working.
45
+ */
46
+ if (newPos === undefined || !isTopLevelNode) {
47
+ // This will also hide the tooltip.
48
+ unbind = bind(element, {
49
+ type: 'mouseover',
50
+ listener: function listener(e) {
51
+ e.stopPropagation();
52
+ }
53
+ });
54
+ }
55
+ }
56
+
57
+ // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
58
+ // due to margins applied to other nodes eg. Headings
59
+ element.style.clear = 'unset';
60
+ ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
61
+ view: view,
62
+ api: api,
63
+ formatMessage: formatMessage,
64
+ getPos: getPos,
65
+ anchorName: anchorName,
66
+ nodeType: nodeType,
67
+ handleOptions: handleOptions,
68
+ isTopLevelNode: isTopLevelNode
69
+ }), element);
70
+ return element;
71
+ }, {
72
+ side: -1,
73
+ type: TYPE_HANDLE_DEC,
74
+ testid: "".concat(TYPE_HANDLE_DEC, "-").concat(uuid()),
75
+ destroy: function destroy() {
76
+ if (editorExperiment('nested-dnd', true)) {
77
+ unbind && unbind();
78
+ }
79
+ }
80
+ });
81
+ };
@@ -1,35 +1,26 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
4
  import { createElement } from 'react';
7
- import { bind } from 'bind-event-listener';
8
5
  import ReactDOM from 'react-dom';
9
- import uuid from 'uuid';
10
6
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
11
7
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
12
8
  import { fg } from '@atlaskit/platform-feature-flags';
13
9
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
10
  import { nodeMargins } from '../ui/consts';
15
- import { DragHandle } from '../ui/drag-handle';
16
11
  import { DropTarget } from '../ui/drop-target';
17
12
  import { DropTargetV2, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET } from '../ui/drop-target-v2';
18
13
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
19
14
  import { canMoveNodeToIndex } from '../utils/validation';
15
+ import { getNestedDepth, TYPE_DROP_TARGET_DEC, unmountDecorations } from './decorations-common';
20
16
  var IGNORE_NODES = ['tableCell', 'tableHeader', 'tableRow', 'layoutColumn', 'listItem', 'caption'];
21
- var IGNORE_NODE_DESCENDANTS = ['listItem', 'taskList', 'decisionList', 'mediaSingle'];
22
17
  var PARENT_WITH_END_DROP_TARGET = ['tableCell', 'tableHeader', 'panel', 'layoutColumn', 'expand', 'nestedExpand', 'bodiedExtension'];
23
18
  var DISABLE_CHILD_DROP_TARGET = ['orderedList', 'bulletList'];
24
- export var TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
25
- export var TYPE_HANDLE_DEC = 'drag-handle';
26
- export var TYPE_NODE_DEC = 'node-decoration';
27
- var getNestedDepth = function getNestedDepth() {
28
- return editorExperiment('nested-dnd', true) ? 100 : 0;
29
- };
30
- export var getNodeAnchor = function getNodeAnchor(node) {
31
- var handleId = ObjHash.getForNode(node);
32
- return "--node-anchor-".concat(node.type.name, "-").concat(handleId);
19
+ var shouldDescend = function shouldDescend(node) {
20
+ if (fg('platform_editor_drag_and_drop_target_v2')) {
21
+ return !['mediaSingle', 'paragraph', 'heading'].includes(node.type.name);
22
+ }
23
+ return true;
33
24
  };
34
25
  var getNodeMargins = function getNodeMargins(node) {
35
26
  if (!node) {
@@ -74,12 +65,6 @@ var getGapAndOffset = function getGapAndOffset(prevNode, nextNode, parentNode) {
74
65
  offset: offset
75
66
  };
76
67
  };
77
- var shouldDescend = function shouldDescend(node) {
78
- if (fg('platform_editor_drag_and_drop_target_v2')) {
79
- return !['mediaSingle', 'paragraph', 'heading'].includes(node.type.name);
80
- }
81
- return true;
82
- };
83
68
 
84
69
  /**
85
70
  * Find drop target decorations in the pos range between from and to
@@ -93,41 +78,6 @@ export var findDropTargetDecs = function findDropTargetDecs(decorations, from, t
93
78
  return spec.type === TYPE_DROP_TARGET_DEC;
94
79
  });
95
80
  };
96
- export var findHandleDec = function findHandleDec(decorations, from, to) {
97
- return decorations.find(from, to, function (spec) {
98
- return spec.type === TYPE_HANDLE_DEC;
99
- });
100
- };
101
-
102
- /**
103
- * Find node decorations in the pos range between from and to (non-inclusive)
104
- * @param decorations
105
- * @param from
106
- * @param to
107
- * @returns
108
- */
109
- export var findNodeDecs = function findNodeDecs(decorations, from, to) {
110
- var newfrom = from;
111
- var newTo = to;
112
-
113
- // make it non-inclusive
114
- if (newfrom !== undefined) {
115
- newfrom++;
116
- }
117
-
118
- // make it non-inclusive
119
- if (newTo !== undefined) {
120
- newTo--;
121
- }
122
-
123
- // return empty array if range reversed
124
- if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
125
- return new Array();
126
- }
127
- return decorations.find(newfrom, newTo, function (spec) {
128
- return spec.type === TYPE_NODE_DEC;
129
- });
130
- };
131
81
  export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache) {
132
82
  return Decoration.widget(pos, function (_, getPos) {
133
83
  var element = document.createElement('div');
@@ -253,151 +203,4 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
253
203
  }, undefined, anchorRectCache));
254
204
  }
255
205
  return decs;
256
- };
257
- export var emptyParagraphNodeDecorations = function emptyParagraphNodeDecorations() {
258
- var anchorName = "--node-anchor-paragraph-0";
259
- var style = "anchor-name: ".concat(anchorName, "; margin-top: 0px;");
260
- return Decoration.node(0, 2, _defineProperty({
261
- style: style
262
- }, 'data-drag-handler-anchor-name', anchorName), {
263
- type: TYPE_NODE_DEC
264
- });
265
- };
266
- var ObjHash = /*#__PURE__*/function () {
267
- function ObjHash() {
268
- _classCallCheck(this, ObjHash);
269
- }
270
- _createClass(ObjHash, null, [{
271
- key: "getForNode",
272
- value: function getForNode(node) {
273
- if (this.caching.has(node)) {
274
- return this.caching.get(node);
275
- }
276
- var uniqueId = uuid();
277
- this.caching.set(node, uniqueId);
278
- return uniqueId;
279
- }
280
- }]);
281
- return ObjHash;
282
- }();
283
- _defineProperty(ObjHash, "caching", new WeakMap());
284
- var shouldIgnoreNode = function shouldIgnoreNode(node) {
285
- if ('mediaSingle' === node.type.name && fg('platform_editor_element_dnd_nested_fix_patch_1')) {
286
- if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
287
- return true;
288
- }
289
- }
290
- return IGNORE_NODES.includes(node.type.name);
291
- };
292
- export var shouldDescendIntoNode = function shouldDescendIntoNode(node) {
293
- // Optimisation to avoid drawing node decorations for empty table cells
294
- if (['tableCell', 'tableHeader'].includes(node.type.name) && !editorExperiment('table-nested-dnd', true) && fg('platform_editor_element_dnd_nested_fix_patch_3')) {
295
- var _node$firstChild;
296
- if (node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'paragraph') {
297
- return false;
298
- }
299
- }
300
- return !IGNORE_NODE_DESCENDANTS.includes(node.type.name);
301
- };
302
- export var nodeDecorations = function nodeDecorations(newState, from, to) {
303
- var decs = [];
304
- var docFrom = from === undefined || from < 0 ? 0 : from;
305
- var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
306
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, _parent, index) {
307
- var _Decoration$node2;
308
- var depth = 0;
309
- var anchorName;
310
- var shouldDescend = shouldDescendIntoNode(node);
311
- var handleId = ObjHash.getForNode(node);
312
- anchorName = "--node-anchor-".concat(node.type.name, "-").concat(handleId);
313
- if (editorExperiment('nested-dnd', true)) {
314
- var _anchorName;
315
- // Doesn't descend into a node
316
- if (node.isInline) {
317
- return false;
318
- }
319
- if (shouldIgnoreNode(node)) {
320
- return shouldDescend; //skip over, don't consider it a valid depth
321
- }
322
- depth = newState.doc.resolve(pos).depth;
323
- anchorName = (_anchorName = anchorName) !== null && _anchorName !== void 0 ? _anchorName : "--node-anchor-".concat(node.type.name, "-").concat(pos);
324
- } else {
325
- var _anchorName2;
326
- anchorName = (_anchorName2 = anchorName) !== null && _anchorName2 !== void 0 ? _anchorName2 : "--node-anchor-".concat(node.type.name, "-").concat(index);
327
- }
328
- decs.push(Decoration.node(pos, pos + node.nodeSize, (_Decoration$node2 = {
329
- style: "anchor-name: ".concat(anchorName, "; ").concat(pos === 0 ? 'margin-top: 0px;' : '', "; position: relative; z-index: 1;")
330
- }, _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-name', anchorName), _defineProperty(_Decoration$node2, 'data-drag-handler-node-type', node.type.name), _defineProperty(_Decoration$node2, 'data-drag-handler-anchor-depth', "".concat(depth)), _Decoration$node2), {
331
- type: TYPE_NODE_DEC,
332
- anchorName: anchorName,
333
- nodeType: node.type.name
334
- }));
335
- return shouldDescend && depth < getNestedDepth();
336
- });
337
- return decs;
338
- };
339
- export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
340
- unmountDecorations('data-blocks-drag-handle-container');
341
- var unbind;
342
- return Decoration.widget(pos, function (view, getPos) {
343
- var element = document.createElement('span');
344
- // Need to set it to inline to avoid text being split when merging two paragraphs
345
- // platform_editor_element_dnd_nested_fix_patch_2 -> inline decoration causes focus issues when refocusing Editor into first line
346
- element.style.display = fg('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
347
- element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
348
- element.setAttribute('data-blocks-drag-handle-container', 'true');
349
- var isTopLevelNode = true;
350
- if (editorExperiment('nested-dnd', true)) {
351
- var newPos = fg('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
352
- if (typeof newPos === 'number') {
353
- var $pos = view.state.doc.resolve(newPos);
354
- isTopLevelNode = ($pos === null || $pos === void 0 ? void 0 : $pos.parent.type.name) === 'doc';
355
- }
356
- /*
357
- * We disable mouseover event to fix flickering issue on hover
358
- * However, the tooltip for nested drag handle is no long working.
359
- */
360
- if (newPos === undefined || !isTopLevelNode) {
361
- // This will also hide the tooltip.
362
- unbind = bind(element, {
363
- type: 'mouseover',
364
- listener: function listener(e) {
365
- e.stopPropagation();
366
- }
367
- });
368
- }
369
- }
370
-
371
- // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
372
- // due to margins applied to other nodes eg. Headings
373
- element.style.clear = 'unset';
374
- ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
375
- view: view,
376
- api: api,
377
- formatMessage: formatMessage,
378
- getPos: getPos,
379
- anchorName: anchorName,
380
- nodeType: nodeType,
381
- handleOptions: handleOptions,
382
- isTopLevelNode: isTopLevelNode
383
- }), element);
384
- return element;
385
- }, {
386
- side: -1,
387
- type: TYPE_HANDLE_DEC,
388
- testid: "".concat(TYPE_HANDLE_DEC, "-").concat(uuid()),
389
- destroy: function destroy() {
390
- if (editorExperiment('nested-dnd', true)) {
391
- unbind && unbind();
392
- }
393
- }
394
- });
395
- };
396
- var unmountDecorations = function unmountDecorations(selector) {
397
- // Removing decorations manually instead of using native destroy function in prosemirror API
398
- // as it was more responsive and causes less re-rendering
399
- var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
400
- decorationsToRemove.forEach(function (el) {
401
- ReactDOM.unmountComponentAtNode(el);
402
- });
403
206
  };
@@ -15,7 +15,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
15
  import { AnchorRectCache, isAnchorSupported } from '../utils/anchor-utils';
16
16
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
17
17
  import { getTrMetadata } from '../utils/transactions';
18
- import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, findDropTargetDecs, findHandleDec, findNodeDecs, nodeDecorations } from './decorations';
18
+ import { findNodeDecs, nodeDecorations } from './decorations-anchor';
19
+ import { dragHandleDecoration, emptyParagraphNodeDecorations, findHandleDec } from './decorations-drag-handle';
20
+ import { dropTargetDecorations, findDropTargetDecs } from './decorations-drop-target';
19
21
  import { handleMouseOver } from './handle-mouse-over';
20
22
  import { boundKeydownHandler } from './keymap';
21
23
  export var key = new PluginKey('blockControls');
@@ -14,7 +14,7 @@ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indi
14
14
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
15
  import { layers } from '@atlaskit/theme/constants';
16
16
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
17
- import { getNodeAnchor } from '../pm-plugins/decorations';
17
+ import { getNodeAnchor } from '../pm-plugins/decorations-common';
18
18
  import { isAnchorSupported } from '../utils/anchor-utils';
19
19
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
20
20
  import { shouldAllowInlineDropTarget } from '../utils/inline-drop-target';
@@ -12,19 +12,17 @@ import { css, jsx } from '@emotion/react';
12
12
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
13
13
  import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
14
14
  import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
15
- import { getNodeAnchor } from '../pm-plugins/decorations';
15
+ import { getNodeAnchor } from '../pm-plugins/decorations-common';
16
16
  import { isAnchorSupported } from '../utils/anchor-utils';
17
+ import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
17
18
  var dropTargetCommonStyle = css({
18
19
  position: 'absolute',
19
20
  display: 'block'
20
21
  });
21
- var hideDropTargetStyle = css({
22
- display: 'none'
23
- });
24
22
  var hoverZoneCommonStyle = css({
25
23
  position: 'absolute',
26
- // same value as block hover zone
27
- zIndex: 110
24
+ // above the top and bottom drop zone as block hover zone
25
+ zIndex: 120
28
26
  });
29
27
 
30
28
  // gap between node boundary and drop indicator/drop zone
@@ -32,6 +30,60 @@ var GAP = 4;
32
30
  var HOVER_ZONE_WIDTH_OFFSET = 40;
33
31
  var HOVER_ZONE_HEIGHT_OFFSET = 10;
34
32
  var HOVER_ZONE_DEFAULT_WIDTH = 40;
33
+ var getDropTargetPositionOverride = function getDropTargetPositionOverride(node, editorWidth) {
34
+ if (!node || !editorWidth) {
35
+ return {
36
+ left: 0,
37
+ right: 0
38
+ };
39
+ }
40
+ var getOffsets = function getOffsets(nodeWidth) {
41
+ var offset = (editorWidth - nodeWidth) / 2;
42
+ return {
43
+ left: offset,
44
+ right: offset
45
+ };
46
+ };
47
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'table' && node.attrs.width) {
48
+ return getOffsets(node.attrs.width);
49
+ }
50
+
51
+ // media single 🤦
52
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'mediaSingle') {
53
+ var mediaNodeWidth = 0;
54
+ if (node.attrs.width) {
55
+ if (node.attrs.widthType === 'pixel') {
56
+ mediaNodeWidth = node.attrs.width;
57
+ } else if (editorWidth) {
58
+ mediaNodeWidth = node.attrs.width / 100 * editorWidth;
59
+ }
60
+ } else {
61
+ // use media width
62
+ var mediaNode = node.firstChild;
63
+ if (mediaNode && mediaNode.attrs.width) {
64
+ mediaNodeWidth = mediaNode.attrs.width;
65
+ }
66
+ }
67
+ if (mediaNodeWidth) {
68
+ if (node.attrs.layout === 'align-start') {
69
+ return {
70
+ left: 0,
71
+ right: editorWidth - mediaNodeWidth
72
+ };
73
+ } else if (node.attrs.layout === 'align-end') {
74
+ return {
75
+ left: editorWidth - mediaNodeWidth,
76
+ right: 0
77
+ };
78
+ }
79
+ return getOffsets(mediaNodeWidth);
80
+ }
81
+ }
82
+ return {
83
+ left: 0,
84
+ right: 0
85
+ };
86
+ };
35
87
  export var InlineDropTarget = function InlineDropTarget(_ref) {
36
88
  var api = _ref.api,
37
89
  nextNode = _ref.nextNode,
@@ -51,22 +103,25 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
51
103
  var handleDragLeave = useCallback(function () {
52
104
  setIsDraggedOver(false);
53
105
  }, []);
106
+ var offsets = useMemo(function () {
107
+ return getDropTargetPositionOverride(nextNode, widthState === null || widthState === void 0 ? void 0 : widthState.lineLength);
108
+ }, [nextNode, widthState]);
54
109
  var dropTargetRectStyle = useMemo(function () {
55
110
  if (isAnchorSupported()) {
56
111
  return css({
57
112
  height: "calc(anchor-size(".concat(anchorName, " height))"),
58
113
  positionAnchor: anchorName,
59
- left: position === 'left' ? "calc(anchor(left) - ".concat(GAP, "px)") : "calc(anchor(right) + ".concat(GAP, "px)"),
114
+ left: position === 'left' ? "calc(anchor(left) - ".concat(GAP - offsets.left, "px)") : "calc(anchor(right) + ".concat(GAP - offsets.right, "px)"),
60
115
  top: "calc(anchor(top))"
61
116
  });
62
117
  }
63
118
  var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
64
119
  return css({
65
120
  height: "calc(".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0, "px)"),
66
- left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
121
+ left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP + offsets.left, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offsets.right, "px"),
67
122
  top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px")
68
123
  });
69
- }, [anchorName, anchorRectCache, position]);
124
+ }, [anchorName, anchorRectCache, offsets.left, offsets.right, position]);
70
125
  var onDrop = useCallback(function () {
71
126
  var _api$blockControls;
72
127
  var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
@@ -83,8 +138,8 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
83
138
  }, [api, getPos, position]);
84
139
  return jsx(Fragment, null, jsx("div", {
85
140
  "data-test-id": "block-ctrl-drop-target-".concat(position),
86
- css: [dropTargetCommonStyle, dropTargetRectStyle, !isDraggedOver && hideDropTargetStyle]
87
- }, jsx(DropIndicator, {
141
+ css: [dropTargetCommonStyle, dropTargetRectStyle]
142
+ }, (isDraggedOver || isBlocksDragTargetDebug()) && jsx(DropIndicator, {
88
143
  edge: position
89
144
  })), jsx(InlineHoverZone, {
90
145
  position: position,
@@ -93,7 +148,8 @@ export var InlineDropTarget = function InlineDropTarget(_ref) {
93
148
  anchorRectCache: anchorRectCache,
94
149
  onDragEnter: handleDragEnter,
95
150
  onDragLeave: handleDragLeave,
96
- onDrop: onDrop
151
+ onDrop: onDrop,
152
+ offsets: offsets
97
153
  }));
98
154
  };
99
155
  export var InlineHoverZone = function InlineHoverZone(_ref3) {
@@ -101,6 +157,7 @@ export var InlineHoverZone = function InlineHoverZone(_ref3) {
101
157
  editorWidthState = _ref3.editorWidthState,
102
158
  anchorRectCache = _ref3.anchorRectCache,
103
159
  position = _ref3.position,
160
+ offsets = _ref3.offsets,
104
161
  onDragEnter = _ref3.onDragEnter,
105
162
  onDragLeave = _ref3.onDragLeave,
106
163
  onDrop = _ref3.onDrop;
@@ -119,27 +176,29 @@ export var InlineHoverZone = function InlineHoverZone(_ref3) {
119
176
  }
120
177
  }, [onDragEnter, onDragLeave, onDrop]);
121
178
  var inlineHoverZoneRectStyle = useMemo(function () {
179
+ var offset = offsets[position];
122
180
  if (isAnchorSupported()) {
123
181
  return css({
124
182
  positionAnchor: anchorName,
125
- left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP, "px)"),
126
- right: position === 'left' ? "calc(anchor(left) + ".concat(GAP, "px)") : 'unset',
183
+ left: position === 'left' ? 'unset' : "calc(anchor(right) + ".concat(GAP - offset, "px)"),
184
+ right: position === 'left' ? "calc(anchor(left) + ".concat(GAP - offset, "px)") : 'unset',
127
185
  top: "calc(anchor(top))",
128
- width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
186
+ width: editorWith ? "calc((".concat(editorWith, "px - anchor-size(").concat(anchorName, " width))/2 - ").concat(HOVER_ZONE_WIDTH_OFFSET, "px + ").concat(offset, "px)") : "".concat(HOVER_ZONE_DEFAULT_WIDTH, "px"),
129
187
  height: "calc(anchor-size(".concat(anchorName, " height))")
130
188
  });
131
189
  }
132
190
  var nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
133
- var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
191
+ var width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET + offset : HOVER_ZONE_DEFAULT_WIDTH;
134
192
  return css({
135
- left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP, "px"),
193
+ left: position === 'left' ? "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP + offset, "px") : "".concat(((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP - offset, "px"),
136
194
  top: "".concat((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0, "px"),
137
195
  width: "".concat(width, "px"),
138
196
  height: "calc(".concat((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0, "px - ").concat(HOVER_ZONE_HEIGHT_OFFSET, "px)")
139
197
  });
140
- }, [anchorName, anchorRectCache, editorWith, position]);
198
+ }, [anchorName, anchorRectCache, editorWith, offsets, position]);
141
199
  return jsx("div", {
142
200
  ref: ref,
201
+ "data-test-id": "drop-target-hover-zone-".concat(position),
143
202
  css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
144
203
  });
145
204
  };
@@ -0,0 +1,8 @@
1
+ export var isWrappedMedia = function isWrappedMedia(node) {
2
+ if ('mediaSingle' === (node === null || node === void 0 ? void 0 : node.type.name)) {
3
+ if (['wrap-right', 'wrap-left'].includes(node.attrs.layout)) {
4
+ return true;
5
+ }
6
+ }
7
+ return false;
8
+ };
@@ -1,10 +1,14 @@
1
1
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
2
2
  import { MAX_LAYOUT_COLUMN_SUPPORTED } from '../consts';
3
3
  import { isPreRelease1 } from './advanced-layouts-flags';
4
+ import { isWrappedMedia } from './check-media-layout';
4
5
  export var shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
5
6
  if (!isPreRelease1() || isNested) {
6
7
  return false;
7
8
  }
9
+ if (isWrappedMedia(node)) {
10
+ return false;
11
+ }
8
12
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
9
13
  return node.childCount < MAX_LAYOUT_COLUMN_SUPPORTED;
10
14
  }
@@ -0,0 +1,13 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
+ /**
6
+ * Find node decorations in the pos range between from and to (non-inclusive)
7
+ * @param decorations
8
+ * @param from
9
+ * @param to
10
+ * @returns
11
+ */
12
+ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
13
+ export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
@@ -0,0 +1,7 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ export declare const TYPE_DROP_TARGET_DEC = "drop-target-decoration";
3
+ export declare const TYPE_HANDLE_DEC = "drag-handle";
4
+ export declare const TYPE_NODE_DEC = "node-decoration";
5
+ export declare const getNestedDepth: () => 0 | 100;
6
+ export declare const getNodeAnchor: (node: PMNode) => string;
7
+ export declare const unmountDecorations: (selector: string) => void;
@@ -0,0 +1,7 @@
1
+ import { type IntlShape } from 'react-intl-next';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import type { BlockControlsPlugin, HandleOptions } from '../types';
5
+ export declare const emptyParagraphNodeDecorations: () => Decoration;
6
+ export declare const findHandleDec: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
7
+ export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
@@ -0,0 +1,17 @@
1
+ import { type IntlShape } from 'react-intl-next';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
+ import type { ActiveNode, BlockControlsPlugin } from '../types';
6
+ import { type DropTargetProps } from '../ui/drop-target';
7
+ import { type AnchorRectCache } from '../utils/anchor-utils';
8
+ /**
9
+ * Find drop target decorations in the pos range between from and to
10
+ * @param decorations
11
+ * @param from
12
+ * @param to
13
+ * @returns
14
+ */
15
+ export declare const findDropTargetDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
16
+ export declare const createDropTargetDecoration: (pos: number, props: Omit<DropTargetProps, 'getPos'>, side?: number, anchorRectCache?: AnchorRectCache) => Decoration;
17
+ export declare const dropTargetDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>, formatMessage: IntlShape['formatMessage'], activeNode?: ActiveNode, anchorRectCache?: AnchorRectCache, from?: number, to?: number) => Decoration[];
@@ -3,6 +3,10 @@ import { type EditorContainerWidth } from '@atlaskit/editor-common/src/types';
3
3
  import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
4
4
  import { type AnchorRectCache } from '../utils/anchor-utils';
5
5
  import { type DropTargetProps } from './drop-target';
6
+ type DropTargetOffsets = {
7
+ left: number;
8
+ right: number;
9
+ };
6
10
  export declare const InlineDropTarget: ({ api, nextNode, position, anchorRectCache, getPos, }: DropTargetProps & {
7
11
  anchorRectCache?: AnchorRectCache | undefined;
8
12
  position: 'left' | 'right';
@@ -12,9 +16,10 @@ type InlineHoverZoneProps = {
12
16
  editorWidthState?: EditorContainerWidth;
13
17
  anchorRectCache?: AnchorRectCache;
14
18
  position: 'left' | 'right';
19
+ offsets: DropTargetOffsets;
15
20
  onDragEnter: () => void;
16
21
  onDragLeave: () => void;
17
22
  onDrop: () => void;
18
23
  };
19
- export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
24
+ export declare const InlineHoverZone: ({ node, editorWidthState, anchorRectCache, position, offsets, onDragEnter, onDragLeave, onDrop, }: InlineHoverZoneProps) => jsx.JSX.Element;
20
25
  export {};
@@ -0,0 +1,2 @@
1
+ import { type Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ export declare const isWrappedMedia: (node?: PMNode) => boolean;
@@ -0,0 +1,13 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
+ import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
+ /**
6
+ * Find node decorations in the pos range between from and to (non-inclusive)
7
+ * @param decorations
8
+ * @param from
9
+ * @param to
10
+ * @returns
11
+ */
12
+ export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
13
+ export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
@@ -0,0 +1,7 @@
1
+ import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
+ export declare const TYPE_DROP_TARGET_DEC = "drop-target-decoration";
3
+ export declare const TYPE_HANDLE_DEC = "drag-handle";
4
+ export declare const TYPE_NODE_DEC = "node-decoration";
5
+ export declare const getNestedDepth: () => 0 | 100;
6
+ export declare const getNodeAnchor: (node: PMNode) => string;
7
+ export declare const unmountDecorations: (selector: string) => void;