@atlaskit/editor-plugin-block-controls 2.13.21 → 2.13.23

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 (28) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/plugin.js +3 -2
  3. package/dist/cjs/pm-plugins/decorations-common.js +10 -2
  4. package/dist/cjs/pm-plugins/decorations-drag-handle.js +29 -12
  5. package/dist/cjs/pm-plugins/decorations-drop-target.js +52 -20
  6. package/dist/cjs/pm-plugins/handle-mouse-over.js +8 -2
  7. package/dist/cjs/pm-plugins/main.js +14 -14
  8. package/dist/es2019/plugin.js +3 -2
  9. package/dist/es2019/pm-plugins/decorations-common.js +10 -2
  10. package/dist/es2019/pm-plugins/decorations-drag-handle.js +27 -12
  11. package/dist/es2019/pm-plugins/decorations-drop-target.js +52 -23
  12. package/dist/es2019/pm-plugins/handle-mouse-over.js +8 -2
  13. package/dist/es2019/pm-plugins/main.js +14 -14
  14. package/dist/esm/plugin.js +3 -2
  15. package/dist/esm/pm-plugins/decorations-common.js +10 -2
  16. package/dist/esm/pm-plugins/decorations-drag-handle.js +29 -12
  17. package/dist/esm/pm-plugins/decorations-drop-target.js +52 -20
  18. package/dist/esm/pm-plugins/handle-mouse-over.js +8 -2
  19. package/dist/esm/pm-plugins/main.js +14 -14
  20. package/dist/types/pm-plugins/decorations-common.d.ts +2 -1
  21. package/dist/types/pm-plugins/decorations-drag-handle.d.ts +2 -1
  22. package/dist/types/pm-plugins/decorations-drop-target.d.ts +4 -3
  23. package/dist/types/pm-plugins/main.d.ts +4 -3
  24. package/dist/types-ts4.5/pm-plugins/decorations-common.d.ts +2 -1
  25. package/dist/types-ts4.5/pm-plugins/decorations-drag-handle.d.ts +2 -1
  26. package/dist/types-ts4.5/pm-plugins/decorations-drop-target.d.ts +4 -3
  27. package/dist/types-ts4.5/pm-plugins/main.d.ts +4 -3
  28. package/package.json +5 -2
@@ -1,5 +1,6 @@
1
1
  import { createElement } from 'react';
2
2
  import ReactDOM from 'react-dom';
3
+ import uuid from 'uuid';
3
4
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
4
5
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
6
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -76,10 +77,12 @@ const getGapAndOffset = (prevNode, nextNode, parentNode) => {
76
77
  export const findDropTargetDecs = (decorations, from, to) => {
77
78
  return decorations.find(from, to, spec => spec.type === TYPE_DROP_TARGET_DEC);
78
79
  };
79
- export const createDropTargetDecoration = (pos, props, side, anchorRectCache, isSameLayout) => {
80
+ export const createDropTargetDecoration = (pos, props, nodeViewPortalProviderAPI, side, anchorRectCache, isSameLayout) => {
81
+ const key = uuid();
80
82
  return Decoration.widget(pos, (_, getPos) => {
81
83
  const element = document.createElement('div');
82
84
  element.setAttribute('data-blocks-drop-target-container', 'true');
85
+ element.setAttribute('data-blocks-drop-target-key', key);
83
86
  element.style.clear = 'unset';
84
87
  if (fg('platform_editor_drag_and_drop_target_v2')) {
85
88
  const {
@@ -89,17 +92,33 @@ export const createDropTargetDecoration = (pos, props, side, anchorRectCache, is
89
92
  element.style.setProperty(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, `${offset}px`);
90
93
  element.style.setProperty(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, `${gap}px`);
91
94
  element.style.setProperty('display', 'block');
92
- ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, {
93
- ...props,
94
- getPos,
95
- anchorRectCache,
96
- isSameLayout
97
- }), element);
95
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
96
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/createElement(DropTargetV2, {
97
+ ...props,
98
+ getPos,
99
+ anchorRectCache,
100
+ isSameLayout
101
+ }), element, key);
102
+ } else {
103
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, {
104
+ ...props,
105
+ getPos,
106
+ anchorRectCache,
107
+ isSameLayout
108
+ }), element);
109
+ }
98
110
  } else {
99
- ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
100
- ...props,
101
- getPos
102
- }), element);
111
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
112
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/createElement(DropTarget, {
113
+ ...props,
114
+ getPos
115
+ }), element, key);
116
+ } else {
117
+ ReactDOM.render( /*#__PURE__*/createElement(DropTarget, {
118
+ ...props,
119
+ getPos
120
+ }), element);
121
+ }
103
122
  }
