@atlaskit/editor-plugin-block-controls 3.19.5 → 3.19.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 3.19.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [#174199](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/174199)
8
+ [`eee50ab6df3df`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eee50ab6df3df) -
9
+ Only create and find node decorations within the range provided
10
+ - Updated dependencies
11
+
12
+ ## 3.19.6
13
+
14
+ ### Patch Changes
15
+
16
+ - [#172583](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/172583)
17
+ [`40f387a0c0962`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/40f387a0c0962) -
18
+ Clean up platform_editor_controls_patch_2
19
+ - Updated dependencies
20
+
3
21
  ## 3.19.5
4
22
 
5
23
  ### Patch Changes
@@ -49,7 +49,7 @@ var findNextAnchorDecoration = function findNextAnchorDecoration(state) {
49
49
  return undefined;
50
50
  }
51
51
  var nextHandleNode = state.doc.nodeAt(nextHandleNodePos);
52
- var nodeDecorations = nextHandleNode && (0, _decorationsAnchor.findNodeDecs)(decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
52
+ var nodeDecorations = nextHandleNode && (0, _decorationsAnchor.findNodeDecs)(state, decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
53
53
  if (!nodeDecorations || nodeDecorations.length === 0) {
54
54
  return undefined;
55
55
  }
@@ -48,46 +48,79 @@ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, pare
48
48
  }
49
49
  return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
50
50
  };
51
+ var getPositionBeforeNodeAtPos = function getPositionBeforeNodeAtPos(state, pos) {
52
+ if (pos <= 0 || pos >= state.doc.nodeSize - 2) {
53
+ return pos;
54
+ }
55
+ var $pos = state.doc.resolve(pos);
56
+ if ($pos.depth > 0) {
57
+ return $pos.before();
58
+ }
59
+ return pos;
60
+ };
51
61
 
52
62
  /**
53
- * Find node decorations in the pos range between from and to (non-inclusive)
54
- * @param decorations
55
- * @param from
56
- * @param to
63
+ * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
64
+ * @param from Position to start search from (inclusive)
65
+ * @param to Position to end search at (non-inclusive)
57
66
  * @returns
58
67
  */
59
- var findNodeDecs = exports.findNodeDecs = function findNodeDecs(decorations, from, to) {
60
- var newfrom = from;
61
- var newTo = to;
68
+ var findNodeDecs = exports.findNodeDecs = function findNodeDecs(state, decorations, from, to) {
69
+ var newFrom = from;
70
+ if ((0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
71
+ // return empty array if range reversed
72
+ if (typeof to === 'number' && typeof newFrom === 'number' && newFrom > to) {
73
+ return [];
74
+ }
75
+ var decs = decorations.find(newFrom, to, function (spec) {
76
+ return spec.type === _decorationsCommon.TYPE_NODE_DEC;
77
+ });
62
78
 
63
- // make it non-inclusive
64
- if (newfrom !== undefined) {
65
- newfrom++;
66
- }
79
+ // Prosemirror finds any decorations that overlap with the provided position range, but we don't want to include decorations of nodes that start outside of the range
80
+ if (typeof to === 'number' && typeof newFrom === 'number') {
81
+ decs = decs.filter(function (dec) {
82
+ return dec.from >= (newFrom || 0) && dec.from < to;
83
+ });
84
+ }
85
+ return decs;
86
+ } else {
87
+ var newTo = to;
67
88
 
68
- // make it non-inclusive
69
- if (newTo !== undefined) {
70
- newTo--;
71
- }
89
+ // make it non-inclusive
90
+ if (newFrom !== undefined) {
91
+ newFrom++;
92
+ }
93
+
94
+ // make it non-inclusive
95
+ if (newTo !== undefined) {
96
+ newTo--;
97
+ }
72
98
 
73
- // return empty array if range reversed
74
- if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
75
- return [];
99
+ // return empty array if range reversed
100
+ if (newFrom !== undefined && newTo !== undefined && newFrom > newTo) {
101
+ return [];
102
+ }
103
+ return decorations.find(newFrom, newTo, function (spec) {
104
+ return spec.type === _decorationsCommon.TYPE_NODE_DEC;
105
+ });
76
106
  }
77
- return decorations.find(newfrom, newTo, function (spec) {
78
- return spec.type === _decorationsCommon.TYPE_NODE_DEC;
79
- });
80
107
  };
81
108
  var nodeDecorations = exports.nodeDecorations = function nodeDecorations(newState, from, to) {
82
109
  var decs = [];
83
110
  var docFrom = from === undefined || from < 0 ? 0 : from;
84
111
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
85
112
  var ignore_nodes = (0, _experiments.editorExperiment)('advanced_layouts', true) ? IGNORE_NODES_NEXT : IGNORE_NODES;
86
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
113
+ newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, _) {
87
114
  var depth = 0;
88
115
  var shouldDescend = shouldDescendIntoNode(node);
89
116
  var anchorName = (0, _decorationsCommon.getNodeAnchor)(node);
90
117
  var nodeTypeWithLevel = (0, _decorationsCommon.getNodeTypeWithLevel)(node);
118
+ if ((0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true)) {
119
+ // We don't want to create decorations for nodes that start outside of the provided position range
120
+ if (pos < getPositionBeforeNodeAtPos(newState, docFrom)) {
121
+ return shouldDescend;
122
+ }
123
+ }
91
124
 
92
125
  // Doesn't descend into a node
93
126
  if (node.isInline) {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.handleMouseDown = void 0;
7
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
7
  var handleMouseDown = exports.handleMouseDown = function handleMouseDown(api) {
9
8
  return function (view, event) {
10
9
  if (!(event.target instanceof HTMLElement)) {
@@ -20,7 +19,7 @@ var handleMouseDown = exports.handleMouseDown = function handleMouseDown(api) {
20
19
  return false;
21
20
  }
22
21
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
23
- } else if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
22
+ } else {
24
23
  var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
25
24
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
26
25
  }
@@ -224,9 +224,9 @@ var getDecorations = exports.getDecorations = function getDecorations(state) {
224
224
  var _key$getState;
225
225
  return (_key$getState = key.getState(state)) === null || _key$getState === void 0 ? void 0 : _key$getState.decorations;
226
226
  };
227
- var getDecorationAtPos = function getDecorationAtPos(decorations, pos, to) {
227
+ var getDecorationAtPos = function getDecorationAtPos(state, decorations, pos, to) {
228
228
  // Find the newly minted node decs that touch the active node
229
- var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, pos - 1, to);
229
+ var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(state, decorations, (0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) ? pos : pos - 1, to);
230
230
 
231
231
  // Find the specific dec that the active node corresponds to
232
232
  var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
@@ -251,8 +251,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
251
251
  menuTriggerBy = currentState.menuTriggerBy,
252
252
  isPMDragging = currentState.isPMDragging,
253
253
  isShiftDown = currentState.isShiftDown,
254
- lastDragCancelled = currentState.lastDragCancelled,
255
- isSelectedViaDragHandle = currentState.isSelectedViaDragHandle;
254
+ lastDragCancelled = currentState.lastDragCancelled;
256
255
  var isActiveNodeDeleted = false;
257
256
  var _getTrMetadata = (0, _transactions.getTrMetadata)(tr),
258
257
  from = _getTrMetadata.from,
@@ -335,14 +334,14 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
335
334
  var shouldRedrawNodeDecs = !isResizerResizing && (isNodeDecsMissing || (meta === null || meta === void 0 ? void 0 : meta.isDragging));
336
335
  var isActiveNodeModified = false;
337
336
  if (api && shouldRedrawNodeDecs) {
338
- var oldNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, from, to);
337
+ var oldNodeDecs = (0, _decorationsAnchor.findNodeDecs)(newState, decorations, from, to);
339
338
  decorations = decorations.remove(oldNodeDecs);
340
339
  var newNodeDecs = (0, _decorationsAnchor.nodeDecorations)(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
341
340
  decorations = decorations.add(newState.doc, newNodeDecs);
342
341
  if ((0, _experiments.editorExperiment)('platform_editor_controls', 'control')) {
343
342
  if (latestActiveNode && !isActiveNodeDeleted) {
344
343
  // Find the newly minted node decs that touch the active node
345
- var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(decorations, latestActiveNode.pos - 1, to);
344
+ var findNewNodeDecs = (0, _decorationsAnchor.findNodeDecs)(newState, decorations, (0, _experiments.editorExperiment)('platform_editor_block_control_optimise_render', true) ? latestActiveNode.pos : latestActiveNode.pos - 1, to);
346
345
 
347
346
  // Find the specific dec that the active node corresponds to
348
347
  var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
@@ -361,8 +360,8 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
361
360
  }
362
361
  } else {
363
362
  if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
364
- var _nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
365
- var rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
363
+ var _nodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.pos, to);
364
+ var rootNodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.rootPos, to);
366
365
  if (_nodeDecAtActivePos || rootNodeDecAtActivePos) {
367
366
  isActiveNodeModified = true;
368
367
  }
@@ -401,7 +400,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
401
400
  // Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
402
401
  shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
403
402
  }
404
- if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
403
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
405
404
  // Remove handle dec when editor is blurred
406
405
  shouldRemoveHandle = shouldRemoveHandle || (meta === null || meta === void 0 ? void 0 : meta.editorBlurred);
407
406
  }
@@ -468,7 +467,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
468
467
  }
469
468
  var isEmptyDoc = (0, _utils.isEmptyDocument)(newState.doc);
470
469
  if (isEmptyDoc) {
471
- var hasNodeDecoration = !!(0, _decorationsAnchor.findNodeDecs)(decorations).length;
470
+ var hasNodeDecoration = !!(0, _decorationsAnchor.findNodeDecs)(newState, decorations).length;
472
471
  if (!hasNodeDecoration) {
473
472
  decorations = decorations.add(newState.doc, [(0, _decorationsDragHandle.emptyParagraphNodeDecorations)()]);
474
473
  }
@@ -493,7 +492,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
493
492
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
494
493
  isMenuOpenNew = !isMenuOpen;
495
494
  }
496
- var isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
495
+ var isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
497
496
  return {
498
497
  decorations: decorations,
499
498
  activeNode: newActiveNode,
@@ -510,7 +509,7 @@ var _apply = exports.apply = function apply(api, formatMessage, tr, currentState
510
509
  multiSelectDnD: multiSelectDnD,
511
510
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
512
511
  lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
513
- isSelectedViaDragHandle: isSelectedViaDragHandleNew
512
+ isSelectedViaDragHandle: isSelectedViaDragHandle
514
513
  };
515
514
  };
516
515
  var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, nodeViewPortalProviderAPI) {
@@ -660,7 +659,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
660
659
  (0, _handleMouseOver.handleMouseOver)(view, event, api);
661
660
  return false;
662
661
  },
663
- mousedown: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_2') ? (0, _handleMouseDown.handleMouseDown)(api) : undefined,
662
+ mousedown: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _handleMouseDown.handleMouseDown)(api) : undefined,
664
663
  keydown: function keydown(view, event) {
665
664
  if (isMultiSelectEnabled) {
666
665
  if (event.shiftKey && event.ctrlKey) {
@@ -684,11 +683,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
684
683
  return true;
685
684
  }
686
685
  }
687
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
686
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
688
687
  var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
689
688
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
690
689
  }
691
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
690
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
692
691
  var _api$blockControls$sh2;
693
692
  if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
694
693
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -721,11 +720,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
721
720
  return true;
722
721
  }
723
722
  }
724
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
723
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
725
724
  var _isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
726
725
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(_isDragHandle));
727
726
  }
