@atlaskit/editor-plugin-block-controls 2.6.3 → 2.7.0

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 (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/commands/move-to-layout.js +76 -0
  3. package/dist/cjs/consts.js +3 -2
  4. package/dist/cjs/plugin.js +2 -0
  5. package/dist/cjs/pm-plugins/decorations.js +7 -7
  6. package/dist/cjs/pm-plugins/main.js +10 -10
  7. package/dist/cjs/ui/consts.js +8 -1
  8. package/dist/cjs/ui/drop-target-v2.js +24 -17
  9. package/dist/cjs/ui/inline-drop-target.js +138 -0
  10. package/dist/cjs/utils/advanced-layouts-flags.js +11 -0
  11. package/dist/cjs/utils/anchor-utils.js +71 -15
  12. package/dist/cjs/utils/inline-drop-target.js +18 -0
  13. package/dist/es2019/commands/move-to-layout.js +69 -0
  14. package/dist/es2019/consts.js +2 -1
  15. package/dist/es2019/plugin.js +2 -0
  16. package/dist/es2019/pm-plugins/decorations.js +7 -7
  17. package/dist/es2019/pm-plugins/main.js +11 -11
  18. package/dist/es2019/ui/consts.js +7 -0
  19. package/dist/es2019/ui/drop-target-v2.js +24 -16
  20. package/dist/es2019/ui/inline-drop-target.js +130 -0
  21. package/dist/es2019/utils/advanced-layouts-flags.js +5 -0
  22. package/dist/es2019/utils/anchor-utils.js +55 -9
  23. package/dist/es2019/utils/inline-drop-target.js +12 -0
  24. package/dist/esm/commands/move-to-layout.js +70 -0
  25. package/dist/esm/consts.js +2 -1
  26. package/dist/esm/plugin.js +2 -0
  27. package/dist/esm/pm-plugins/decorations.js +7 -7
  28. package/dist/esm/pm-plugins/main.js +11 -11
  29. package/dist/esm/ui/consts.js +7 -0
  30. package/dist/esm/ui/drop-target-v2.js +24 -17
  31. package/dist/esm/ui/inline-drop-target.js +130 -0
  32. package/dist/esm/utils/advanced-layouts-flags.js +5 -0
  33. package/dist/esm/utils/anchor-utils.js +70 -14
  34. package/dist/esm/utils/inline-drop-target.js +12 -0
  35. package/dist/types/commands/move-to-layout.d.ts +3 -0
  36. package/dist/types/consts.d.ts +1 -0
  37. package/dist/types/pm-plugins/decorations.d.ts +3 -3
  38. package/dist/types/pm-plugins/main.d.ts +3 -3
  39. package/dist/types/types.d.ts +1 -0
  40. package/dist/types/ui/consts.d.ts +3 -0
  41. package/dist/types/ui/drop-target-v2.d.ts +3 -3
  42. package/dist/types/ui/inline-drop-target.d.ts +20 -0
  43. package/dist/types/utils/advanced-layouts-flags.d.ts +1 -0
  44. package/dist/types/utils/anchor-utils.d.ts +16 -3
  45. package/dist/types/utils/inline-drop-target.d.ts +2 -0
  46. package/dist/types-ts4.5/commands/move-to-layout.d.ts +3 -0
  47. package/dist/types-ts4.5/consts.d.ts +1 -0
  48. package/dist/types-ts4.5/pm-plugins/decorations.d.ts +3 -3
  49. package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -3
  50. package/dist/types-ts4.5/types.d.ts +1 -0
  51. package/dist/types-ts4.5/ui/consts.d.ts +3 -0
  52. package/dist/types-ts4.5/ui/drop-target-v2.d.ts +3 -3
  53. package/dist/types-ts4.5/ui/inline-drop-target.d.ts +20 -0
  54. package/dist/types-ts4.5/utils/advanced-layouts-flags.d.ts +1 -0
  55. package/dist/types-ts4.5/utils/anchor-utils.d.ts +16 -3
  56. package/dist/types-ts4.5/utils/inline-drop-target.d.ts +2 -0
  57. package/package.json +4 -1
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.isAnchorSupported = exports.AnchorHeightsCache = void 0;
7
+ exports.isAnchorSupported = exports.AnchorRectCache = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
@@ -18,36 +18,42 @@ var isAnchorSupported = exports.isAnchorSupported = (0, _memoizeOne.default)(fun
18
18
  }
19
19
  return false;
20
20
  });