104
123
  return element;
105
124
  }, {
@@ -107,23 +126,33 @@ export const createDropTargetDecoration = (pos, props, side, anchorRectCache, is
107
126
  side
108
127
  });
109
128
  };
110
- export const createLayoutDropTargetDecoration = (pos, props, anchorRectCache) => {
129
+ export const createLayoutDropTargetDecoration = (pos, props, nodeViewPortalProviderAPI, anchorRectCache) => {
130
+ const key = uuid();
111
131
  return Decoration.widget(pos, (_, getPos) => {
112
132
  const element = document.createElement('div');
113
133
  element.setAttribute('data-blocks-drop-target-container', 'true');
134
+ element.setAttribute('data-blocks-drop-target-key', key);
114
135
  element.style.clear = 'unset';
115
- ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, {
116
- ...props,
117
- getPos,
118
- anchorRectCache
119
- }), element);
136
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
137
+ nodeViewPortalProviderAPI.render(() => /*#__PURE__*/createElement(DropTargetLayout, {
138
+ ...props,
139
+ getPos,
140
+ anchorRectCache
141
+ }), element, key);
142
+ } else {
143
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, {
144
+ ...props,
145
+ getPos,
146
+ anchorRectCache
147
+ }), element);
148
+ }
120
149
  return element;
121
150
  }, {
122
151
  type: TYPE_DROP_TARGET_DEC
123
152
  });
124
153
  };
125
- export const dropTargetDecorations = (newState, api, formatMessage, activeNode, anchorRectCache, from, to) => {
126
- unmountDecorations('data-blocks-drop-target-container');
154
+ export const dropTargetDecorations = (newState, api, formatMessage, nodeViewPortalProviderAPI, activeNode, anchorRectCache, from, to) => {
155
+ unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drop-target-container', 'data-blocks-drop-target-key');
127
156
  const decs = [];
128
157
  const POS_END_OF_DOC = newState.doc.nodeSize - 2;
129
158
  const docFrom = from === undefined || from < 0 ? 0 : from;
@@ -167,7 +196,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
167
196
  api,
168
197
  parent,
169
198
  formatMessage
170
- }, anchorRectCache));
199
+ }, nodeViewPortalProviderAPI, anchorRectCache));
171
200
  }
172
201
  }
173
202
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
@@ -213,7 +242,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
213
242
  parentNode: parent || undefined,
214
243
  formatMessage,
215
244
  dropTargetStyle: shouldShowFullHeight ? 'remainingHeight' : 'default'
216
- }, -1, anchorRectCache, isSameLayout));
245
+ }, nodeViewPortalProviderAPI, -1, anchorRectCache, isSameLayout));
217
246
  if (endPos !== undefined) {
218
247
  decs.push(createDropTargetDecoration(endPos, {
219
248
  api,
@@ -221,7 +250,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
221
250
  parentNode: parent || undefined,
222
251
  formatMessage,
223
252
  dropTargetStyle: 'remainingHeight'
224
- }, -1, anchorRectCache));
253
+ }, nodeViewPortalProviderAPI, -1, anchorRectCache));
225
254
  }
226
255
  if (fg('platform_editor_drag_and_drop_target_v2')) {
227
256
  pushNodeStack(node, depth);
@@ -236,7 +265,7 @@ export const dropTargetDecorations = (newState, api, formatMessage, activeNode,
236
265
  formatMessage,
237
266
  prevNode: newState.doc.lastChild || undefined,
238
267
  parentNode: newState.doc
239
- }, undefined, anchorRectCache));
268
+ }, nodeViewPortalProviderAPI, undefined, anchorRectCache));
240
269
  }
241
270
  return decs;
242
271
  };
@@ -8,13 +8,19 @@ const isEmptyNestedParagraphOrHeading = target => {
8
8
  }
9
9
  return false;
10
10
  };
