@atlaskit/editor-plugin-block-menu 5.1.1 → 5.1.3

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,21 @@
1
1
  # @atlaskit/editor-plugin-block-menu
2
2
 
3
+ ## 5.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8ae5288a74a40`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8ae5288a74a40) -
8
+ Update traversal logic in selection
9
+ - Updated dependencies
10
+
11
+ ## 5.1.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [`00c08e3995cb2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/00c08e3995cb2) -
16
+ Clean up platform_editor_block_menu_empty_line
17
+ - Updated dependencies
18
+
3
19
  ## 5.1.1
4
20
 
5
21
  ### Patch Changes
@@ -8,7 +8,6 @@ var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _monitoring = require("@atlaskit/editor-common/monitoring");
9
9
  var _state = require("@atlaskit/editor-prosemirror/state");
10
10
  var _utils = require("@atlaskit/editor-prosemirror/utils");
11
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
12
11
  var _selection = require("./selection");
13
12
  var _layoutTransforms = require("./transforms/layout-transforms");
14
13
  var _transformNodeToTargetType = require("./transforms/transformNodeToTargetType");
@@ -107,7 +106,7 @@ var formatNode = exports.formatNode = function formatNode(api) {
107
106
  var nodePos = selection.from;
108
107
 
109
108
  // when selection is empty, we insert a empty target node
110
- if (selection.empty && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
109
+ if (selection.empty) {
111
110
  var listNodes = [];
112
111
  // need to find if there is any list node in the current selection
113
112
  // As when select a empty list, selection is empty, but we want to convert the list instead of inserting a target node
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.transformNode = void 0;
7
7
  var _model = require("@atlaskit/editor-prosemirror/model");
8
8
  var _transform = require("./transform-node-utils/transform");
9
+ var _utils = require("./transforms/utils");
9
10
  var transformNode = exports.transformNode = function transformNode(api) {
10
11
  return (
11
12
  // eslint-disable-next-line no-unused-vars
@@ -22,28 +23,19 @@ var transformNode = exports.transformNode = function transformNode(api) {
22
23
  $from = preservedSelection.$from;
23
24
  var selectedParent = $from.parent;
24
25
  var fragment = _model.Fragment.empty;
25
- // top level selections can safely be transformed without checking for depth
26
- var isWithinSelectedRange = $from.depth === 0;
27
- tr.doc.nodesBetween(from, to, function (node) {
28
- // need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
29
- if (!isWithinSelectedRange && node.eq(selectedParent)) {
30
- isWithinSelectedRange = true;
31
- return true;
26
+ var isList = (0, _utils.isListNode)(selectedParent);
27
+ var slice = tr.doc.slice(isList ? from - 1 : from, isList ? to + 1 : to);
28
+ slice.content.forEach(function (node) {
29
+ var outputNode = (0, _transform.getOutputNodes)({
30
+ sourceNode: node,
31
+ targetNodeType: targetType,
32
+ schema: tr.doc.type.schema
33
+ });
34
+ if (outputNode) {
35
+ fragment = fragment.append(_model.Fragment.fromArray(outputNode));
32
36
  }
33
- if (isWithinSelectedRange) {
34
- var outputNode = (0, _transform.getOutputNodes)({
35
- sourceNode: node,
36
- targetNodeType: targetType,
37
- schema: tr.doc.type.schema
38
- });
39
- if (outputNode) {
40
- fragment = fragment.append(_model.Fragment.fromArray(outputNode));
41
- }
42
- return false;
43
- }
44
- return true;
45
37
  });
46
- tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
38
+ tr.replaceWith(isList ? preservedSelection.from - 1 : preservedSelection.from, preservedSelection.to, fragment);
47
39
  return tr;
48
40
  };
49
41
  }
@@ -23,7 +23,6 @@ var _editorToolbar = require("@atlaskit/editor-toolbar");
23
23
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
24
24
  var _platformFeatureFlagsReact = require("@atlaskit/platform-feature-flags-react");
25
25
  var _compiled = require("@atlaskit/primitives/compiled");
26
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
27
26
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
28
27
  var _blockMenuProvider = require("./block-menu-provider");
29
28
  var _blockMenuRenderer = require("./block-menu-renderer");
@@ -43,7 +42,6 @@ var useConditionalBlockMenuEffect = (0, _platformFeatureFlagsReact.conditionalHo
43
42
  menuTriggerBy = _ref.menuTriggerBy,
44
43
  selectedByShortcutOrDragHandle = _ref.selectedByShortcutOrDragHandle,
45
44
  hasFocus = _ref.hasFocus,
46
- shouldShowBlockMenuForEmptyLine = _ref.shouldShowBlockMenuForEmptyLine,
47
45
  openedViaKeyboard = _ref.openedViaKeyboard,
48
46
  prevIsMenuOpenRef = _ref.prevIsMenuOpenRef;
49
47
  /**
@@ -51,7 +49,7 @@ var useConditionalBlockMenuEffect = (0, _platformFeatureFlagsReact.conditionalHo
51
49
  */
52
50
  (0, _react.useEffect)(function () {
53
51
  var _api$userIntent;
54
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine) {
52
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus) {
55
53
  return;
56
54
  }
57
55
 
@@ -71,20 +69,19 @@ var useConditionalBlockMenuEffect = (0, _platformFeatureFlagsReact.conditionalHo
71
69
  // Update the previous state
72
70
  prevIsMenuOpenRef.current = isMenuOpen;
73
71
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent('blockMenuOpen'));
74
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, openedViaKeyboard, prevIsMenuOpenRef]);
72
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, openedViaKeyboard, prevIsMenuOpenRef]);
75
73
  }, function (_ref2) {
76
74
  var api = _ref2.api,
77
75
  isMenuOpen = _ref2.isMenuOpen,
78
76
  menuTriggerBy = _ref2.menuTriggerBy,
79
77
  selectedByShortcutOrDragHandle = _ref2.selectedByShortcutOrDragHandle,
80
78
  hasFocus = _ref2.hasFocus,
81
- shouldShowBlockMenuForEmptyLine = _ref2.shouldShowBlockMenuForEmptyLine,
82
79
  currentUserIntent = _ref2.currentUserIntent,
83
80
  openedViaKeyboard = _ref2.openedViaKeyboard,
84
81
  prevIsMenuOpenRef = _ref2.prevIsMenuOpenRef;
85
82
  (0, _react.useEffect)(function () {
86
83
  var _api$userIntent2;
87
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
84
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
88
85
  return;
89
86
  }
90
87
 
@@ -104,7 +101,7 @@ var useConditionalBlockMenuEffect = (0, _platformFeatureFlagsReact.conditionalHo
104
101
  // Update the previous state
105
102
  prevIsMenuOpenRef.current = isMenuOpen;
106
103
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('blockMenuOpen'));
107
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
104
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
108
105
  });
109
106
  var BlockMenuContent = function BlockMenuContent(_ref3) {
110
107
  var _api$blockMenu;
@@ -167,10 +164,6 @@ var BlockMenu = function BlockMenu(_ref4) {
167
164
  var prevIsMenuOpenRef = (0, _react.useRef)(false);
168
165
  var popupRef = (0, _react.useRef)(undefined);
169
166
  var hasFocus = (_ref5 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef || popupRef.current && (popupRef.current.contains(document.activeElement) || popupRef.current === document.activeElement)) !== null && _ref5 !== void 0 ? _ref5 : false;
170
- var hasSelection = !!editorView && !editorView.state.selection.empty;
171
- // hasSelection true, always show block menu
172
- // hasSelection false, only show block menu when empty line experiment is enabled
173
- var shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true);
174
167
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
175
168
 
176
169
  // Use conditional hook based on feature flag
@@ -180,7 +173,6 @@ var BlockMenu = function BlockMenu(_ref4) {
180
173
  menuTriggerBy: menuTriggerBy,
181
174
  selectedByShortcutOrDragHandle: selectedByShortcutOrDragHandle,
182
175
  hasFocus: hasFocus,
183
- shouldShowBlockMenuForEmptyLine: shouldShowBlockMenuForEmptyLine,
184
176
  currentUserIntent: (0, _platformFeatureFlags.fg)('platform_editor_toolbar_aifc_user_intent_fix') ? undefined : currentUserIntent,
185
177
  openedViaKeyboard: openedViaKeyboard,
186
178
  prevIsMenuOpenRef: prevIsMenuOpenRef
@@ -217,7 +209,7 @@ var BlockMenu = function BlockMenu(_ref4) {
217
209
  return tr;
218
210
  });
219
211
  };
220
- if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
212
+ if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
221
213
  closeMenu();
222
214
  return null;
223
215
  }
@@ -7,13 +7,12 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.DeleteSection = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _editorToolbar = require("@atlaskit/editor-toolbar");
10
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
11
10
  var DeleteSection = exports.DeleteSection = function DeleteSection(_ref) {
12
11
  var _api$selection;
13
12
  var api = _ref.api,
14
13
  children = _ref.children;
15
14
  var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
16
- var isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty) && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true);
15
+ var isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty);
17
16
  if (isEmptyLineSelected) {
18
17
  return null;
19
18
  }
@@ -5,32 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.checkIsFormatMenuHidden = void 0;
7
7
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
- var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
9
8
  var TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES = true;
10
9
  var getIsFormatMenuHidden = function getIsFormatMenuHidden(selection, schema) {
11
- var nodes = schema.nodes;
12
- if (!nodes) {
13
- return false;
14
- }
15
- if (TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES) {
16
- var disabledOnNodes = [nodes.syncBlock, nodes.bodiedSyncBlock, nodes.rule];
17
- var disabledNode = (0, _utils.findSelectedNodeOfType)(disabledOnNodes)(selection);
18
- return !!disabledNode;
19
- }
20
- var content;
21
- var allowedNodes = [nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection, nodes.expand];
22
- var selectedNode = (0, _utils.findSelectedNodeOfType)(allowedNodes)(selection);
23
- if (selectedNode) {
24
- content = selectedNode.node;
25
- } else {
26
- var listTypeOrBlockQuoteNode = (0, _utils.findParentNodeOfType)([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
27
- if (listTypeOrBlockQuoteNode) {
28
- content = listTypeOrBlockQuoteNode.node;
29
- }
30
- }
31
- return !content;
32
- };
33
- var getIsFormatMenuHiddenEmptyLine = function getIsFormatMenuHiddenEmptyLine(selection, schema) {
34
10
  var nodes = schema.nodes;
35
11
  if (!nodes) {
36
12
  return false;
@@ -66,5 +42,5 @@ var checkIsFormatMenuHidden = exports.checkIsFormatMenuHidden = function checkIs
66
42
  if (!selection || !schema || !menuTriggerBy) {
67
43
  return false;
68
44
  }
69
- return (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true) ? getIsFormatMenuHiddenEmptyLine(selection, schema) : getIsFormatMenuHidden(selection, schema);
45
+ return getIsFormatMenuHidden(selection, schema);
70
46
  };
@@ -2,7 +2,6 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
5
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
6
5
  import { setSelectionAfterTransform } from './selection';
7
6
  import { createDefaultLayoutSection } from './transforms/layout-transforms';
8
7
  import { transformNodeToTargetType } from './transforms/transformNodeToTargetType';
@@ -112,7 +111,7 @@ export const formatNode = api => (targetType, analyticsAttrs) => {
112
111
  let nodePos = selection.from;
113
112
 
114
113
  // when selection is empty, we insert a empty target node
115
- if (selection.empty && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
114
+ if (selection.empty) {
116
115
  const listNodes = [];
117
116
  // need to find if there is any list node in the current selection
118
117
  // As when select a empty list, selection is empty, but we want to convert the list instead of inserting a target node
@@ -1,5 +1,6 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
2
  import { getOutputNodes } from './transform-node-utils/transform';
3
+ import { isListNode } from './transforms/utils';
3
4
  export const transformNode = api =>
4
5
  // eslint-disable-next-line no-unused-vars
5
6
  (targetType, analyticsAttrs) => {
@@ -18,28 +19,19 @@ export const transformNode = api =>
18
19
  } = preservedSelection;
19
20
  const selectedParent = $from.parent;
20
21
  let fragment = Fragment.empty;
21
- // top level selections can safely be transformed without checking for depth
22
- let isWithinSelectedRange = $from.depth === 0;
23
- tr.doc.nodesBetween(from, to, node => {
24
- // need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
25
- if (!isWithinSelectedRange && node.eq(selectedParent)) {
26
- isWithinSelectedRange = true;
27
- return true;
22
+ const isList = isListNode(selectedParent);
23
+ const slice = tr.doc.slice(isList ? from - 1 : from, isList ? to + 1 : to);
24
+ slice.content.forEach(node => {
25
+ const outputNode = getOutputNodes({
26
+ sourceNode: node,
27
+ targetNodeType: targetType,
28
+ schema: tr.doc.type.schema
29
+ });
30
+ if (outputNode) {
31
+ fragment = fragment.append(Fragment.fromArray(outputNode));
28
32
  }
29
- if (isWithinSelectedRange) {
30
- const outputNode = getOutputNodes({
31
- sourceNode: node,
32
- targetNodeType: targetType,
33
- schema: tr.doc.type.schema
34
- });
35
- if (outputNode) {
36
- fragment = fragment.append(Fragment.fromArray(outputNode));
37
- }
38
- return false;
39
- }
40
- return true;
41
33
  });
42
- tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
34
+ tr.replaceWith(isList ? preservedSelection.from - 1 : preservedSelection.from, preservedSelection.to, fragment);
43
35
  return tr;
44
36
  };
45
37
  };
@@ -16,7 +16,6 @@ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownM
16
16
  import { fg } from '@atlaskit/platform-feature-flags';
17
17
  import { conditionalHooksFactory } from '@atlaskit/platform-feature-flags-react';
18
18
  import { Box } from '@atlaskit/primitives/compiled';
19
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
20
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
21
20
  import { useBlockMenu } from './block-menu-provider';
22
21
  import { BlockMenuRenderer } from './block-menu-renderer';
@@ -33,7 +32,6 @@ const useConditionalBlockMenuEffect = conditionalHooksFactory(() => fg('platform
33
32
  menuTriggerBy,
34
33
  selectedByShortcutOrDragHandle,
35
34
  hasFocus,
36
- shouldShowBlockMenuForEmptyLine,
37
35
  openedViaKeyboard,
38
36
  prevIsMenuOpenRef
39
37
  }) => {
@@ -42,7 +40,7 @@ const useConditionalBlockMenuEffect = conditionalHooksFactory(() => fg('platform
42
40
  */
43
41
  useEffect(() => {
44
42
  var _api$userIntent;
45
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine) {
43
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus) {
46
44
  return;
47
45
  }
48
46
 
@@ -62,21 +60,20 @@ const useConditionalBlockMenuEffect = conditionalHooksFactory(() => fg('platform
62
60
  // Update the previous state
63
61
  prevIsMenuOpenRef.current = isMenuOpen;
64
62
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent('blockMenuOpen'));
65
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, openedViaKeyboard, prevIsMenuOpenRef]);
63
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, openedViaKeyboard, prevIsMenuOpenRef]);
66
64
  }, ({
67
65
  api,
68
66
  isMenuOpen,
69
67
  menuTriggerBy,
70
68
  selectedByShortcutOrDragHandle,
71
69
  hasFocus,
72
- shouldShowBlockMenuForEmptyLine,
73
70
  currentUserIntent,
74
71
  openedViaKeyboard,
75
72
  prevIsMenuOpenRef
76
73
  }) => {
77
74
  useEffect(() => {
78
75
  var _api$userIntent2;
79
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
76
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
80
77
  return;
81
78
  }
82
79
 
@@ -96,7 +93,7 @@ const useConditionalBlockMenuEffect = conditionalHooksFactory(() => fg('platform
96
93
  // Update the previous state
97
94
  prevIsMenuOpenRef.current = isMenuOpen;
98
95
  api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('blockMenuOpen'));
99
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
96
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
100
97
  });
101
98
  const BlockMenuContent = ({
102
99
  api,
@@ -157,10 +154,6 @@ const BlockMenu = ({
157
154
  const prevIsMenuOpenRef = useRef(false);
158
155
  const popupRef = useRef(undefined);
159
156
  const hasFocus = (_ref = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef || popupRef.current && (popupRef.current.contains(document.activeElement) || popupRef.current === document.activeElement)) !== null && _ref !== void 0 ? _ref : false;
160
- const hasSelection = !!editorView && !editorView.state.selection.empty;
161
- // hasSelection true, always show block menu
162
- // hasSelection false, only show block menu when empty line experiment is enabled
163
- const shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
164
157
  const selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
165
158
 
166
159
  // Use conditional hook based on feature flag
@@ -170,7 +163,6 @@ const BlockMenu = ({
170
163
  menuTriggerBy,
171
164
  selectedByShortcutOrDragHandle,
172
165
  hasFocus,
173
- shouldShowBlockMenuForEmptyLine,
174
166
  currentUserIntent: fg('platform_editor_toolbar_aifc_user_intent_fix') ? undefined : currentUserIntent,
175
167
  openedViaKeyboard,
176
168
  prevIsMenuOpenRef
@@ -209,7 +201,7 @@ const BlockMenu = ({
209
201
  return tr;
210
202
  });
211
203
  };
212
- if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
204
+ if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
213
205
  closeMenu();
214
206
  return null;
215
207
  }
@@ -1,13 +1,12 @@
1
1
  import React from 'react';
2
2
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
4
3
  export const DeleteSection = ({
5
4
  api,
6
5
  children
7
6
  }) => {
8
7
  var _api$selection, _api$selection$shared, _api$selection$shared2;
9
8
  const selection = api === null || api === void 0 ? void 0 : (_api$selection = api.selection) === null || _api$selection === void 0 ? void 0 : (_api$selection$shared = _api$selection.sharedState) === null || _api$selection$shared === void 0 ? void 0 : (_api$selection$shared2 = _api$selection$shared.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
10
- const isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty) && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
9
+ const isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty);
11
10
  if (isEmptyLineSelected) {
12
11
  return null;
13
12
  }
@@ -1,30 +1,6 @@
1
1
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
3
2
  const TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES = true;
4
3
  const getIsFormatMenuHidden = (selection, schema) => {
5
- const nodes = schema.nodes;
6
- if (!nodes) {
7
- return false;
8
- }
9
- if (TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES) {
10
- const disabledOnNodes = [nodes.syncBlock, nodes.bodiedSyncBlock, nodes.rule];
11
- const disabledNode = findSelectedNodeOfType(disabledOnNodes)(selection);
12
- return !!disabledNode;
13
- }
14
- let content;
15
- const allowedNodes = [nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection, nodes.expand];
16
- const selectedNode = findSelectedNodeOfType(allowedNodes)(selection);
17
- if (selectedNode) {
18
- content = selectedNode.node;
19
- } else {
20
- const listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
21
- if (listTypeOrBlockQuoteNode) {
22
- content = listTypeOrBlockQuoteNode.node;
23
- }
24
- }
25
- return !content;
26
- };
27
- const getIsFormatMenuHiddenEmptyLine = (selection, schema) => {
28
4
  const nodes = schema.nodes;
29
5
  if (!nodes) {
30
6
  return false;
@@ -60,5 +36,5 @@ export const checkIsFormatMenuHidden = api => {
60
36
  if (!selection || !schema || !menuTriggerBy) {
61
37
  return false;
62
38
  }
63
- return expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true) ? getIsFormatMenuHiddenEmptyLine(selection, schema) : getIsFormatMenuHidden(selection, schema);
39
+ return getIsFormatMenuHidden(selection, schema);
64
40
  };
@@ -2,7 +2,6 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } f
2
2
  import { logException } from '@atlaskit/editor-common/monitoring';
3
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
5
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
6
5
  import { setSelectionAfterTransform } from './selection';
7
6
  import { createDefaultLayoutSection } from './transforms/layout-transforms';
8
7
  import { transformNodeToTargetType } from './transforms/transformNodeToTargetType';
@@ -102,7 +101,7 @@ export var formatNode = function formatNode(api) {
102
101
  var nodePos = selection.from;
103
102
 
104
103
  // when selection is empty, we insert a empty target node
105
- if (selection.empty && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true)) {
104
+ if (selection.empty) {
106
105
  var listNodes = [];
107
106
  // need to find if there is any list node in the current selection
108
107
  // As when select a empty list, selection is empty, but we want to convert the list instead of inserting a target node
@@ -1,5 +1,6 @@
1
1
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
2
  import { getOutputNodes } from './transform-node-utils/transform';
3
+ import { isListNode } from './transforms/utils';
3
4
  export var transformNode = function transformNode(api) {
4
5
  return (
5
6
  // eslint-disable-next-line no-unused-vars
@@ -16,28 +17,19 @@ export var transformNode = function transformNode(api) {
16
17
  $from = preservedSelection.$from;
17
18
  var selectedParent = $from.parent;
18
19
  var fragment = Fragment.empty;
19
- // top level selections can safely be transformed without checking for depth
20
- var isWithinSelectedRange = $from.depth === 0;
21
- tr.doc.nodesBetween(from, to, function (node) {
22
- // need to only transform selected content, for nested selections nodesBetween includes the path to the selected parent
23
- if (!isWithinSelectedRange && node.eq(selectedParent)) {
24
- isWithinSelectedRange = true;
25
- return true;
20
+ var isList = isListNode(selectedParent);
21
+ var slice = tr.doc.slice(isList ? from - 1 : from, isList ? to + 1 : to);
22
+ slice.content.forEach(function (node) {
23
+ var outputNode = getOutputNodes({
24
+ sourceNode: node,
25
+ targetNodeType: targetType,
26
+ schema: tr.doc.type.schema
27
+ });
28
+ if (outputNode) {
29
+ fragment = fragment.append(Fragment.fromArray(outputNode));
26
30
  }
27
- if (isWithinSelectedRange) {
28
- var outputNode = getOutputNodes({
29
- sourceNode: node,
30
- targetNodeType: targetType,
31
- schema: tr.doc.type.schema
32
- });
33
- if (outputNode) {
34
- fragment = fragment.append(Fragment.fromArray(outputNode));
35
- }
36
- return false;
37
- }
38
- return true;
39
31
  });
40
- tr.replaceWith(preservedSelection.from, preservedSelection.to, fragment);
32
+ tr.replaceWith(isList ? preservedSelection.from - 1 : preservedSelection.from, preservedSelection.to, fragment);
41
33
  return tr;
42
34
  };
43
35
  }
@@ -16,7 +16,6 @@ import { ToolbarDropdownItem, ToolbarDropdownItemSection, ToolbarNestedDropdownM
16
16
  import { fg } from '@atlaskit/platform-feature-flags';
17
17
  import { conditionalHooksFactory } from '@atlaskit/platform-feature-flags-react';
18
18
  import { Box } from '@atlaskit/primitives/compiled';
19
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
20
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
21
20
  import { useBlockMenu } from './block-menu-provider';
22
21
  import { BlockMenuRenderer } from './block-menu-renderer';
@@ -35,7 +34,6 @@ var useConditionalBlockMenuEffect = conditionalHooksFactory(function () {
35
34
  menuTriggerBy = _ref.menuTriggerBy,
36
35
  selectedByShortcutOrDragHandle = _ref.selectedByShortcutOrDragHandle,
37
36
  hasFocus = _ref.hasFocus,
38
- shouldShowBlockMenuForEmptyLine = _ref.shouldShowBlockMenuForEmptyLine,
39
37
  openedViaKeyboard = _ref.openedViaKeyboard,
40
38
  prevIsMenuOpenRef = _ref.prevIsMenuOpenRef;
41
39
  /**
@@ -43,7 +41,7 @@ var useConditionalBlockMenuEffect = conditionalHooksFactory(function () {
43
41
  */
44
42
  useEffect(function () {
45
43
  var _api$userIntent;
46
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine) {
44
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus) {
47
45
  return;
48
46
  }
49
47
 
@@ -63,20 +61,19 @@ var useConditionalBlockMenuEffect = conditionalHooksFactory(function () {
63
61
  // Update the previous state
64
62
  prevIsMenuOpenRef.current = isMenuOpen;
65
63
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : _api$userIntent.commands.setCurrentUserIntent('blockMenuOpen'));
66
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, openedViaKeyboard, prevIsMenuOpenRef]);
64
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, openedViaKeyboard, prevIsMenuOpenRef]);
67
65
  }, function (_ref2) {
68
66
  var api = _ref2.api,
69
67
  isMenuOpen = _ref2.isMenuOpen,
70
68
  menuTriggerBy = _ref2.menuTriggerBy,
71
69
  selectedByShortcutOrDragHandle = _ref2.selectedByShortcutOrDragHandle,
72
70
  hasFocus = _ref2.hasFocus,
73
- shouldShowBlockMenuForEmptyLine = _ref2.shouldShowBlockMenuForEmptyLine,
74
71
  currentUserIntent = _ref2.currentUserIntent,
75
72
  openedViaKeyboard = _ref2.openedViaKeyboard,
76
73
  prevIsMenuOpenRef = _ref2.prevIsMenuOpenRef;
77
74
  useEffect(function () {
78
75
  var _api$userIntent2;
79
- if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
76
+ if (!isMenuOpen || !menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
80
77
  return;
81
78
  }
82
79
 
@@ -96,7 +93,7 @@ var useConditionalBlockMenuEffect = conditionalHooksFactory(function () {
96
93
  // Update the previous state
97
94
  prevIsMenuOpenRef.current = isMenuOpen;
98
95
  api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 || (_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('blockMenuOpen'));
99
- }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, shouldShowBlockMenuForEmptyLine, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
96
+ }, [api, isMenuOpen, menuTriggerBy, selectedByShortcutOrDragHandle, hasFocus, currentUserIntent, openedViaKeyboard, prevIsMenuOpenRef]);
100
97
  });
101
98
  var BlockMenuContent = function BlockMenuContent(_ref3) {
102
99
  var _api$blockMenu;
@@ -159,10 +156,6 @@ var BlockMenu = function BlockMenu(_ref4) {
159
156
  var prevIsMenuOpenRef = useRef(false);
160
157
  var popupRef = useRef(undefined);
161
158
  var hasFocus = (_ref5 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef || popupRef.current && (popupRef.current.contains(document.activeElement) || popupRef.current === document.activeElement)) !== null && _ref5 !== void 0 ? _ref5 : false;
162
- var hasSelection = !!editorView && !editorView.state.selection.empty;
163
- // hasSelection true, always show block menu
164
- // hasSelection false, only show block menu when empty line experiment is enabled
165
- var shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
166
159
  var selectedByShortcutOrDragHandle = !!isSelectedViaDragHandle || !!openedViaKeyboard;
167
160
 
168
161
  // Use conditional hook based on feature flag
@@ -172,7 +165,6 @@ var BlockMenu = function BlockMenu(_ref4) {
172
165
  menuTriggerBy: menuTriggerBy,
173
166
  selectedByShortcutOrDragHandle: selectedByShortcutOrDragHandle,
174
167
  hasFocus: hasFocus,
175
- shouldShowBlockMenuForEmptyLine: shouldShowBlockMenuForEmptyLine,
176
168
  currentUserIntent: fg('platform_editor_toolbar_aifc_user_intent_fix') ? undefined : currentUserIntent,
177
169
  openedViaKeyboard: openedViaKeyboard,
178
170
  prevIsMenuOpenRef: prevIsMenuOpenRef
@@ -209,7 +201,7 @@ var BlockMenu = function BlockMenu(_ref4) {
209
201
  return tr;
210
202
  });
211
203
  };
212
- if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
204
+ if (!menuTriggerBy || !selectedByShortcutOrDragHandle || !hasFocus || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
213
205
  closeMenu();
214
206
  return null;
215
207
  }
@@ -1,12 +1,11 @@
1
1
  import React from 'react';
2
2
  import { ToolbarDropdownItemSection } from '@atlaskit/editor-toolbar';
3
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
4
3
  export var DeleteSection = function DeleteSection(_ref) {
5
4
  var _api$selection;
6
5
  var api = _ref.api,
7
6
  children = _ref.children;
8
7
  var selection = api === null || api === void 0 || (_api$selection = api.selection) === null || _api$selection === void 0 || (_api$selection = _api$selection.sharedState) === null || _api$selection === void 0 || (_api$selection = _api$selection.currentState()) === null || _api$selection === void 0 ? void 0 : _api$selection.selection;
9
- var isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty) && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
8
+ var isEmptyLineSelected = !!(selection !== null && selection !== void 0 && selection.empty);
10
9
  if (isEmptyLineSelected) {
11
10
  return null;
12
11
  }
@@ -1,30 +1,6 @@
1
1
  import { findParentNodeOfType, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
- import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
3
2
  var TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES = true;
4
3
  var getIsFormatMenuHidden = function getIsFormatMenuHidden(selection, schema) {
5
- var nodes = schema.nodes;
6
- if (!nodes) {
7
- return false;
8
- }
9
- if (TRANSFORM_MENU_ENABLED_FOR_ALL_TOP_LEVEL_NODES) {
10
- var disabledOnNodes = [nodes.syncBlock, nodes.bodiedSyncBlock, nodes.rule];
11
- var disabledNode = findSelectedNodeOfType(disabledOnNodes)(selection);
12
- return !!disabledNode;
13
- }
14
- var content;
15
- var allowedNodes = [nodes.paragraph, nodes.heading, nodes.blockquote, nodes.panel, nodes.codeBlock, nodes.bulletList, nodes.orderedList, nodes.taskList, nodes.layoutSection, nodes.expand];
16
- var selectedNode = findSelectedNodeOfType(allowedNodes)(selection);
17
- if (selectedNode) {
18
- content = selectedNode.node;
19
- } else {
20
- var listTypeOrBlockQuoteNode = findParentNodeOfType([nodes.paragraph, nodes.heading, nodes.blockquote, nodes.listItem, nodes.taskItem])(selection);
21
- if (listTypeOrBlockQuoteNode) {
22
- content = listTypeOrBlockQuoteNode.node;
23
- }
24
- }
25
- return !content;
26
- };
27
- var getIsFormatMenuHiddenEmptyLine = function getIsFormatMenuHiddenEmptyLine(selection, schema) {
28
4
  var nodes = schema.nodes;
29
5
  if (!nodes) {
30
6
  return false;
@@ -60,5 +36,5 @@ export var checkIsFormatMenuHidden = function checkIsFormatMenuHidden(api) {
60
36
  if (!selection || !schema || !menuTriggerBy) {
61
37
  return false;
62
38
  }
63
- return expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true) ? getIsFormatMenuHiddenEmptyLine(selection, schema) : getIsFormatMenuHidden(selection, schema);
39
+ return getIsFormatMenuHidden(selection, schema);
64
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "5.1.1",
3
+ "version": "5.1.3",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -44,12 +44,12 @@
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/platform-feature-flags-react": "^0.4.0",
46
46
  "@atlaskit/primitives": "^16.4.0",
47
- "@atlaskit/tmp-editor-statsig": "^14.3.0",
47
+ "@atlaskit/tmp-editor-statsig": "^14.4.0",
48
48
  "@atlaskit/tokens": "^8.4.0",
49
49
  "@babel/runtime": "^7.0.0"
50
50
  },
51
51
  "peerDependencies": {
52
- "@atlaskit/editor-common": "^110.36.0",
52
+ "@atlaskit/editor-common": "^110.37.0",
53
53
  "react": "^18.2.0",
54
54
  "react-intl-next": "npm:react-intl@^5.18.1"
55
55
  },