21
- var AnchorHeightsCache = exports.AnchorHeightsCache = /*#__PURE__*/function () {
22
- function AnchorHeightsCache() {
23
- (0, _classCallCheck2.default)(this, AnchorHeightsCache);
24
- (0, _defineProperty2.default)(this, "anchorHeightsMap", {});
21
+ var AnchorRectCache = exports.AnchorRectCache = /*#__PURE__*/function () {
22
+ function AnchorRectCache() {
23
+ (0, _classCallCheck2.default)(this, AnchorRectCache);
24
+ (0, _defineProperty2.default)(this, "anchorRectMap", {});
25
25
  (0, _defineProperty2.default)(this, "isAnchorSupported", isAnchorSupported());
26
26
  (0, _defineProperty2.default)(this, "isDirty", true);
27
27
  (0, _defineProperty2.default)(this, "view", null);
28
28
  }
29
- (0, _createClass2.default)(AnchorHeightsCache, [{
29
+ (0, _createClass2.default)(AnchorRectCache, [{
30
30
  key: "clear",
31
31
  value: function clear() {
32
32
  this.isDirty = true;
33
- this.anchorHeightsMap = {};
33
+ this.anchorRectMap = {};
34
34
  }
35
35
  }, {
36
- key: "getHeights",
37
- value: function getHeights() {
36
+ key: "getRects",
37
+ value: function getRects() {
38
38
  if (this.isDirty) {
39
39
  var _this$view;
40
40
  var anchorElements = ((_this$view = this.view) === null || _this$view === void 0 ? void 0 : _this$view.dom.querySelectorAll('[data-drag-handler-anchor-name]')) || [];
41
- this.anchorHeightsMap = Array.from(anchorElements).reduce(function (prev, curr) {
41
+ this.anchorRectMap = Array.from(anchorElements).reduce(function (prev, curr) {
42
42
  var anchorName = curr.getAttribute('data-drag-handler-anchor-name');
43
43
  if (anchorName) {
44
- return _objectSpread(_objectSpread({}, prev), {}, (0, _defineProperty2.default)({}, anchorName, curr.clientHeight));
44
+ return _objectSpread(_objectSpread({}, prev), {}, (0, _defineProperty2.default)({}, anchorName, {
45
+ height: curr.clientHeight,
46
+ top: curr.offsetTop,
47
+ left: curr.offsetLeft,
48
+ right: curr.offsetLeft + curr.clientWidth,
49
+ width: curr.clientWidth
50
+ }));
45
51
  }
46
52
  return prev;
47
53
  }, {});
48
54
  this.isDirty = false;
49
55
  }
50
- return this.anchorHeightsMap;
56
+ return this.anchorRectMap;
51
57
  }
52
58
  }, {
53
59
  key: "setEditorView",
@@ -59,12 +65,62 @@ var AnchorHeightsCache = exports.AnchorHeightsCache = /*#__PURE__*/function () {
59
65
  }, {
60
66
  key: "getHeight",
61
67
  value: function getHeight(anchorName) {
68
+ var _rects$anchorName;
62
69
  if (this.isAnchorSupported) {
63
70
  return null;
64
71
  }
65
- var heights = this.getHeights();
66
- return heights[anchorName];
72
+ var rects = this.getRects();
73
+ return (_rects$anchorName = rects[anchorName]) === null || _rects$anchorName === void 0 ? void 0 : _rects$anchorName.height;
74
+ }
75
+ }, {
76
+ key: "getWidth",
77
+ value: function getWidth(anchorName) {
78
+ var _rects$anchorName2;
79
+ if (this.isAnchorSupported) {
80
+ return null;
81
+ }
82
+ var rects = this.getRects();
83
+ return (_rects$anchorName2 = rects[anchorName]) === null || _rects$anchorName2 === void 0 ? void 0 : _rects$anchorName2.width;
84
+ }
85
+ }, {
86
+ key: "getLeft",
87
+ value: function getLeft(anchorName) {
88
+ var _rects$anchorName3;
89
+ if (this.isAnchorSupported) {
90
+ return null;
91
+ }
92
+ var rects = this.getRects();
93
+ return (_rects$anchorName3 = rects[anchorName]) === null || _rects$anchorName3 === void 0 ? void 0 : _rects$anchorName3.left;
94
+ }
95
+ }, {
96
+ key: "getTop",
97
+ value: function getTop(anchorName) {
98
+ var _rects$anchorName4;
99
+ if (this.isAnchorSupported) {
100
+ return null;
101
+ }
102
+ var rects = this.getRects();
103
+ return (_rects$anchorName4 = rects[anchorName]) === null || _rects$anchorName4 === void 0 ? void 0 : _rects$anchorName4.top;
104
+ }
105
+ }, {
106
+ key: "getRight",
107
+ value: function getRight(anchorName) {
108
+ var _rects$anchorName5;
109
+ if (this.isAnchorSupported) {
110
+ return null;
111
+ }
112
+ var rects = this.getRects();
113
+ return (_rects$anchorName5 = rects[anchorName]) === null || _rects$anchorName5 === void 0 ? void 0 : _rects$anchorName5.right;
114
+ }
115
+ }, {
116
+ key: "getRect",
117
+ value: function getRect(anchorName) {
118
+ if (this.isAnchorSupported) {
119
+ return null;
120
+ }
121
+ var rects = this.getRects();
122
+ return rects[anchorName];
67
123
  }
68
124
  }]);
69
- return AnchorHeightsCache;
125
+ return AnchorRectCache;
70
126
  }();
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shouldAllowInlineDropTarget = void 0;
7
+ var _utils = require("@atlaskit/editor-common/utils");
8
+ var _consts = require("../consts");
9
+ var _advancedLayoutsFlags = require("./advanced-layouts-flags");
10
+ var shouldAllowInlineDropTarget = exports.shouldAllowInlineDropTarget = function shouldAllowInlineDropTarget(isNested, node) {
11
+ if (!(0, _advancedLayoutsFlags.isPreRelease1)() || isNested) {
12
+ return false;
13
+ }
14
+ if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutSection') {
15
+ return node.childCount < _consts.MAX_LAYOUT_COLUMN_SUPPORTED;
16
+ }
17
+ return !(0, _utils.isEmptyParagraph)(node);
18
+ };
@@ -0,0 +1,69 @@
1
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
+ import { DEFAULT_COLUMN_DISTRIBUTIONS } from '../ui/consts';
3
+ const createNewLayout = (schema, layoutContents) => {
4
+ // TODO update with constant
5
+ if (layoutContents.length === 0 || layoutContents.length > 5) {
6
+ return null;
7
+ }
8
+ const width = DEFAULT_COLUMN_DISTRIBUTIONS[layoutContents.length];
9
+ if (!width) {
10
+ return null;
11
+ }
12
+ const {
13
+ layoutSection,
14
+ layoutColumn
15
+ } = schema.nodes || {};
16
+ try {
17
+ const layoutSectionNode = layoutSection.createChecked(undefined, Fragment.fromArray(layoutContents.map(layoutContent => {
18
+ return layoutColumn.createChecked({
19
+ width
20
+ }, layoutContent);
21
+ })));
22
+ return layoutSectionNode;
23
+ } catch (error) {
24
+ // TODO analytics
25
+ }
26
+ return null;
27
+ };
28
+ export const moveToLayout = api => (from, to, position) => ({
29
+ tr
30
+ }) => {
31
+ const {
32
+ layoutSection,
33
+ layoutColumn,
34
+ doc
35
+ } = tr.doc.type.schema.nodes || {};
36
+
37
+ // layout plugin does not exist
38
+ if (!layoutSection || !layoutColumn) {
39
+ return tr;
40
+ }
41
+ const $to = tr.doc.resolve(to);
42
+
43
+ // invalid to position or not top level.
44
+ if (!$to.nodeAfter || $to.parent.type !== doc) {
45
+ return tr;
46
+ }
47
+ const $from = tr.doc.resolve(from);
48
+
49
+ // invalid from position
50
+ if (!$from.nodeAfter) {
51
+ return tr;
52
+ }
53
+ const toNode = $to.nodeAfter;
54
+ const fromNode = $from.nodeAfter;
55
+ const fromNodeEndPos = from + fromNode.nodeSize;
56
+ const toNodeEndPos = to + toNode.nodeSize;
57
+ if ($to.nodeAfter.type !== layoutSection) {
58
+ const layoutContents = position === 'left' ? [fromNode, toNode] : [toNode, fromNode];
59
+ const newLayout = createNewLayout(tr.doc.type.schema, layoutContents);
60
+ if (newLayout) {
61
+ tr.delete(from, fromNodeEndPos);
62
+ const mappedTo = tr.mapping.map(to);
63
+ tr.delete(mappedTo, toNodeEndPos);
64
+ tr.insert(mappedTo, newLayout); // insert the content at the new position
65
+ }
66
+ return tr;
67
+ }
68
+ return tr;
69
+ };
@@ -4,4 +4,5 @@ export let DIRECTION = /*#__PURE__*/function (DIRECTION) {
4
4
  DIRECTION["LEFT"] = "left";
5
5
  DIRECTION["RIGHT"] = "right";
6
6
  return DIRECTION;
7
- }({});
7
+ }({});
8
+ export const MAX_LAYOUT_COLUMN_SUPPORTED = 3;
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
4
  import { moveNode } from './commands/move-node';
5
+ import { moveToLayout } from './commands/move-to-layout';
5
6
  import { createEmptyBlockExperimentPlugin } from './pm-plugins/empty-block-experiment';
6
7
  import { createPlugin, key } from './pm-plugins/main';
7
8
  import { DragHandleMenu } from './ui/drag-handle-menu';
@@ -28,6 +29,7 @@ export const blockControlsPlugin = ({
28
29
  },
29
30
  commands: {
30
31
  moveNode: moveNode(api),
32
+ moveToLayout: moveToLayout(api),
31
33
  showDragHandleAt: (pos, anchorName, nodeType, handleOptions) => ({
32
34
  tr
33
35
  }) => {
@@ -110,7 +110,7 @@ export const findNodeDecs = (decorations, from, to) => {
110
110
  }
111
111
  return decorations.find(newfrom, newTo, spec => spec.type === TYPE_NODE_DEC);
112
112
  };
113
- export const createDropTargetDecoration = (pos, props, side, anchorHeightsCache) => {
113
+ export const createDropTargetDecoration = (pos, props, side, anchorRectCache) => {
114
114
  return Decoration.widget(pos, (_, getPos) => {
115
115
  const element = document.createElement('div');
116
116
  element.setAttribute('data-blocks-drop-target-container', 'true');
@@ -127,7 +127,7 @@ export const createDropTargetDecoration = (pos, props, side, anchorHeightsCache)
127
127
  ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, {
128
128
  ...props,
129
129
  getPos,
130
- anchorHeightsCache
130
+ anchorRectCache
131
131
  }), element);
132
132
  } else {
133
133
  ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
@@ -141,7 +141,7 @@ export const createDropTargetDecoration = (pos, props, side, anchorHeightsCache)
141
141
  side
142
142
  });
143
143
  };
144
- export const dropTargetDecorations = (newState, api, formatMessage, activeNode, anchorHeightsCache, from, to) => {
144
+ export const dropTargetDecorations = (newState, api, formatMessage, activeNode, anchorRectCache, from, to) => {
145
145
  unmountDecorations('data-blocks-drop-target-container');
146
146
  const decs = [];
147
147
  const POS_END_OF_DOC = newState.doc.nodeSize - 2;
@@ -150,7 +150,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
150
150
  let prevNode;
151
151
  const activeNodePos = activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos;
152
152
  const activePMNode = typeof activeNodePos === 'number' && newState.doc.resolve(activeNodePos).nodeAfter;
153
- anchorHeightsCache === null || anchorHeightsCache === void 0 ? void 0 : anchorHeightsCache.clear();
153
+ anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.clear();
154
154
  const prevNodeStack = [];
155
155
  const popNodeStack = depth => {
156
156
  let result;
@@ -215,7 +215,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
215
215
  parentNode: parent || undefined,
216
216
  formatMessage,
217
217
  dropTargetStyle: shouldShowFullHeight ? 'fullHeight' : 'default'
218
- }, -1, anchorHeightsCache));
218
+ }, -1, anchorRectCache));
219
219
  if (endPos !== undefined) {
220
220
  decs.push(createDropTargetDecoration(endPos, {
221
221
  api,
@@ -223,7 +223,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
223
223
  parentNode: parent || undefined,
224
224
  formatMessage,
225
225
  dropTargetStyle: isInSupportedContainer ? 'fullHeight' : 'default'
226
- }, -1, anchorHeightsCache));
226
+ }, -1, anchorRectCache));
227
227
  }
228
228
  if (fg('platform_editor_drag_and_drop_target_v2')) {
229
229
  pushNodeStack(node, depth);
@@ -238,7 +238,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
238
238
  formatMessage,
239
239
  prevNode: newState.doc.lastChild || undefined,
240
240
  parentNode: newState.doc
241
- }, undefined, anchorHeightsCache));
241
+ }, undefined, anchorRectCache));
242
242
  }