11
+ const isEmptyParagraphOrPlaceholder = node => {
12
+ if (node && node.type.name === 'paragraph') {
13
+ var _node$firstChild;
14
+ return node.childCount === 0 || node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'placeholder';
15
+ }
16
+ return false;
17
+ };
11
18
  const isLayoutColumnWithoutContent = node => {
12
19
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
13
20
  let foundNonEmptyNode = false;
14
21
  for (let i = 0; i < node.childCount; i++) {
15
- var _child$firstChild;
16
22
  const child = node.child(i);
17
- if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
23
+ if (!isEmptyParagraphOrPlaceholder(child)) {
18
24
  foundNonEmptyNode = true;
19
25
  break;
20
26
  }
@@ -93,7 +93,7 @@ const initialState = {
93
93
  isDocSizeLimitEnabled: null,
94
94
  isPMDragging: false
95
95
  };
96
- export const newApply = (api, formatMessage, tr, currentState, newState, flags, anchorRectCache) => {
96
+ export const newApply = (api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache) => {
97
97
  var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
98
98
  let {
99
99
  activeNode,
@@ -186,7 +186,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
186
186
  var _activeNode5, _activeNode6;
187
187
  const oldHandle = findHandleDec(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
188
188
  decorations = decorations.remove(oldHandle);
189
- const handleDec = dragHandleDecoration(api, formatMessage, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.anchorName, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.nodeType, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.handleOptions);
189
+ const handleDec = dragHandleDecoration(api, formatMessage, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.anchorName, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.nodeType, nodeViewPortalProviderAPI, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.handleOptions);
190
190
  decorations = decorations.add(newState.doc, [handleDec]);
191
191
  }
192
192
 
@@ -194,7 +194,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
194
194
  const isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) && maybeNodeCountChanged && !(meta !== null && meta !== void 0 && meta.nodeMoved);
195
195
 
196
196
  // Remove drop target decorations when dragging stops or they need to be redrawn
197
- if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
197
+ if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing || isBlocksDragTargetDebug()) {
198
198
  const dropTargetDecs = findDropTargetDecs(decorations);
199
199
  decorations = decorations.remove(dropTargetDecs);
200
200
  }
@@ -202,7 +202,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
202
202
  // Add drop targets when dragging starts or some are missing
203
203
  if (api) {
204
204
  if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || isBlocksDragTargetDebug()) {
205
- const decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorRectCache);
205
+ const decs = dropTargetDecorations(newState, api, formatMessage, nodeViewPortalProviderAPI, latestActiveNode, anchorRectCache);
206
206
  decorations = decorations.add(newState.doc, decs);
207
207
  }
208
208
  }
@@ -227,7 +227,7 @@ export const newApply = (api, formatMessage, tr, currentState, newState, flags,
227
227
  isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
228
228
  };
229
229
  };
