@atlaskit/editor-plugin-block-controls 8.0.1 → 8.0.2

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,13 @@
1
1
  # @atlaskit/editor-plugin-block-controls
2
2
 
3
+ ## 8.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`4bf196f8645a7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4bf196f8645a7) -
8
+ Editor-4011: Added util function isMultiNodeSelection
9
+ - Updated dependencies
10
+
3
11
  ## 8.0.1
4
12
 
5
13
  ### Patch Changes
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.handleMouseOver = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _memoizeOne = _interopRequireDefault(require("memoize-one"));
10
+ var _selection = require("@atlaskit/editor-common/selection");
10
11
  var _toolbarFlagCheck = require("@atlaskit/editor-common/toolbar-flag-check");
11
12
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
13
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
@@ -177,19 +178,9 @@ var handleMouseOver = exports.handleMouseOver = function handleMouseOver(view, e
177
178
  if (toolbarFlagsEnabled) {
178
179
  if ((0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu', 'isEnabled', true)) {
179
180
  var _selectionPreservatio;
180
- var selection = (_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
181
- var nodeTypes = [];
182
- selection === null || selection === void 0 || selection.$from.doc.nodesBetween(selection.from, selection.to, function (node, pos) {
183
- if (pos < selection.from) {
184
- // ignore parent node
185
- return true;
186
- }
187
- nodeTypes.push(node.type.name);
188
-
189
- // only care about the top level (relatively in the range) nodes
190
- return false;
191
- });
192
- var isMultipleSelected = nodeTypes.length > 1;
181
+ var preservedSelection = (_selectionPreservatio = _pluginKey.selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
182
+ var selection = preservedSelection || view.state.selection;
183
+ var isMultipleSelected = selection && (0, _selection.isMultiBlockSelection)(selection);
193
184
 
194
185
  // Only execute when selection is not a multi-selection, block menu is open, and menu is opened via keyboard
195
186
  // as when it is a multi-selection, the showDragHandleAt command interfere with selection
@@ -339,23 +339,6 @@ var getNodeMargins = function getNodeMargins(node) {
339
339
  }
340
340
  return _consts2.nodeMargins[nodeTypeName] || _consts2.nodeMargins['default'];
341
341
  };
342
- var isMultiNodeRange = function isMultiNodeRange(range) {
343
- if (range.endIndex - range.startIndex <= 1) {
344
- return false; // At most one child
345
- }
346
-
347
- // Count block nodes in the range, return true if more than one
348
- var blockCount = 0;
349
- for (var i = range.startIndex; i < range.endIndex; i++) {
350
- if (range.parent.child(i).isBlock) {
351
- blockCount++;
352
- }
353
- if (blockCount > 1) {
354
- return true;
355
- }
356
- }
357
- return false;
358
- };
359
342
  var isPosWithinRange = function isPosWithinRange(pos, range) {
360
343
  return range.start <= pos && range.end >= pos + 1;
361
344
  };
@@ -397,7 +380,7 @@ var expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
397
380
  });
398
381
 
399
382
  // Set selection to expanded selection range if it encompases the clicked drag handle
400
- if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiNodeRange(expandedRange.range)) {
383
+ if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && (0, _selection.isMultiBlockRange)(expandedRange.range)) {
401
384
  var collapsed = (0, _getSelection.collapseToSelectionRange)(expandedRange.$from, expandedRange.$to);
402
385
 
403
386
  // Then create a selection from the start of the first node to the end of the last node
@@ -1,4 +1,5 @@
1
1
  import memoizeOne from 'memoize-one';
2
+ import { isMultiBlockSelection } from '@atlaskit/editor-common/selection';
2
3
  import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
3
4
  import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
@@ -169,19 +170,9 @@ export const handleMouseOver = (view, event, api) => {
169
170
  if (toolbarFlagsEnabled) {
170
171
  if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
171
172
  var _selectionPreservatio;
172
- const selection = (_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
173
- const nodeTypes = [];
174
- selection === null || selection === void 0 ? void 0 : selection.$from.doc.nodesBetween(selection.from, selection.to, (node, pos) => {
175
- if (pos < selection.from) {
176
- // ignore parent node
177
- return true;
178
- }
179
- nodeTypes.push(node.type.name);
180
-
181
- // only care about the top level (relatively in the range) nodes
182
- return false;
183
- });
184
- const isMultipleSelected = nodeTypes.length > 1;
173
+ const preservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
174
+ const selection = preservedSelection || view.state.selection;
175
+ const isMultipleSelected = selection && isMultiBlockSelection(selection);
185
176
 
186
177
  // Only execute when selection is not a multi-selection, block menu is open, and menu is opened via keyboard
187
178
  // as when it is a multi-selection, the showDragHandleAt command interfere with selection
@@ -14,7 +14,7 @@ import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-commo
14
14
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
15
15
  import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
16
16
  import { blockControlsMessages } from '@atlaskit/editor-common/messages';
17
- import { expandToBlockRange } from '@atlaskit/editor-common/selection';
17
+ import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
18
18
  import { DRAG_HANDLE_WIDTH, tableControlsSpacing } from '@atlaskit/editor-common/styles';
19
19
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
20
20
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -334,23 +334,6 @@ const getNodeMargins = node => {
334
334
  }
335
335
  return nodeMargins[nodeTypeName] || nodeMargins['default'];
336
336
  };
337
- const isMultiNodeRange = range => {
338
- if (range.endIndex - range.startIndex <= 1) {
339
- return false; // At most one child
340
- }
341
-
342
- // Count block nodes in the range, return true if more than one
343
- let blockCount = 0;
344
- for (let i = range.startIndex; i < range.endIndex; i++) {
345
- if (range.parent.child(i).isBlock) {
346
- blockCount++;
347
- }
348
- if (blockCount > 1) {
349
- return true;
350
- }
351
- }
352
- return false;
353
- };
354
337
  const isPosWithinRange = (pos, range) => {
355
338
  return range.start <= pos && range.end >= pos + 1;
356
339
  };
@@ -394,7 +377,7 @@ const expandAndUpdateSelection = ({
394
377
  });
395
378
 
396
379
  // Set selection to expanded selection range if it encompases the clicked drag handle
397
- if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiNodeRange(expandedRange.range)) {
380
+ if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
398
381
  const collapsed = collapseToSelectionRange(expandedRange.$from, expandedRange.$to);
399
382
 
400
383
  // Then create a selection from the start of the first node to the end of the last node
@@ -1,5 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import memoizeOne from 'memoize-one';
3
+ import { isMultiBlockSelection } from '@atlaskit/editor-common/selection';
3
4
  import { areToolbarFlagsEnabled } from '@atlaskit/editor-common/toolbar-flag-check';
4
5
  import { fg } from '@atlaskit/platform-feature-flags';
5
6
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
@@ -170,19 +171,9 @@ export var handleMouseOver = function handleMouseOver(view, event, api) {
170
171
  if (toolbarFlagsEnabled) {
171
172
  if (expValEqualsNoExposure('platform_editor_block_menu', 'isEnabled', true)) {
172
173
  var _selectionPreservatio;
173
- var selection = (_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
174
- var nodeTypes = [];
175
- selection === null || selection === void 0 || selection.$from.doc.nodesBetween(selection.from, selection.to, function (node, pos) {
176
- if (pos < selection.from) {
177
- // ignore parent node
178
- return true;
179
- }
180
- nodeTypes.push(node.type.name);
181
-
182
- // only care about the top level (relatively in the range) nodes
183
- return false;
184
- });
185
- var isMultipleSelected = nodeTypes.length > 1;
174
+ var preservedSelection = (_selectionPreservatio = selectionPreservationPluginKey.getState(view.state)) === null || _selectionPreservatio === void 0 ? void 0 : _selectionPreservatio.preservedSelection;
175
+ var selection = preservedSelection || view.state.selection;
176
+ var isMultipleSelected = selection && isMultiBlockSelection(selection);
186
177
 
187
178
  // Only execute when selection is not a multi-selection, block menu is open, and menu is opened via keyboard
188
179
  // as when it is a multi-selection, the showDragHandleAt command interfere with selection
@@ -19,7 +19,7 @@ import { browser as browserLegacy, getBrowserInfo } from '@atlaskit/editor-commo
19
19
  import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
20
20
  import { dragToMoveDown, dragToMoveLeft, dragToMoveRight, dragToMoveUp, getAriaKeyshortcuts, TooltipContentWithMultipleShortcuts } from '@atlaskit/editor-common/keymaps';
21
21
  import { blockControlsMessages } from '@atlaskit/editor-common/messages';
22
- import { expandToBlockRange } from '@atlaskit/editor-common/selection';
22
+ import { expandToBlockRange, isMultiBlockRange } from '@atlaskit/editor-common/selection';
23
23
  import { DRAG_HANDLE_WIDTH, tableControlsSpacing } from '@atlaskit/editor-common/styles';
24
24
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
25
25
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
@@ -336,23 +336,6 @@ var getNodeMargins = function getNodeMargins(node) {
336
336
  }
337
337
  return nodeMargins[nodeTypeName] || nodeMargins['default'];
338
338
  };
339
- var isMultiNodeRange = function isMultiNodeRange(range) {
340
- if (range.endIndex - range.startIndex <= 1) {
341
- return false; // At most one child
342
- }
343
-
344
- // Count block nodes in the range, return true if more than one
345
- var blockCount = 0;
346
- for (var i = range.startIndex; i < range.endIndex; i++) {
347
- if (range.parent.child(i).isBlock) {
348
- blockCount++;
349
- }
350
- if (blockCount > 1) {
351
- return true;
352
- }
353
- }
354
- return false;
355
- };
356
339
  var isPosWithinRange = function isPosWithinRange(pos, range) {
357
340
  return range.start <= pos && range.end >= pos + 1;
358
341
  };
@@ -394,7 +377,7 @@ var expandAndUpdateSelection = function expandAndUpdateSelection(_ref2) {
394
377
  });
395
378
 
396
379
  // Set selection to expanded selection range if it encompases the clicked drag handle
397
- if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiNodeRange(expandedRange.range)) {
380
+ if (expandedRange.range && isPosWithinRange(startPos, expandedRange.range) && isMultiBlockRange(expandedRange.range)) {
398
381
  var collapsed = collapseToSelectionRange(expandedRange.$from, expandedRange.$to);
399
382
 
400
383
  // Then create a selection from the start of the first node to the end of the last node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",