243
243
  return decs;
244
244
  };
@@ -11,7 +11,7 @@ import { autoScrollForElements } from '@atlaskit/pragmatic-drag-and-drop-auto-sc
11
11
  import { combine } from '@atlaskit/pragmatic-drag-and-drop/combine';
12
12
  import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
13
13
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
- import { AnchorHeightsCache, isAnchorSupported } from '../utils/anchor-utils';
14
+ import { AnchorRectCache, isAnchorSupported } from '../utils/anchor-utils';
15
15
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
16
16
  import { getTrMetadata } from '../utils/transactions';
17
17
  import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, findDropTargetDecs, findHandleDec, findNodeDecs, nodeDecorations } from './decorations';
@@ -89,7 +89,7 @@ const initialState = {
89
89
  isDocSizeLimitEnabled: null,
90
90
  isPMDragging: false
91
91
  };
92
- export const newApply = (api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache) => {
92
+ export const newApply = (api, formatMessage, tr, currentState, newState, flags, anchorRectCache) => {
93
93
  var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
94
94
  let {
95
95
  activeNode,
@@ -198,7 +198,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
198
198
  // Add drop targets when dragging starts or some are missing
199
199
  if (api) {
200
200
  if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || isBlocksDragTargetDebug()) {
201
- const decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorHeightsCache);
201
+ const decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorRectCache);
202
202
  decorations = decorations.add(newState.doc, decs);
203
203
  }
204
204
  }