230
- export const oldApply = (api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache) => {
230
+ export const oldApply = (api, formatMessage, tr, currentState, oldState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache) => {
231
231
  var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
232
232
  const {
233
233
  isNestedEnabled
@@ -319,7 +319,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
319
319
  decorations = decorations.remove(oldHandle);
320
320
  }
321
321
  const decAtPos = newNodeDecs.find(dec => dec.from === mappedPosisiton);
322
- draghandleDec = dragHandleDecoration(api, formatMessage, (_meta$activeNode$pos = meta === null || meta === void 0 ? void 0 : (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref = (_meta$activeNode$anch = meta === null || meta === void 0 ? void 0 : (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 ? void 0 : (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref !== void 0 ? _ref : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref2 = (_meta$activeNode$node = meta === null || meta === void 0 ? void 0 : (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 ? void 0 : (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref2 !== void 0 ? _ref2 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, meta === null || meta === void 0 ? void 0 : (_meta$activeNode6 = meta.activeNode) === null || _meta$activeNode6 === void 0 ? void 0 : _meta$activeNode6.handleOptions);
322
+ draghandleDec = dragHandleDecoration(api, formatMessage, (_meta$activeNode$pos = meta === null || meta === void 0 ? void 0 : (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref = (_meta$activeNode$anch = meta === null || meta === void 0 ? void 0 : (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 ? void 0 : (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref !== void 0 ? _ref : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref2 = (_meta$activeNode$node = meta === null || meta === void 0 ? void 0 : (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 ? void 0 : (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref2 !== void 0 ? _ref2 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, nodeViewPortalProviderAPI, meta === null || meta === void 0 ? void 0 : (_meta$activeNode6 = meta.activeNode) === null || _meta$activeNode6 === void 0 ? void 0 : _meta$activeNode6.handleOptions);
323
323
  } else {
324
324
  let nodeType = activeNode.nodeType;
325
325
  let anchorName = activeNode.anchorName;
@@ -332,7 +332,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
332
332
  anchorName
333
333
  };
334
334
  }
335
- draghandleDec = dragHandleDecoration(api, formatMessage, activeNode.pos, anchorName, nodeType);
335
+ draghandleDec = dragHandleDecoration(api, formatMessage, activeNode.pos, anchorName, nodeType, nodeViewPortalProviderAPI);
336
336
  }
337
337
  decorations = decorations.add(newState.doc, [draghandleDec]);
338
338
  }
@@ -342,7 +342,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
342
342
  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$hand2 = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand2 !== void 0 && _meta$activeNode$hand2.isFocused)) {
343
343
  const oldHandle = decorations.find(undefined, undefined, spec => spec.type === 'drag-handle');
344
344
  decorations = decorations.remove(oldHandle);
345
- const decs = dragHandleDecoration(api, formatMessage, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
345
+ const decs = dragHandleDecoration(api, formatMessage, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, nodeViewPortalProviderAPI, meta.activeNode.handleOptions);
346
346
  decorations = decorations.add(newState.doc, [decs]);
347
347
  }
348
348
 
@@ -350,10 +350,10 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
350
350
  if (!isPerformanceFix && activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
351
351
  const oldHandle = decorations.find(undefined, undefined, spec => spec.type === 'drag-handle');
352
352
  decorations = decorations.remove(oldHandle);
353
- const decs = dragHandleDecoration(api, formatMessage, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
353
+ const decs = dragHandleDecoration(api, formatMessage, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType, nodeViewPortalProviderAPI);
354
354
  decorations = decorations.add(newState.doc, [decs]);
355
355
  }
356
- if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
356
+ if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing || isBlocksDragTargetDebug()) {
357
357
  // Remove drop target decoration when dragging stops
358
358
  const dropTargetDecs = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration');
359
359
  decorations = decorations.remove(dropTargetDecs);
@@ -371,7 +371,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
371
371
  // if the transaction is only for analytics and user is dragging, continue to draw drop targets
372
372
  if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
373
373
  var _meta$activeNode7;
374
- 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);
374
+ const decs = dropTargetDecorations(newState, api, formatMessage, nodeViewPortalProviderAPI, 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);
375
375
  decorations = decorations.add(newState.doc, decs);
376
376
  }
377
377
  }
@@ -396,7 +396,7 @@ export const oldApply = (api, formatMessage, tr, currentState, oldState, newStat
396
396
  isPMDragging: (_meta$isPMDragging2 = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging2 !== void 0 ? _meta$isPMDragging2 : isPMDragging
397
397
  };
398
398
  };
399
- export const createPlugin = (api, getIntl) => {
399
+ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
400
400
  const {
401
401
  formatMessage
402
402
  } = getIntl();
@@ -425,9 +425,9 @@ export const createPlugin = (api, getIntl) => {
425
425
  },
426
426
  apply(tr, currentState, oldState, newState) {
427
427
  if (isOptimisedApply) {
428
- return newApply(api, formatMessage, tr, currentState, newState, flags, anchorRectCache);
428
+ return newApply(api, formatMessage, tr, currentState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache);
429
429
  }
430
- return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorRectCache);
430
+ return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, nodeViewPortalProviderAPI, anchorRectCache);
431
431
  }
432
432
  },
433
433
  props: {
@@ -14,8 +14,9 @@ export var blockControlsPlugin = function blockControlsPlugin(_ref) {
14
14
  return [{
15
15
  name: 'blockControlsPmPlugin',
16
16
  plugin: function plugin(_ref2) {
17
- var getIntl = _ref2.getIntl;
18
- return createPlugin(api, getIntl);
17
+ var getIntl = _ref2.getIntl,
18
+ nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
19
+ return createPlugin(api, getIntl, nodeViewPortalProviderAPI);
19
20
  }
20
21
  }];
21
22
  },
@@ -3,6 +3,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import ReactDOM from 'react-dom';
5
5
  import uuid from 'uuid';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
7
8
  export var TYPE_DROP_TARGET_DEC = 'drop-target-decoration';
8
9
  export var TYPE_HANDLE_DEC = 'drag-handle';
@@ -32,11 +33,18 @@ var ObjHash = /*#__PURE__*/function () {
32
33
  return ObjHash;
33
34
  }();
34
35
  _defineProperty(ObjHash, "caching", new WeakMap());
35
- export var unmountDecorations = function unmountDecorations(selector) {
36
+ export var unmountDecorations = function unmountDecorations(nodeViewPortalProviderAPI, selector, key) {
36
37
  // Removing decorations manually instead of using native destroy function in prosemirror API
37
38
  // as it was more responsive and causes less re-rendering
38
39
  var decorationsToRemove = document.querySelectorAll("[".concat(selector, "=\"true\"]"));
39
40
  decorationsToRemove.forEach(function (el) {
40
- ReactDOM.unmountComponentAtNode(el);
41
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
42
+ var nodeKey = el.getAttribute(key);
43
+ if (nodeKey) {
44
+ nodeViewPortalProviderAPI.remove(nodeKey);
45
+ }
46
+ } else {
47
+ ReactDOM.unmountComponentAtNode(el);
48
+ }
41
49
  });
42
50
  };
@@ -22,9 +22,10 @@ export var findHandleDec = function findHandleDec(decorations, from, to) {
22
22
  return spec.type === TYPE_HANDLE_DEC;
23
23
  });
24
24
  };
25
- export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, handleOptions) {
26
- unmountDecorations('data-blocks-drag-handle-container');
25
+ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessage, pos, anchorName, nodeType, nodeViewPortalProviderAPI, handleOptions) {
26
+ unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drag-handle-container', 'data-blocks-drag-handle-key');
27
27
  var unbind;
28
+ var key = uuid();
28
29
  return Decoration.widget(pos, function (view, getPos) {
29
30
  var element = document.createElement('span');
30
31
  // Need to set it to inline to avoid text being split when merging two paragraphs
@@ -32,6 +33,7 @@ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessa
32
33
  element.style.display = fg('platform_editor_element_dnd_nested_fix_patch_2') ? 'block' : 'inline';
33
34
  element.setAttribute('data-testid', 'block-ctrl-decorator-widget');
34
35
  element.setAttribute('data-blocks-drag-handle-container', 'true');
36
+ element.setAttribute('data-blocks-drag-handle-key', key);
35
37
  var isTopLevelNode = true;
36
38
  if (editorExperiment('nested-dnd', true)) {
37
39
  var newPos = fg('platform_editor_element_dnd_nested_fix_patch_3') ? getPos() : pos;
@@ -57,16 +59,31 @@ export var dragHandleDecoration = function dragHandleDecoration(api, formatMessa
57
59
  // There are times when global clear: "both" styles are applied to this decoration causing jumpiness
58
60
  // due to margins applied to other nodes eg. Headings
59
61
  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);
62
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
63
+ nodeViewPortalProviderAPI.render(function () {
64
+ return /*#__PURE__*/createElement(DragHandle, {
65
+ view: view,
66
+ api: api,
67
+ formatMessage: formatMessage,
68
+ getPos: getPos,
69
+ anchorName: anchorName,
70
+ nodeType: nodeType,
71
+ handleOptions: handleOptions,
72
+ isTopLevelNode: isTopLevelNode
73
+ });
74
+ }, element, key);
75
+ } else {
76
+ ReactDOM.render( /*#__PURE__*/createElement(DragHandle, {
77
+ view: view,
78
+ api: api,
79
+ formatMessage: formatMessage,
80
+ getPos: getPos,
81
+ anchorName: anchorName,
82
+ nodeType: nodeType,
83
+ handleOptions: handleOptions,
84
+ isTopLevelNode: isTopLevelNode
85
+ }), element);
86
+ }
70
87
  return element;
71
88
  }, {
72
89
  side: -1,
@@ -3,6 +3,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
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; }
4
4
  import { createElement } from 'react';
5
5
  import ReactDOM from 'react-dom';
6
+ import uuid from 'uuid';
6
7
  import { isEmptyParagraph } from '@atlaskit/editor-common/utils';
7
8
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
8
9
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -81,10 +82,12 @@ export var findDropTargetDecs = function findDropTargetDecs(decorations, from, t
81
82
  return spec.type === TYPE_DROP_TARGET_DEC;
82
83
  });
83
84
  };
84
- export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, side, anchorRectCache, isSameLayout) {
85
+ export var createDropTargetDecoration = function createDropTargetDecoration(pos, props, nodeViewPortalProviderAPI, side, anchorRectCache, isSameLayout) {
86
+ var key = uuid();
85
87
  return Decoration.widget(pos, function (_, getPos) {
86
88
  var element = document.createElement('div');
87
89
  element.setAttribute('data-blocks-drop-target-container', 'true');
90
+ element.setAttribute('data-blocks-drop-target-key', key);
88
91
  element.style.clear = 'unset';
89
92
  if (fg('platform_editor_drag_and_drop_target_v2')) {
90
93
  var _getGapAndOffset = getGapAndOffset(props.prevNode, props.nextNode, props.parentNode),
@@ -93,15 +96,33 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
93
96
  element.style.setProperty(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_OFFSET, "".concat(offset, "px"));
94
97
  element.style.setProperty(EDITOR_BLOCK_CONTROLS_DROP_INDICATOR_GAP, "".concat(gap, "px"));
95
98
  element.style.setProperty('display', 'block');
96
- ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
97
- getPos: getPos,
98
- anchorRectCache: anchorRectCache,
99
- isSameLayout: isSameLayout
100
- })), element);
99
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
100
+ nodeViewPortalProviderAPI.render(function () {
101
+ return /*#__PURE__*/createElement(DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
102
+ getPos: getPos,
103
+ anchorRectCache: anchorRectCache,
104
+ isSameLayout: isSameLayout
105
+ }));
106
+ }, element, key);
107
+ } else {
108
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetV2, _objectSpread(_objectSpread({}, props), {}, {
109
+ getPos: getPos,
110
+ anchorRectCache: anchorRectCache,
111
+ isSameLayout: isSameLayout
112
+ })), element);
113
+ }
101
114
  } else {
102
- ReactDOM.render( /*#__PURE__*/createElement(DropTarget, _objectSpread(_objectSpread({}, props), {}, {
103
- getPos: getPos
104
- })), element);
115
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
116
+ nodeViewPortalProviderAPI.render(function () {
117
+ return /*#__PURE__*/createElement(DropTarget, _objectSpread(_objectSpread({}, props), {}, {
118
+ getPos: getPos
119
+ }));
120
+ }, element, key);
121
+ } else {
122
+ ReactDOM.render( /*#__PURE__*/createElement(DropTarget, _objectSpread(_objectSpread({}, props), {}, {
123
+ getPos: getPos
124
+ })), element);
125
+ }
105
126
  }