728
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_5')) {
727
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
729
728
  var _api$blockControls$sh3;
730
729
  if (api !== null && api !== void 0 && (_api$blockControls$sh3 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh3 !== void 0 && _api$blockControls$sh3.isSelectedViaDragHandle) {
731
730
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -741,7 +740,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl, no
741
740
  }
742
741
  },
743
742
  blur: function blur(view, event) {
744
- if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
743
+ if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
745
744
  var _api$core2;
746
745
  var isChildOfEditor = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest("#".concat(_ui.EDIT_AREA_ID)) !== null;
747
746
 
@@ -609,7 +609,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
609
609
  var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
610
610
  var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
611
611
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
612
- var safeAnchorName = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_2') ? (0, _anchorName.refreshAnchorName)({
612
+ var safeAnchorName = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _anchorName.refreshAnchorName)({
613
613
  getPos: getPos,
614
614
  view: view,
615
615
  anchorName: anchorName
@@ -655,7 +655,7 @@ var DragHandle = exports.DragHandle = function DragHandle(_ref) {
655
655
  var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
656
656
  var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
657
657
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
658
- var safeAnchorName = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_2') ? (0, _anchorName.refreshAnchorName)({
658
+ var safeAnchorName = (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? (0, _anchorName.refreshAnchorName)({
659
659
  getPos: getPos,
660
660
  view: view,
661
661
  anchorName: anchorName
@@ -129,11 +129,11 @@ var TypeAheadControl = exports.TypeAheadControl = function TypeAheadControl(_ref
129
129
  // CHANGES - `removed editorExperiment('advanced_layouts', true) && isLayoutColumn` checks as quick insert button will not be positioned for layout column
130
130
  var calculatePosition = (0, _react.useCallback)(function () {
131
131
  var supportsAnchor = CSS.supports('top', "anchor(".concat(rootAnchorName, " start)")) && CSS.supports('left', "anchor(".concat(rootAnchorName, " start)"));
132
- var safeAnchorName = (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_2') ? (0, _anchorName.refreshAnchorName)({
132
+ var safeAnchorName = (0, _anchorName.refreshAnchorName)({
133
133
  getPos: getPos,
134
134
  view: view,
135
135
  anchorName: rootAnchorName
136
- }) : rootAnchorName;
136
+ });
137
137
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(safeAnchorName, "\"]"));
138
138
  var hasResizer = rootNodeType === 'table' || rootNodeType === 'mediaSingle';
139
139
  var isExtension = rootNodeType === 'extension' || rootNodeType === 'bodiedExtension';
@@ -23,7 +23,7 @@ var refreshAnchorName = exports.refreshAnchorName = function refreshAnchorName(_
23
23
  var state = _main.key.getState(view.state);
24
24
  if (state !== null && state !== void 0 && state.decorations) {
25
25
  var _node$nodeSize;
26
- var nodeDecs = (0, _decorationsAnchor.findNodeDecs)(state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
26
+ var nodeDecs = (0, _decorationsAnchor.findNodeDecs)(view.state, state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
27
27
  var nodeDec = nodeDecs.at(0);
28
28
  if (!nodeDec) {
29
29
  return newAnchorName;
@@ -48,7 +48,7 @@ const findNextAnchorDecoration = state => {
48
48
  return undefined;
49
49
  }
50
50
  const nextHandleNode = state.doc.nodeAt(nextHandleNodePos);
51
- let nodeDecorations = nextHandleNode && findNodeDecs(decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
51
+ let nodeDecorations = nextHandleNode && findNodeDecs(state, decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
52
52
  if (!nodeDecorations || nodeDecorations.length === 0) {
53
53
  return undefined;
54
54
  }
@@ -40,44 +40,75 @@ const shouldIgnoreNode = (node, ignore_nodes, depth, parent) => {
40
40
  }
41
41
  return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
42
42
  };
43
+ const getPositionBeforeNodeAtPos = (state, pos) => {
44
+ if (pos <= 0 || pos >= state.doc.nodeSize - 2) {
45
+ return pos;
46
+ }
47
+ const $pos = state.doc.resolve(pos);
48
+ if ($pos.depth > 0) {
49
+ return $pos.before();
50
+ }
51
+ return pos;
52
+ };
43
53
 
44
54
  /**
45
- * Find node decorations in the pos range between from and to (non-inclusive)
46
- * @param decorations
47
- * @param from
48
- * @param to
55
+ * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
56
+ * @param from Position to start search from (inclusive)
57
+ * @param to Position to end search at (non-inclusive)
49
58
  * @returns
50
59
  */
51
- export const findNodeDecs = (decorations, from, to) => {
52
- let newfrom = from;
53
- let newTo = to;
60
+ export const findNodeDecs = (state, decorations, from, to) => {
61
+ let newFrom = from;
62
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
63
+ // return empty array if range reversed
64
+ if (typeof to === 'number' && typeof newFrom === 'number' && newFrom > to) {
65
+ return [];
66
+ }
67
+ let decs = decorations.find(newFrom, to, spec => spec.type === TYPE_NODE_DEC);
54
68
 
55
- // make it non-inclusive
56
- if (newfrom !== undefined) {
57
- newfrom++;
58
- }
69
+ // Prosemirror finds any decorations that overlap with the provided position range, but we don't want to include decorations of nodes that start outside of the range
70
+ if (typeof to === 'number' && typeof newFrom === 'number') {
71
+ decs = decs.filter(dec => {
72
+ return dec.from >= (newFrom || 0) && dec.from < to;
73
+ });
74
+ }
75
+ return decs;
76
+ } else {
77
+ let newTo = to;
59
78
 
60
- // make it non-inclusive
61
- if (newTo !== undefined) {
62
- newTo--;
63
- }
79
+ // make it non-inclusive
80
+ if (newFrom !== undefined) {
81
+ newFrom++;
82
+ }
83
+
84
+ // make it non-inclusive
85
+ if (newTo !== undefined) {
86
+ newTo--;
87
+ }
64
88
 
65
- // return empty array if range reversed
66
- if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
67
- return [];
89
+ // return empty array if range reversed
90
+ if (newFrom !== undefined && newTo !== undefined && newFrom > newTo) {
91
+ return [];
92
+ }
93
+ return decorations.find(newFrom, newTo, spec => spec.type === TYPE_NODE_DEC);
68
94
  }
69
- return decorations.find(newfrom, newTo, spec => spec.type === TYPE_NODE_DEC);
70
95
  };
71
96
  export const nodeDecorations = (newState, from, to) => {
72
97
  const decs = [];
73
98
  const docFrom = from === undefined || from < 0 ? 0 : from;
74
99
  const docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
75
100
  const ignore_nodes = editorExperiment('advanced_layouts', true) ? IGNORE_NODES_NEXT : IGNORE_NODES;
76
- newState.doc.nodesBetween(docFrom, docTo, (node, pos, parent, index) => {
101
+ newState.doc.nodesBetween(docFrom, docTo, (node, pos, parent, _) => {
77
102
  let depth = 0;
78
103
  const shouldDescend = shouldDescendIntoNode(node);
79
104
  const anchorName = getNodeAnchor(node);
80
105
  const nodeTypeWithLevel = getNodeTypeWithLevel(node);
106
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
107
+ // We don't want to create decorations for nodes that start outside of the provided position range
108
+ if (pos < getPositionBeforeNodeAtPos(newState, docFrom)) {
109
+ return shouldDescend;
110
+ }
111
+ }
81
112
 
82
113
  // Doesn't descend into a node
83
114
  if (node.isInline) {
@@ -1,4 +1,3 @@
1
- import { fg } from '@atlaskit/platform-feature-flags';
2
1
  export const handleMouseDown = api => (view, event) => {
3
2
  if (!(event.target instanceof HTMLElement)) {
4
3
  return false;
@@ -13,7 +12,7 @@ export const handleMouseDown = api => (view, event) => {
13
12
  return false;
14
13
  }
15
14
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
16
- } else if (fg('platform_editor_controls_patch_5')) {
15
+ } else {
17
16
  const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
18
17
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
19
18
  }
@@ -222,9 +222,9 @@ export const getDecorations = state => {
222
222
  var _key$getState;
223
223
  return (_key$getState = key.getState(state)) === null || _key$getState === void 0 ? void 0 : _key$getState.decorations;
224
224
  };
225
- const getDecorationAtPos = (decorations, pos, to) => {
225
+ const getDecorationAtPos = (state, decorations, pos, to) => {
226
226
  // Find the newly minted node decs that touch the active node
227
- const findNewNodeDecs = findNodeDecs(decorations, pos - 1, to);
227
+ const findNewNodeDecs = findNodeDecs(state, decorations, editorExperiment('platform_editor_block_control_optimise_render', true) ? pos : pos - 1, to);
228
228
 
229
229
  // Find the specific dec that the active node corresponds to
230
230
  const nodeDecsAtActivePos = findNewNodeDecs.filter(dec => (dec === null || dec === void 0 ? void 0 : dec.from) === pos);
@@ -250,8 +250,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
250
250
  menuTriggerBy,
251
251
  isPMDragging,
252
252
  isShiftDown,
253
- lastDragCancelled,
254
- isSelectedViaDragHandle
253
+ lastDragCancelled
255
254
  } = currentState;
256
255
  let isActiveNodeDeleted = false;
257
256
  const {
@@ -336,14 +335,14 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
336
335
  const shouldRedrawNodeDecs = !isResizerResizing && (isNodeDecsMissing || (meta === null || meta === void 0 ? void 0 : meta.isDragging));
337
336
  let isActiveNodeModified = false;
338
337
  if (api && shouldRedrawNodeDecs) {
339
- const oldNodeDecs = findNodeDecs(decorations, from, to);
338
+ const oldNodeDecs = findNodeDecs(newState, decorations, from, to);
340
339
  decorations = decorations.remove(oldNodeDecs);
341
340
  const newNodeDecs = nodeDecorations(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
342
341
  decorations = decorations.add(newState.doc, newNodeDecs);
343
342
  if (editorExperiment('platform_editor_controls', 'control')) {
344
343
  if (latestActiveNode && !isActiveNodeDeleted) {
345
344
  // Find the newly minted node decs that touch the active node
346
- const findNewNodeDecs = findNodeDecs(decorations, latestActiveNode.pos - 1, to);
345
+ const findNewNodeDecs = findNodeDecs(newState, decorations, editorExperiment('platform_editor_block_control_optimise_render', true) ? latestActiveNode.pos : latestActiveNode.pos - 1, to);
347
346
 
348
347
  // Find the specific dec that the active node corresponds to
349
348
  const nodeDecsAtActivePos = findNewNodeDecs.filter(dec => (dec === null || dec === void 0 ? void 0 : dec.from) === latestActiveNode.pos);
@@ -360,8 +359,8 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
360
359
  }
361
360
  } else {
362
361
  if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
363
- const nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
364
- const rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
362
+ const nodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.pos, to);
363
+ const rootNodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.rootPos, to);
365
364
  if (nodeDecAtActivePos || rootNodeDecAtActivePos) {
366
365
  isActiveNodeModified = true;
367
366
  }
@@ -400,7 +399,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
400
399
  // Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
401
400
  shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
402
401
  }
403
- if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
402
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
404
403
  // Remove handle dec when editor is blurred
405
404
  shouldRemoveHandle = shouldRemoveHandle || (meta === null || meta === void 0 ? void 0 : meta.editorBlurred);
406
405
  }
@@ -468,7 +467,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
468
467
  }
469
468
  const isEmptyDoc = isEmptyDocument(newState.doc);
470
469
  if (isEmptyDoc) {
471
- const hasNodeDecoration = !!findNodeDecs(decorations).length;
470
+ const hasNodeDecoration = !!findNodeDecs(newState, decorations).length;
472
471
  if (!hasNodeDecoration) {
473
472
  decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
474
473
  }
@@ -493,7 +492,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
493
492
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
494
493
  isMenuOpenNew = !isMenuOpen;
495
494
  }
496
- const isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
495
+ const isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
497
496
  return {
498
497
  decorations,
499
498
  activeNode: newActiveNode,
@@ -510,7 +509,7 @@ export const apply = (api, formatMessage, tr, currentState, newState, flags, nod
510
509
  multiSelectDnD,
511
510
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
512
511
  lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
513
- isSelectedViaDragHandle: isSelectedViaDragHandleNew
512
+ isSelectedViaDragHandle
514
513
  };
515
514
  };
516
515
  export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
@@ -666,7 +665,7 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
666
665
  handleMouseOver(view, event, api);
667
666
  return false;
668
667
  },
669
- mousedown: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? handleMouseDown(api) : undefined,
668
+ mousedown: editorExperiment('platform_editor_controls', 'variant1') ? handleMouseDown(api) : undefined,
670
669
  keydown(view, event) {
671
670
  if (isMultiSelectEnabled) {
672
671
  if (event.shiftKey && event.ctrlKey) {
@@ -691,11 +690,11 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
691
690
  return true;
692
691
  }
693
692
  }
694
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
693
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1')) {
695
694
  const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
696
695
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
697
696
  }
698
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
697
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1')) {
699
698
  var _api$blockControls$sh2;
700
699
  if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
701
700
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -730,11 +729,11 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
730
729
  return true;
731
730
  }
732
731
  }
733
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
732
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1')) {
734
733
  const isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
735
734
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
736
735
  }
737
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
736
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1')) {
738
737
  var _api$blockControls$sh3;
739
738
  if (api !== null && api !== void 0 && (_api$blockControls$sh3 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh3 !== void 0 && _api$blockControls$sh3.isSelectedViaDragHandle) {
740
739
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -751,7 +750,7 @@ export const createPlugin = (api, getIntl, nodeViewPortalProviderAPI) => {
751
750
  }
752
751
  },
753
752
  blur(view, event) {
754
- if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
753
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
755
754
  var _api$core2;
756
755
  const isChildOfEditor = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest(`#${EDIT_AREA_ID}`) !== null;
757
756
 
@@ -593,7 +593,7 @@ export const DragHandle = ({
593
593
  const node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
594
594
  const parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
595
595
  const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
596
- const safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
596
+ const safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') ? refreshAnchorName({
597
597
  getPos,
598
598
  view,
599
599
  anchorName
@@ -641,7 +641,7 @@ export const DragHandle = ({
641
641
  const node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
642
642
  const parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
643
643
  const supportsAnchor = CSS.supports('top', `anchor(${anchorName} start)`) && CSS.supports('left', `anchor(${anchorName} start)`);
644
- const safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
644
+ const safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') ? refreshAnchorName({
645
645
  getPos,
646
646
  view,
647
647
  anchorName
@@ -118,11 +118,11 @@ export const TypeAheadControl = ({
118
118
  // CHANGES - `removed editorExperiment('advanced_layouts', true) && isLayoutColumn` checks as quick insert button will not be positioned for layout column
119
119
  const calculatePosition = useCallback(() => {
120
120
  const supportsAnchor = CSS.supports('top', `anchor(${rootAnchorName} start)`) && CSS.supports('left', `anchor(${rootAnchorName} start)`);
121
- const safeAnchorName = fg('platform_editor_controls_patch_2') ? refreshAnchorName({
121
+ const safeAnchorName = refreshAnchorName({
122
122
  getPos,
123
123
  view,
124
124
  anchorName: rootAnchorName
125
- }) : rootAnchorName;
125
+ });
126
126
  const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${safeAnchorName}"]`);
127
127
  const hasResizer = rootNodeType === 'table' || rootNodeType === 'mediaSingle';
128
128
  const isExtension = rootNodeType === 'extension' || rootNodeType === 'bodiedExtension';
@@ -18,7 +18,7 @@ export const refreshAnchorName = ({
18
18
  const state = key.getState(view.state);
19
19
  if (state !== null && state !== void 0 && state.decorations) {
20
20
  var _node$nodeSize;
21
- const nodeDecs = findNodeDecs(state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
21
+ const nodeDecs = findNodeDecs(view.state, state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
22
22
  const nodeDec = nodeDecs.at(0);
23
23
  if (!nodeDec) {
24
24
  return newAnchorName;
@@ -43,7 +43,7 @@ var findNextAnchorDecoration = function findNextAnchorDecoration(state) {
43
43
  return undefined;
44
44
  }
45
45
  var nextHandleNode = state.doc.nodeAt(nextHandleNodePos);
46
- var nodeDecorations = nextHandleNode && findNodeDecs(decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
46
+ var nodeDecorations = nextHandleNode && findNodeDecs(state, decorations, nextHandleNodePos, nextHandleNodePos + nextHandleNode.nodeSize);
47
47
  if (!nodeDecorations || nodeDecorations.length === 0) {
48
48
  return undefined;
49
49
  }
@@ -41,46 +41,79 @@ var shouldIgnoreNode = function shouldIgnoreNode(node, ignore_nodes, depth, pare
41
41
  }
42
42
  return (isEmbedCard || isMediaSingle) && ['wrap-right', 'wrap-left'].includes(node.attrs.layout) ? true : ignore_nodes.includes(node.type.name);
43
43
  };
44
+ var getPositionBeforeNodeAtPos = function getPositionBeforeNodeAtPos(state, pos) {
45
+ if (pos <= 0 || pos >= state.doc.nodeSize - 2) {
46
+ return pos;
47
+ }
48
+ var $pos = state.doc.resolve(pos);
49
+ if ($pos.depth > 0) {
50
+ return $pos.before();
51
+ }
52
+ return pos;
53
+ };
44
54
 
45
55
  /**
46
- * Find node decorations in the pos range between from and to (non-inclusive)
47
- * @param decorations
48
- * @param from
49
- * @param to
56
+ * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
57
+ * @param from Position to start search from (inclusive)
58
+ * @param to Position to end search at (non-inclusive)
50
59
  * @returns
51
60
  */
52
- export var findNodeDecs = function findNodeDecs(decorations, from, to) {
53
- var newfrom = from;
54
- var newTo = to;
61
+ export var findNodeDecs = function findNodeDecs(state, decorations, from, to) {
62
+ var newFrom = from;
63
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
64
+ // return empty array if range reversed
65
+ if (typeof to === 'number' && typeof newFrom === 'number' && newFrom > to) {
66
+ return [];
67
+ }
68
+ var decs = decorations.find(newFrom, to, function (spec) {
69
+ return spec.type === TYPE_NODE_DEC;
70
+ });
55
71
 
56
- // make it non-inclusive
57
- if (newfrom !== undefined) {
58
- newfrom++;
59
- }
72
+ // Prosemirror finds any decorations that overlap with the provided position range, but we don't want to include decorations of nodes that start outside of the range
73
+ if (typeof to === 'number' && typeof newFrom === 'number') {
74
+ decs = decs.filter(function (dec) {
75
+ return dec.from >= (newFrom || 0) && dec.from < to;
76
+ });
77
+ }
78
+ return decs;
79
+ } else {
80
+ var newTo = to;
60
81
 
61
- // make it non-inclusive
62
- if (newTo !== undefined) {
63
- newTo--;
64
- }
82
+ // make it non-inclusive
83
+ if (newFrom !== undefined) {
84
+ newFrom++;
85
+ }
86
+
87
+ // make it non-inclusive
88
+ if (newTo !== undefined) {
89
+ newTo--;
90
+ }
65
91
 
66
- // return empty array if range reversed
67
- if (newfrom !== undefined && newTo !== undefined && newfrom > newTo) {
68
- return [];
92
+ // return empty array if range reversed
93
+ if (newFrom !== undefined && newTo !== undefined && newFrom > newTo) {
94
+ return [];
95
+ }
96
+ return decorations.find(newFrom, newTo, function (spec) {
97
+ return spec.type === TYPE_NODE_DEC;
98
+ });
69
99
  }
70
- return decorations.find(newfrom, newTo, function (spec) {
71
- return spec.type === TYPE_NODE_DEC;
72
- });
73
100
  };
74
101
  export var nodeDecorations = function nodeDecorations(newState, from, to) {
75
102
  var decs = [];
76
103
  var docFrom = from === undefined || from < 0 ? 0 : from;
77
104
  var docTo = to === undefined || to > newState.doc.nodeSize - 2 ? newState.doc.nodeSize - 2 : to;
78
105
  var ignore_nodes = editorExperiment('advanced_layouts', true) ? IGNORE_NODES_NEXT : IGNORE_NODES;
79
- newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, index) {
106
+ newState.doc.nodesBetween(docFrom, docTo, function (node, pos, parent, _) {
80
107
  var depth = 0;
81
108
  var shouldDescend = shouldDescendIntoNode(node);
82
109
  var anchorName = getNodeAnchor(node);
83
110
  var nodeTypeWithLevel = getNodeTypeWithLevel(node);
111
+ if (editorExperiment('platform_editor_block_control_optimise_render', true)) {
112
+ // We don't want to create decorations for nodes that start outside of the provided position range
113
+ if (pos < getPositionBeforeNodeAtPos(newState, docFrom)) {
114
+ return shouldDescend;
115
+ }
116
+ }
84
117
 
85
118
  // Doesn't descend into a node
86
119
  if (node.isInline) {
@@ -1,4 +1,3 @@
1
- import { fg } from '@atlaskit/platform-feature-flags';
2
1
  export var handleMouseDown = function handleMouseDown(api) {
3
2
  return function (view, event) {
4
3
  if (!(event.target instanceof HTMLElement)) {
@@ -14,7 +13,7 @@ export var handleMouseDown = function handleMouseDown(api) {
14
13
  return false;
15
14
  }
16
15
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.showDragHandleAt(rootPos, '', (_rootNode$type$name = rootNode.type.name) !== null && _rootNode$type$name !== void 0 ? _rootNode$type$name : '', undefined, rootPos, '', (_rootNode$type$name2 = rootNode.type.name) !== null && _rootNode$type$name2 !== void 0 ? _rootNode$type$name2 : ''));
17
- } else if (fg('platform_editor_controls_patch_5')) {
16
+ } else {
18
17
  var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle]') !== null;
19
18
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
20
19
  }
@@ -217,9 +217,9 @@ export var getDecorations = function getDecorations(state) {
217
217
  var _key$getState;
218
218
  return (_key$getState = key.getState(state)) === null || _key$getState === void 0 ? void 0 : _key$getState.decorations;
219
219
  };
220
- var getDecorationAtPos = function getDecorationAtPos(decorations, pos, to) {
220
+ var getDecorationAtPos = function getDecorationAtPos(state, decorations, pos, to) {
221
221
  // Find the newly minted node decs that touch the active node
222
- var findNewNodeDecs = findNodeDecs(decorations, pos - 1, to);
222
+ var findNewNodeDecs = findNodeDecs(state, decorations, editorExperiment('platform_editor_block_control_optimise_render', true) ? pos : pos - 1, to);
223
223
 
224
224
  // Find the specific dec that the active node corresponds to
225
225
  var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
@@ -244,8 +244,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
244
244
  menuTriggerBy = currentState.menuTriggerBy,
245
245
  isPMDragging = currentState.isPMDragging,
246
246
  isShiftDown = currentState.isShiftDown,
247
- lastDragCancelled = currentState.lastDragCancelled,
248
- isSelectedViaDragHandle = currentState.isSelectedViaDragHandle;
247
+ lastDragCancelled = currentState.lastDragCancelled;
249
248
  var isActiveNodeDeleted = false;
250
249
  var _getTrMetadata = getTrMetadata(tr),
251
250
  from = _getTrMetadata.from,
@@ -328,14 +327,14 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
328
327
  var shouldRedrawNodeDecs = !isResizerResizing && (isNodeDecsMissing || (meta === null || meta === void 0 ? void 0 : meta.isDragging));
329
328
  var isActiveNodeModified = false;
330
329
  if (api && shouldRedrawNodeDecs) {
331
- var oldNodeDecs = findNodeDecs(decorations, from, to);
330
+ var oldNodeDecs = findNodeDecs(newState, decorations, from, to);
332
331
  decorations = decorations.remove(oldNodeDecs);
333
332
  var newNodeDecs = nodeDecorations(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
334
333
  decorations = decorations.add(newState.doc, newNodeDecs);
335
334
  if (editorExperiment('platform_editor_controls', 'control')) {
336
335
  if (latestActiveNode && !isActiveNodeDeleted) {
337
336
  // Find the newly minted node decs that touch the active node
338
- var findNewNodeDecs = findNodeDecs(decorations, latestActiveNode.pos - 1, to);
337
+ var findNewNodeDecs = findNodeDecs(newState, decorations, editorExperiment('platform_editor_block_control_optimise_render', true) ? latestActiveNode.pos : latestActiveNode.pos - 1, to);
339
338
 
340
339
  // Find the specific dec that the active node corresponds to
341
340
  var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
@@ -354,8 +353,8 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
354
353
  }
355
354
  } else {
356
355
  if (latestActiveNode && (!isActiveNodeDeleted || isReplacedWithSameSize)) {
357
- var _nodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.pos, to);
358
- var rootNodeDecAtActivePos = getDecorationAtPos(decorations, latestActiveNode.rootPos, to);
356
+ var _nodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.pos, to);
357
+ var rootNodeDecAtActivePos = getDecorationAtPos(newState, decorations, latestActiveNode.rootPos, to);
359
358
  if (_nodeDecAtActivePos || rootNodeDecAtActivePos) {
360
359
  isActiveNodeModified = true;
361
360
  }
@@ -394,7 +393,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
394
393
  // Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
395
394
  shouldRemoveHandle = latestActiveNode && (isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
396
395
  }
397
- if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
396
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
398
397
  // Remove handle dec when editor is blurred
399
398
  shouldRemoveHandle = shouldRemoveHandle || (meta === null || meta === void 0 ? void 0 : meta.editorBlurred);
400
399
  }
@@ -461,7 +460,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
461
460
  }
462
461
  var isEmptyDoc = isEmptyDocument(newState.doc);
463
462
  if (isEmptyDoc) {
464
- var hasNodeDecoration = !!findNodeDecs(decorations).length;
463
+ var hasNodeDecoration = !!findNodeDecs(newState, decorations).length;
465
464
  if (!hasNodeDecoration) {
466
465
  decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
467
466
  }
@@ -486,7 +485,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
486
485
  } else if (meta !== null && meta !== void 0 && meta.toggleMenu) {
487
486
  isMenuOpenNew = !isMenuOpen;
488
487
  }
489
- var isSelectedViaDragHandleNew = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5') ? meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle : isSelectedViaDragHandle;
488
+ var isSelectedViaDragHandle = (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle) !== undefined && editorExperiment('platform_editor_controls', 'variant1') && (meta === null || meta === void 0 ? void 0 : meta.isSelectedViaDragHandle);
490
489
  return {
491
490
  decorations: decorations,
492
491
  activeNode: newActiveNode,
@@ -503,7 +502,7 @@ var _apply = function apply(api, formatMessage, tr, currentState, newState, flag
503
502
  multiSelectDnD: multiSelectDnD,
504
503
  isShiftDown: (_meta$isShiftDown = meta === null || meta === void 0 ? void 0 : meta.isShiftDown) !== null && _meta$isShiftDown !== void 0 ? _meta$isShiftDown : isShiftDown,
505
504
  lastDragCancelled: (_meta$lastDragCancell = meta === null || meta === void 0 ? void 0 : meta.lastDragCancelled) !== null && _meta$lastDragCancell !== void 0 ? _meta$lastDragCancell : lastDragCancelled,
506
- isSelectedViaDragHandle: isSelectedViaDragHandleNew
505
+ isSelectedViaDragHandle: isSelectedViaDragHandle
507
506
  };
508
507
  };
509
508
  export { _apply as apply };
@@ -654,7 +653,7 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
654
653
  handleMouseOver(view, event, api);
655
654
  return false;
656
655
  },
657
- mousedown: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? handleMouseDown(api) : undefined,
656
+ mousedown: editorExperiment('platform_editor_controls', 'variant1') ? handleMouseDown(api) : undefined,
658
657
  keydown: function keydown(view, event) {
659
658
  if (isMultiSelectEnabled) {
660
659
  if (event.shiftKey && event.ctrlKey) {
@@ -678,11 +677,11 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
678
677
  return true;
679
678
  }
680
679
  }
681
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
680
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1')) {
682
681
  var isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
683
682
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(isDragHandle));
684
683
  }
685
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
684
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1')) {
686
685
  var _api$blockControls$sh2;
687
686
  if (api !== null && api !== void 0 && (_api$blockControls$sh2 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh2 !== void 0 && _api$blockControls$sh2.isSelectedViaDragHandle) {
688
687
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -715,11 +714,11 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
715
714
  return true;
716
715
  }
717
716
  }
718
- if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
717
+ if ((event.key === 'Enter' || event.key === ' ') && event.target instanceof HTMLElement && editorExperiment('platform_editor_controls', 'variant1')) {
719
718
  var _isDragHandle = event.target.closest('[data-editor-block-ctrl-drag-handle="true"]') !== null;
720
719
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(_isDragHandle));
721
720
  }
722
- if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_5')) {
721
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowRight' || event.key === 'ArrowDown' || event.key === 'ArrowUp') && editorExperiment('platform_editor_controls', 'variant1')) {
723
722
  var _api$blockControls$sh3;
724
723
  if (api !== null && api !== void 0 && (_api$blockControls$sh3 = api.blockControls.sharedState.currentState()) !== null && _api$blockControls$sh3 !== void 0 && _api$blockControls$sh3.isSelectedViaDragHandle) {
725
724
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.blockControls.commands.setSelectedViaDragHandle(false));
@@ -735,7 +734,7 @@ export var createPlugin = function createPlugin(api, getIntl, nodeViewPortalProv
735
734
  }
736
735
  },
737
736
  blur: function blur(view, event) {
738
- if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
737
+ if (editorExperiment('platform_editor_controls', 'variant1')) {
739
738
  var _api$core2;
740
739
  var isChildOfEditor = event.relatedTarget instanceof HTMLElement && event.relatedTarget.closest("#".concat(EDIT_AREA_ID)) !== null;
741
740
 
@@ -606,7 +606,7 @@ export var DragHandle = function DragHandle(_ref) {
606
606
  var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
607
607
  var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
608
608
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
609
- var safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
609
+ var safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') ? refreshAnchorName({
610
610
  getPos: getPos,
611
611
  view: view,
612
612
  anchorName: anchorName
@@ -652,7 +652,7 @@ export var DragHandle = function DragHandle(_ref) {
652
652
  var node = parentPos !== undefined ? view.state.doc.nodeAt(parentPos) : undefined;
653
653
  var parentNodeType = node === null || node === void 0 ? void 0 : node.type.name;
654
654
  var supportsAnchor = CSS.supports('top', "anchor(".concat(anchorName, " start)")) && CSS.supports('left', "anchor(".concat(anchorName, " start)"));
655
- var safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_2') ? refreshAnchorName({
655
+ var safeAnchorName = editorExperiment('platform_editor_controls', 'variant1') ? refreshAnchorName({
656
656
  getPos: getPos,
657
657
  view: view,
658
658
  anchorName: anchorName
@@ -124,11 +124,11 @@ export var TypeAheadControl = function TypeAheadControl(_ref) {
124
124
  // CHANGES - `removed editorExperiment('advanced_layouts', true) && isLayoutColumn` checks as quick insert button will not be positioned for layout column
125
125
  var calculatePosition = useCallback(function () {
126
126
  var supportsAnchor = CSS.supports('top', "anchor(".concat(rootAnchorName, " start)")) && CSS.supports('left', "anchor(".concat(rootAnchorName, " start)"));
127
- var safeAnchorName = fg('platform_editor_controls_patch_2') ? refreshAnchorName({
127
+ var safeAnchorName = refreshAnchorName({
128
128
  getPos: getPos,
129
129
  view: view,
130
130
  anchorName: rootAnchorName
131
- }) : rootAnchorName;
131
+ });
132
132
  var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(safeAnchorName, "\"]"));
133
133
  var hasResizer = rootNodeType === 'table' || rootNodeType === 'mediaSingle';
134
134
  var isExtension = rootNodeType === 'extension' || rootNodeType === 'bodiedExtension';
@@ -17,7 +17,7 @@ export var refreshAnchorName = function refreshAnchorName(_ref) {
17
17
  var state = key.getState(view.state);
18
18
  if (state !== null && state !== void 0 && state.decorations) {
19
19
  var _node$nodeSize;
20
- var nodeDecs = findNodeDecs(state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
20
+ var nodeDecs = findNodeDecs(view.state, state.decorations, pos, pos + ((_node$nodeSize = node === null || node === void 0 ? void 0 : node.nodeSize) !== null && _node$nodeSize !== void 0 ? _node$nodeSize : 0));
21
21
  var nodeDec = nodeDecs.at(0);
22
22
  if (!nodeDec) {
23
23
  return newAnchorName;
@@ -3,11 +3,10 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
5
  /**
6
- * Find node decorations in the pos range between from and to (non-inclusive)
7
- * @param decorations
8
- * @param from
9
- * @param to
6
+ * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
7
+ * @param from Position to start search from (inclusive)
8
+ * @param to Position to end search at (non-inclusive)
10
9
  * @returns
11
10
  */
12
- export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
11
+ export declare const findNodeDecs: (state: EditorState, decorations: DecorationSet, from?: number, to?: number) => Decoration[];
13
12
  export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
@@ -3,11 +3,10 @@ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration, type DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  export declare const shouldDescendIntoNode: (node: PMNode) => boolean;
5
5
  /**
6
- * Find node decorations in the pos range between from and to (non-inclusive)
7
- * @param decorations
8
- * @param from
9
- * @param to
6
+ * Find node decorations corresponding to nodes with starting position between from and to (non-inclusive)
7
+ * @param from Position to start search from (inclusive)
8
+ * @param to Position to end search at (non-inclusive)
10
9
  * @returns
11
10
  */
12
- export declare const findNodeDecs: (decorations: DecorationSet, from?: number, to?: number) => Decoration[];
11
+ export declare const findNodeDecs: (state: EditorState, decorations: DecorationSet, from?: number, to?: number) => Decoration[];
13
12
  export declare const nodeDecorations: (newState: EditorState, from?: number, to?: number) => Decoration[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "3.19.5",
3
+ "version": "3.19.7",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -54,10 +54,10 @@
54
54
  "@atlaskit/pragmatic-drag-and-drop": "^1.7.0",
55
55
  "@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^2.1.0",
56
56
  "@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^3.2.0",
57
- "@atlaskit/primitives": "^14.8.0",
57
+ "@atlaskit/primitives": "^14.9.0",
58
58
  "@atlaskit/theme": "^18.0.0",
59
- "@atlaskit/tmp-editor-statsig": "^7.1.0",
60
- "@atlaskit/tokens": "^5.2.0",
59
+ "@atlaskit/tmp-editor-statsig": "^8.0.0",
60
+ "@atlaskit/tokens": "^5.3.0",
61
61
  "@atlaskit/tooltip": "^20.3.0",
62
62
  "@babel/runtime": "^7.0.0",
63
63
  "@emotion/react": "^11.7.1",
@@ -156,21 +156,12 @@
156
156
  "platform_editor_fix_safari_cursor_hidden_empty": {
157
157
  "type": "boolean"
158
158
  },
159
- "platform_editor_controls_patch_2": {
160
- "type": "boolean"
161
- },
162
159
  "platform_editor_controls_widget_visibility": {
163
160
  "type": "boolean"
164
161
  },
165
162
  "platform_editor_controls_patch_4": {
166
163
  "type": "boolean"
167
164
  },
168
- "platform_editor_controls_patch_5": {
169
- "type": "boolean"
170
- },
171
- "platform_editor_controls_patch_7": {
172
- "type": "boolean"
173
- },
174
165
  "platform_editor_no_cursor_on_live_doc_init": {
175
166
  "type": "boolean"
176
167
  },