@@ -223,7 +223,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
223
223
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
224
224
  };
225
225
  };
226
- export const oldApply = (api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache) => {
226
+ export const oldApply = (api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache) => {
227
227
  var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
228
228
  const {
229
229
  isNestedEnabled
@@ -367,7 +367,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
367
367
  // if the transaction is only for analytics and user is dragging, continue to draw drop targets
368
368
  if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
369
369
  var _meta$activeNode7;
370
- const decs = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorHeightsCache);
370
+ const decs = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorRectCache);
371
371
  decorations = decorations.add(newState.doc, decs);
372
372
  }
373
373
  }
@@ -409,9 +409,9 @@ export const createPlugin = (api, getIntl) => {
409
409
  if (fg('platform_editor_element_dnd_nested_fix_patch_2')) {
410
410
  // TODO: Remove this once FG is used in code
411
411
  }
412
- let anchorHeightsCache;
412
+ let anchorRectCache;
413
413
  if (!isAnchorSupported() && fg('platform_editor_drag_and_drop_target_v2')) {
414
- anchorHeightsCache = new AnchorHeightsCache();
414
+ anchorRectCache = new AnchorRectCache();
415
415
  }
416
416
  return new SafePlugin({
417
417
  key,
@@ -421,9 +421,9 @@ export const createPlugin = (api, getIntl) => {
421
421
  },
422
422
  apply(tr, currentState, oldState, newState) {
423
423
  if (isOptimisedApply) {
424
- return newApply(api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache);
424
+ return newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache);
425
425
  }
426
- return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache);
426
+ return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache);
427
427
  }