106
127
  return element;
107
128
  }, {
@@ -109,22 +130,33 @@ export var createDropTargetDecoration = function createDropTargetDecoration(pos,
109
130
  side: side
110
131
  });
111
132
  };
112
- export var createLayoutDropTargetDecoration = function createLayoutDropTargetDecoration(pos, props, anchorRectCache) {
133
+ export var createLayoutDropTargetDecoration = function createLayoutDropTargetDecoration(pos, props, nodeViewPortalProviderAPI, anchorRectCache) {
134
+ var key = uuid();
113
135
  return Decoration.widget(pos, function (_, getPos) {
114
136
  var element = document.createElement('div');
115
137
  element.setAttribute('data-blocks-drop-target-container', 'true');
138
+ element.setAttribute('data-blocks-drop-target-key', key);
116
139
  element.style.clear = 'unset';
117
- ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, _objectSpread(_objectSpread({}, props), {}, {
118
- getPos: getPos,
119
- anchorRectCache: anchorRectCache
120
- })), element);
140
+ if (fg('platform_editor_react18_plugin_portalprovider')) {
141
+ nodeViewPortalProviderAPI.render(function () {
142
+ return /*#__PURE__*/createElement(DropTargetLayout, _objectSpread(_objectSpread({}, props), {}, {
143
+ getPos: getPos,
144
+ anchorRectCache: anchorRectCache
145
+ }));
146
+ }, element, key);
147
+ } else {
148
+ ReactDOM.render( /*#__PURE__*/createElement(DropTargetLayout, _objectSpread(_objectSpread({}, props), {}, {
149
+ getPos: getPos,
150
+ anchorRectCache: anchorRectCache
151
+ })), element);
152
+ }
121
153
  return element;
122
154
  }, {
123
155
  type: TYPE_DROP_TARGET_DEC
124
156
  });
125
157
  };
126
- export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, activeNode, anchorRectCache, from, to) {
127
- unmountDecorations('data-blocks-drop-target-container');
158
+ export var dropTargetDecorations = function dropTargetDecorations(newState, api, formatMessage, nodeViewPortalProviderAPI, activeNode, anchorRectCache, from, to) {
159
+ unmountDecorations(nodeViewPortalProviderAPI, 'data-blocks-drop-target-container', 'data-blocks-drop-target-key');
128
160
  var decs = [];
129
161
  var POS_END_OF_DOC = newState.doc.nodeSize - 2;
130
162
  var docFrom = from === undefined || from < 0 ? 0 : from;
@@ -168,7 +200,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
168
200
  api: api,
169
201
  parent: parent,
170
202
  formatMessage: formatMessage
171
- }, anchorRectCache));
203
+ }, nodeViewPortalProviderAPI, anchorRectCache));
172
204
  }
173
205
  }
174
206
  if (node.isInline || !parent || DISABLE_CHILD_DROP_TARGET.includes(parent.type.name)) {
@@ -214,7 +246,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
214
246
  parentNode: parent || undefined,
215
247
  formatMessage: formatMessage,
216
248
  dropTargetStyle: shouldShowFullHeight ? 'remainingHeight' : 'default'
217
- }, -1, anchorRectCache, isSameLayout));
249
+ }, nodeViewPortalProviderAPI, -1, anchorRectCache, isSameLayout));
218
250
  if (endPos !== undefined) {
219
251
  decs.push(createDropTargetDecoration(endPos, {
220
252
  api: api,
@@ -222,7 +254,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
222
254
  parentNode: parent || undefined,
223
255
  formatMessage: formatMessage,
224
256
  dropTargetStyle: 'remainingHeight'
225
- }, -1, anchorRectCache));
257
+ }, nodeViewPortalProviderAPI, -1, anchorRectCache));
226
258
  }