428
428
  },
429
429
  props: {
@@ -475,8 +475,8 @@ export const createPlugin = (api, getIntl) => {
475
475
  return false;
476
476
  },
477
477
  dragstart(view) {
478
- var _anchorHeightsCache;
479
- (_anchorHeightsCache = anchorHeightsCache) === null || _anchorHeightsCache === void 0 ? void 0 : _anchorHeightsCache.setEditorView(view);
478
+ var _anchorRectCache;
479
+ (_anchorRectCache = anchorRectCache) === null || _anchorRectCache === void 0 ? void 0 : _anchorRectCache.setEditorView(view);
480
480
  view.dispatch(view.state.tr.setMeta(key, {
481
481
  isPMDragging: true
482
482
  }));
@@ -175,4 +175,11 @@ export const nodeMargins = {
175
175
  top: 0,
176
176
  bottom: 0
177
177
  }
178
+ };
179
+ export const DEFAULT_COLUMN_DISTRIBUTIONS = {
180
+ 1: 100,
181
+ 2: 50,
182
+ 3: 33.33,
183
+ 4: 25,
184
+ 5: 20
178
185
  };
@@ -1,3 +1,4 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
1
2
  /**
2
3
  * @jsxRuntime classic
3
4
  * @jsx jsx
@@ -14,7 +15,9 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
14
15
  import { getNodeAnchor } from '../pm-plugins/decorations';
15
16
  import { isAnchorSupported } from '../utils/anchor-utils';
16
17
  import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
18
+ import { shouldAllowInlineDropTarget } from '../utils/inline-drop-target';
17
19
  import { getNestedNodeLeftPaddingMargin } from './consts';
20
+ import { InlineDropTarget } from './inline-drop-target';
18
21
  const DEFAULT_DROP_INDICATOR_WIDTH = 760;
19
22
  const EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_WIDTH = '--editor-block-controls-drop-indicator-width';
20
23
  const EDITOR_BLOCK_CONTROLS_DROP_TARGET_LEFT_MARGIN = '--editor-block-controls-drop-target-leftMargin';
@@ -70,7 +73,7 @@ const HoverZone = ({
70
73
  node,
71
74
  parent,
72
75
  editorWidth,
73
- anchorHeightsCache,
76
+ anchorRectCache,
74
77
  position,
75
78
  isNestedDropTarget,
76
79
  dropTargetStyle
@@ -90,7 +93,7 @@ const HoverZone = ({
90
93
  const anchorName = node ? getNodeAnchor(node) : '';
91
94
  const heightStyleOffset = `var(--editor-block-controls-drop-indicator-gap, 0)/2`;
92
95
  const transformOffset = `var(${EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET}, 0)`;
93
- const heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? `calc(anchor-size(${anchorName} height)/2 + ${heightStyleOffset})` : `calc(${((anchorHeightsCache === null || anchorHeightsCache === void 0 ? void 0 : anchorHeightsCache.getHeight(anchorName)) || 0) / 2}px + ${heightStyleOffset})` : '4px';
96
+ const heightStyle = anchorName && enableDropZone.includes((node === null || node === void 0 ? void 0 : node.type.name) || '') ? isAnchorSupported() ? `calc(anchor-size(${anchorName} height)/2 + ${heightStyleOffset})` : `calc(${((anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0) / 2}px + ${heightStyleOffset})` : '4px';
94
97
  const transform = position === 'upper' ? `translateY(calc(-100% + ${transformOffset}))` : `translateY(${transformOffset})`;
95
98
  return css({
96
99
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
@@ -100,7 +103,7 @@ const HoverZone = ({
100
103
  // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-values
101
104
  maxWidth: `${editorWidth || 0}px`
102
105
  });
103
- }, [anchorHeightsCache, editorWidth, node, position]);
106
+ }, [anchorRectCache, editorWidth, node, position]);
104
107
  const isFullHeight = useMemo(() => {
105
108
  return dropTargetStyle === 'fullHeight';
106
109
  }, [dropTargetStyle]);
@@ -120,16 +123,17 @@ const HoverZone = ({
120
123
  hoverZoneUpperStyle, isFullHeight && fullHeightStyle, isFullHeightInLayout && fullHeightStyleAdjustZIndexStyle]
121
124
  });
122
125
  };
123
- export const DropTargetV2 = ({
124
- api,
125
- getPos,
126
- prevNode,
127
- nextNode,
128
- parentNode,
129
- formatMessage,
130
- anchorHeightsCache,
131
- dropTargetStyle
132
- }) => {
126
+ export const DropTargetV2 = props => {
127
+ const {
128
+ api,
129
+ getPos,
130
+ prevNode,
131
+ nextNode,
132
+ parentNode,
133
+ formatMessage,
134
+ anchorRectCache,
135
+ dropTargetStyle
136
+ } = props;
133
137
  const [isDraggedOver, setIsDraggedOver] = useState(false);
134
138
  const {
135
139
  widthState
@@ -165,7 +169,7 @@ export const DropTargetV2 = ({
165
169
  onDrop: onDrop,
166
170
  node: prevNode,
167
171
  editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
168
- anchorHeightsCache: anchorHeightsCache,
172
+ anchorRectCache: anchorRectCache,
169
173
  position: "upper",
170
174
  isNestedDropTarget: isNestedDropTarget
171
175
  }), jsx("div", {
@@ -189,9 +193,13 @@ export const DropTargetV2 = ({
189
193
  node: nextNode,
190
194
  parent: parentNode,
191
195
  editorWidth: widthState === null || widthState === void 0 ? void 0 : widthState.lineLength,
192
- anchorHeightsCache: anchorHeightsCache,
196
+ anchorRectCache: anchorRectCache,
193
197
  position: "lower",
194
198
  isNestedDropTarget: isNestedDropTarget,
195
199
  dropTargetStyle: dropTargetStyle
196
- }));
200
+ }), shouldAllowInlineDropTarget(isNestedDropTarget, nextNode) && jsx(Fragment, null, jsx(InlineDropTarget, _extends({}, props, {
201
+ position: "left"
202
+ })), jsx(InlineDropTarget, _extends({}, props, {
203
+ position: "right"
204
+ }))));
197
205
  };
@@ -0,0 +1,130 @@
1
+ /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
2
+ /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
3
+ /**
4
+ * @jsxRuntime classic
5
+ * @jsx jsx
6
+ */
7
+ import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8
+
9
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
10
+ import { css, jsx } from '@emotion/react';
11
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
+ import { DropIndicator } from '@atlaskit/pragmatic-drag-and-drop-react-drop-indicator/box';
13
+ import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
14
+ import { getNodeAnchor } from '../pm-plugins/decorations';
15
+ import { isAnchorSupported } from '../utils/anchor-utils';
16
+ const dropTargetCommonStyle = css({
17
+ position: 'absolute',
18
+ display: 'block'
19
+ });
20
+ const hideDropTargetStyle = css({
21
+ display: 'none'
22
+ });
23
+ const hoverZoneCommonStyle = css({
24
+ position: 'absolute',
25
+ // same value as block hover zone
26
+ zIndex: 110
27
+ });
28
+
29
+ // gap between node boundary and drop indicator/drop zone
30
+ const GAP = 4;
31
+ const HOVER_ZONE_WIDTH_OFFSET = 40;
32
+ const HOVER_ZONE_HEIGHT_OFFSET = 10;
33
+ const HOVER_ZONE_DEFAULT_WIDTH = 40;
34
+ export const InlineDropTarget = ({
35
+ api,
36
+ nextNode,
37
+ position,
38
+ anchorRectCache
39
+ }) => {
40
+ const {
41
+ widthState
42
+ } = useSharedPluginState(api, ['width']);
43
+ const [isDraggedOver, setIsDraggedOver] = useState(false);
44
+ const anchorName = nextNode ? getNodeAnchor(nextNode) : '';
45
+ const handleDragEnter = useCallback(() => {
46
+ setIsDraggedOver(true);
47
+ }, []);
48
+ const handleDragLeave = useCallback(() => {
49
+ setIsDraggedOver(false);
50
+ }, []);
51
+ const dropTargetRectStyle = useMemo(() => {
52
+ if (isAnchorSupported()) {
53
+ return css({
54
+ height: `calc(anchor-size(${anchorName} height))`,
55
+ positionAnchor: anchorName,
56
+ left: position === 'left' ? `calc(anchor(left) - ${GAP}px)` : `calc(anchor(right) + ${GAP}px)`,
57
+ top: `calc(anchor(top))`
58
+ });
59
+ }
60
+ const nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
61
+ return css({
62
+ height: `calc(${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.height) || 0}px)`,
63
+ left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - GAP}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP}px`,
64
+ top: `${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0}px`
65
+ });
66
+ }, [anchorName, anchorRectCache, position]);
67
+ return jsx(Fragment, null, jsx("div", {
68
+ "data-test-id": `block-ctrl-drop-target-${position}`,
69
+ css: [dropTargetCommonStyle, dropTargetRectStyle, !isDraggedOver && hideDropTargetStyle]
70
+ }, jsx(DropIndicator, {
71
+ edge: position
72
+ })), jsx(InlineHoverZone, {
73
+ position: position,
74
+ node: nextNode,
75
+ editorWidthState: widthState,
76
+ anchorRectCache: anchorRectCache,
77
+ onDragEnter: handleDragEnter,
78
+ onDragLeave: handleDragLeave,
79
+ onDrop: () => {}
80
+ }));
81
+ };
82
+ export const InlineHoverZone = ({
83
+ node,
84
+ editorWidthState,
85
+ anchorRectCache,
86
+ position,
87
+ onDragEnter,
88
+ onDragLeave,
89
+ onDrop
90
+ }) => {
91
+ const ref = useRef(null);
92
+ const {
93
+ width: editorWith
94
+ } = editorWidthState || {};
95
+ const anchorName = node ? getNodeAnchor(node) : '';
96
+ useEffect(() => {
97
+ if (ref.current) {
98
+ return dropTargetForElements({
99
+ element: ref.current,
100
+ onDragEnter,
101
+ onDragLeave,
102
+ onDrop
103
+ });
104
+ }
105
+ }, [onDragEnter, onDragLeave, onDrop]);
106
+ const inlineHoverZoneRectStyle = useMemo(() => {
107
+ if (isAnchorSupported()) {
108
+ return css({
109
+ positionAnchor: anchorName,
110
+ left: position === 'left' ? 'unset' : `calc(anchor(right) + ${GAP}px)`,
111
+ right: position === 'left' ? `calc(anchor(left) + ${GAP}px)` : 'unset',
112
+ top: `calc(anchor(top))`,
113
+ width: editorWith ? `calc((${editorWith}px - anchor-size(${anchorName} width))/2 - ${HOVER_ZONE_WIDTH_OFFSET}px)` : `${HOVER_ZONE_DEFAULT_WIDTH}px`,
114
+ height: `calc(anchor-size(${anchorName} height))`
115
+ });
116
+ }
117
+ const nodeRect = anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getRect(anchorName);
118
+ const width = editorWith ? (editorWith - ((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.width) || 0)) / 2 - HOVER_ZONE_WIDTH_OFFSET : HOVER_ZONE_DEFAULT_WIDTH;
119
+ return css({
120
+ left: position === 'left' ? `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.left) || 0) - width - GAP}px` : `${((nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.right) || 0) + GAP}px`,
121
+ top: `${(nodeRect === null || nodeRect === void 0 ? void 0 : nodeRect.top) || 0}px`,
122
+ width: `${width}px`,
123
+ height: `calc(${(anchorRectCache === null || anchorRectCache === void 0 ? void 0 : anchorRectCache.getHeight(anchorName)) || 0}px - ${HOVER_ZONE_HEIGHT_OFFSET}px)`
124
+ });
125
+ }, [anchorName, anchorRectCache, editorWith, position]);
126
+ return jsx("div", {
127
+ ref: ref,
128
+ css: [hoverZoneCommonStyle, inlineHoverZoneRectStyle]
129
+ });
130
+ };
@@ -0,0 +1,5 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+ export const isPreRelease1 = () => {
4
+ return editorExperiment('advanced_layouts', true) || fg('platform_editor_advanced_layouts_pre_release_1');
5
+ };