227
259
  if (fg('platform_editor_drag_and_drop_target_v2')) {
228
260
  pushNodeStack(node, depth);
@@ -237,7 +269,7 @@ export var dropTargetDecorations = function dropTargetDecorations(newState, api,
237
269
  formatMessage: formatMessage,
238
270
  prevNode: newState.doc.lastChild || undefined,
239
271
  parentNode: newState.doc
240
- }, undefined, anchorRectCache));
272
+ }, nodeViewPortalProviderAPI, undefined, anchorRectCache));
241
273
  }
242
274
  return decs;
243
275
  };
@@ -8,13 +8,19 @@ var isEmptyNestedParagraphOrHeading = function isEmptyNestedParagraphOrHeading(t
8
8
  }
9
9
  return false;
10
10
  };
11
+ var isEmptyParagraphOrPlaceholder = function isEmptyParagraphOrPlaceholder(node) {
12
+ if (node && node.type.name === 'paragraph') {
13
+ var _node$firstChild;
14
+ return node.childCount === 0 || node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.type.name) === 'placeholder';
15
+ }
16
+ return false;
17
+ };
11
18
  var isLayoutColumnWithoutContent = function isLayoutColumnWithoutContent(node) {
12
19
  if ((node === null || node === void 0 ? void 0 : node.type.name) === 'layoutColumn') {
13
20
  var foundNonEmptyNode = false;
14
21
  for (var i = 0; i < node.childCount; i++) {
15
- var _child$firstChild;
16
22
  var child = node.child(i);
17
- if (child.content.size && ((_child$firstChild = child.firstChild) === null || _child$firstChild === void 0 ? void 0 : _child$firstChild.type.name) !== 'placeholder') {
23
+ if (!isEmptyParagraphOrPlaceholder(child)) {
18
24
  foundNonEmptyNode = true;
19
25
  break;
20
26
  }