@atlaskit/editor-plugin-block-menu 3.2.3 → 3.2.4

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-menu
2
2
 
3
+ ## 3.2.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`ef686b3cfdbff`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ef686b3cfdbff) -
8
+ ED-29222: Make empty line experiment dependent on block menu
9
+ - Updated dependencies
10
+
3
11
  ## 3.2.3
4
12
 
5
13
  ### Patch Changes
@@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.formatNode = void 0;
7
7
  var _utils = require("@atlaskit/editor-prosemirror/utils");
8
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
9
  var _expValEqualsNoExposure = require("@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure");
10
+ var _selection = require("./selection");
9
11
  var _layoutTransforms = require("./transforms/layout-transforms");
10
12
  var _transformNodeToTargetType = require("./transforms/transformNodeToTargetType");
11
13
  /**
@@ -98,7 +100,11 @@ var formatNode = exports.formatNode = function formatNode(targetType) {
98
100
  nodePos = selection.$from.pos;
99
101
  }
100
102
  try {
101
- return (0, _transformNodeToTargetType.transformNodeToTargetType)(tr, nodeToFormat, nodePos, targetType);
103
+ var newTr = (0, _transformNodeToTargetType.transformNodeToTargetType)(tr, nodeToFormat, nodePos, targetType);
104
+ if (newTr && (0, _platformFeatureFlags.fg)('platform_editor_block_menu_selection_fix')) {
105
+ return (0, _selection.setSelectionAfterTransform)(newTr, nodePos, targetType);
106
+ }
107
+ return newTr;
102
108
  } catch (_unused) {
103
109
  return null;
104
110
  }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setSelectionAfterTransform = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ /**
9
+ * Sets the appropriate selection after transforming a node to a target type
10
+ * @param newTr - The transaction containing the transformed node
11
+ * @param nodePos - The position of the transformed node
12
+ * @param targetType - The target type the node was transformed to
13
+ * @returns The transaction with the updated selection, or the original transaction if no selection change needed
14
+ */
15
+ var setSelectionAfterTransform = exports.setSelectionAfterTransform = function setSelectionAfterTransform(newTr, nodePos, targetType) {
16
+ // Find the actual node that was transformed to get its positioning
17
+ var transformedNodePos = newTr.doc.resolve(nodePos);
18
+ var transformedNode = transformedNodePos.nodeAfter;
19
+ if (!transformedNode) {
20
+ return newTr;
21
+ }
22
+
23
+ // Check if target type is other than list, text, heading, blockquotes
24
+ var isListNode = targetType === 'bulletList' || targetType === 'orderedList' || targetType === 'taskList';
25
+ var isBlockquote = targetType === 'blockquote';
26
+ var isContainer = ['panel', 'expand', 'codeBlock', 'layoutSection'].includes(targetType);
27
+ if (isListNode || isBlockquote) {
28
+ // For taskList, select all content within the list
29
+ var textStart = transformedNodePos.pos + 1; // Inside the taskList
30
+ var textEnd = transformedNodePos.pos + transformedNode.nodeSize - 1; // End of taskList content
31
+ var textSelection = _state.TextSelection.between(newTr.doc.resolve(textStart), newTr.doc.resolve(textEnd));
32
+ return newTr.setSelection(textSelection);
33
+ } else if (isContainer) {
34
+ // Use NodeSelection for types other than list, text, heading, blockquotes
35
+ var nodeSelection = _state.NodeSelection.create(newTr.doc, transformedNodePos.pos);
36
+ return newTr.setSelection(nodeSelection);
37
+ }
38
+ return newTr;
39
+ };
@@ -80,11 +80,10 @@ var BlockMenu = function BlockMenu(_ref2) {
80
80
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(_styles.DRAG_HANDLE_SELECTOR);
81
81
  var hasFocus = (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? (_ref3 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef) !== null && _ref3 !== void 0 ? _ref3 : false : (_editorView$hasFocus = editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) !== null && _editorView$hasFocus !== void 0 ? _editorView$hasFocus : false;
82
82
  var hasSelection = !!editorView && !editorView.state.selection.empty;
83
- var emptyLineEnabled = (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true);
84
83
 
85
84
  // hasSelection true, always show block menu
86
85
  // hasSelection false, only show block menu when empty line experiment is enabled
87
- var shouldShowBlockMenuForEmptyLine = hasSelection || emptyLineEnabled && !hasSelection;
86
+ var shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('platform_editor_block_menu_empty_line', 'isEnabled', true);
88
87
  (0, _react.useEffect)(function () {
89
88
  var _api$userIntent;
90
89
  if (!isMenuOpen || !menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
@@ -1,5 +1,7 @@
1
1
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
4
+ import { setSelectionAfterTransform } from './selection';
3
5
  import { createDefaultLayoutSection } from './transforms/layout-transforms';
4
6
  import { transformNodeToTargetType } from './transforms/transformNodeToTargetType';
5
7
  /**
@@ -101,7 +103,11 @@ export const formatNode = targetType => {
101
103
  nodePos = selection.$from.pos;
102
104
  }
103
105
  try {
104
- return transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
106
+ const newTr = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
107
+ if (newTr && fg('platform_editor_block_menu_selection_fix')) {
108
+ return setSelectionAfterTransform(newTr, nodePos, targetType);
109
+ }
110
+ return newTr;
105
111
  } catch {
106
112
  return null;
107
113
  }
@@ -0,0 +1,33 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ /**
3
+ * Sets the appropriate selection after transforming a node to a target type
4
+ * @param newTr - The transaction containing the transformed node
5
+ * @param nodePos - The position of the transformed node
6
+ * @param targetType - The target type the node was transformed to
7
+ * @returns The transaction with the updated selection, or the original transaction if no selection change needed
8
+ */
9
+ export const setSelectionAfterTransform = (newTr, nodePos, targetType) => {
10
+ // Find the actual node that was transformed to get its positioning
11
+ const transformedNodePos = newTr.doc.resolve(nodePos);
12
+ const transformedNode = transformedNodePos.nodeAfter;
13
+ if (!transformedNode) {
14
+ return newTr;
15
+ }
16
+
17
+ // Check if target type is other than list, text, heading, blockquotes
18
+ const isListNode = targetType === 'bulletList' || targetType === 'orderedList' || targetType === 'taskList';
19
+ const isBlockquote = targetType === 'blockquote';
20
+ const isContainer = ['panel', 'expand', 'codeBlock', 'layoutSection'].includes(targetType);
21
+ if (isListNode || isBlockquote) {
22
+ // For taskList, select all content within the list
23
+ const textStart = transformedNodePos.pos + 1; // Inside the taskList
24
+ const textEnd = transformedNodePos.pos + transformedNode.nodeSize - 1; // End of taskList content
25
+ const textSelection = TextSelection.between(newTr.doc.resolve(textStart), newTr.doc.resolve(textEnd));
26
+ return newTr.setSelection(textSelection);
27
+ } else if (isContainer) {
28
+ // Use NodeSelection for types other than list, text, heading, blockquotes
29
+ const nodeSelection = NodeSelection.create(newTr.doc, transformedNodePos.pos);
30
+ return newTr.setSelection(nodeSelection);
31
+ }
32
+ return newTr;
33
+ };
@@ -70,11 +70,10 @@ const BlockMenu = ({
70
70
  const targetHandleRef = editorView === null || editorView === void 0 ? void 0 : (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
71
71
  const hasFocus = expValEqualsNoExposure('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? (_ref = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef) !== null && _ref !== void 0 ? _ref : false : (_editorView$hasFocus = editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) !== null && _editorView$hasFocus !== void 0 ? _editorView$hasFocus : false;
72
72
  const hasSelection = !!editorView && !editorView.state.selection.empty;
73
- const emptyLineEnabled = expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
74
73
 
75
74
  // hasSelection true, always show block menu
76
75
  // hasSelection false, only show block menu when empty line experiment is enabled
77
- const shouldShowBlockMenuForEmptyLine = hasSelection || emptyLineEnabled && !hasSelection;
76
+ const shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
78
77
  useEffect(() => {
79
78
  var _api$userIntent;
80
79
  if (!isMenuOpen || !menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
@@ -1,5 +1,7 @@
1
1
  import { findParentNodeOfType, findSelectedNodeOfType, safeInsert as pmSafeInsert } from '@atlaskit/editor-prosemirror/utils';
2
+ import { fg } from '@atlaskit/platform-feature-flags';
2
3
  import { expValEqualsNoExposure } from '@atlaskit/tmp-editor-statsig/exp-val-equals-no-exposure';
4
+ import { setSelectionAfterTransform } from './selection';
3
5
  import { createDefaultLayoutSection } from './transforms/layout-transforms';
4
6
  import { transformNodeToTargetType } from './transforms/transformNodeToTargetType';
5
7
  /**
@@ -92,7 +94,11 @@ export var formatNode = function formatNode(targetType) {
92
94
  nodePos = selection.$from.pos;
93
95
  }
94
96
  try {
95
- return transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
97
+ var newTr = transformNodeToTargetType(tr, nodeToFormat, nodePos, targetType);
98
+ if (newTr && fg('platform_editor_block_menu_selection_fix')) {
99
+ return setSelectionAfterTransform(newTr, nodePos, targetType);
100
+ }
101
+ return newTr;
96
102
  } catch (_unused) {
97
103
  return null;
98
104
  }
@@ -0,0 +1,33 @@
1
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
2
+ /**
3
+ * Sets the appropriate selection after transforming a node to a target type
4
+ * @param newTr - The transaction containing the transformed node
5
+ * @param nodePos - The position of the transformed node
6
+ * @param targetType - The target type the node was transformed to
7
+ * @returns The transaction with the updated selection, or the original transaction if no selection change needed
8
+ */
9
+ export var setSelectionAfterTransform = function setSelectionAfterTransform(newTr, nodePos, targetType) {
10
+ // Find the actual node that was transformed to get its positioning
11
+ var transformedNodePos = newTr.doc.resolve(nodePos);
12
+ var transformedNode = transformedNodePos.nodeAfter;
13
+ if (!transformedNode) {
14
+ return newTr;
15
+ }
16
+
17
+ // Check if target type is other than list, text, heading, blockquotes
18
+ var isListNode = targetType === 'bulletList' || targetType === 'orderedList' || targetType === 'taskList';
19
+ var isBlockquote = targetType === 'blockquote';
20
+ var isContainer = ['panel', 'expand', 'codeBlock', 'layoutSection'].includes(targetType);
21
+ if (isListNode || isBlockquote) {
22
+ // For taskList, select all content within the list
23
+ var textStart = transformedNodePos.pos + 1; // Inside the taskList
24
+ var textEnd = transformedNodePos.pos + transformedNode.nodeSize - 1; // End of taskList content
25
+ var textSelection = TextSelection.between(newTr.doc.resolve(textStart), newTr.doc.resolve(textEnd));
26
+ return newTr.setSelection(textSelection);
27
+ } else if (isContainer) {
28
+ // Use NodeSelection for types other than list, text, heading, blockquotes
29
+ var nodeSelection = NodeSelection.create(newTr.doc, transformedNodePos.pos);
30
+ return newTr.setSelection(nodeSelection);
31
+ }
32
+ return newTr;
33
+ };
@@ -72,11 +72,10 @@ var BlockMenu = function BlockMenu(_ref2) {
72
72
  var targetHandleRef = editorView === null || editorView === void 0 || (_editorView$dom = editorView.dom) === null || _editorView$dom === void 0 ? void 0 : _editorView$dom.querySelector(DRAG_HANDLE_SELECTOR);
73
73
  var hasFocus = expValEqualsNoExposure('platform_editor_block_menu_keyboard_navigation', 'isEnabled', true) ? (_ref3 = (editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) || document.activeElement === targetHandleRef) !== null && _ref3 !== void 0 ? _ref3 : false : (_editorView$hasFocus = editorView === null || editorView === void 0 ? void 0 : editorView.hasFocus()) !== null && _editorView$hasFocus !== void 0 ? _editorView$hasFocus : false;
74
74
  var hasSelection = !!editorView && !editorView.state.selection.empty;
75
- var emptyLineEnabled = expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
76
75
 
77
76
  // hasSelection true, always show block menu
78
77
  // hasSelection false, only show block menu when empty line experiment is enabled
79
- var shouldShowBlockMenuForEmptyLine = hasSelection || emptyLineEnabled && !hasSelection;
78
+ var shouldShowBlockMenuForEmptyLine = hasSelection || !hasSelection && expValEqualsNoExposure('platform_editor_block_menu_empty_line', 'isEnabled', true);
80
79
  useEffect(function () {
81
80
  var _api$userIntent;
82
81
  if (!isMenuOpen || !menuTriggerBy || !isSelectedViaDragHandle || !hasFocus || !shouldShowBlockMenuForEmptyLine || ['resizing', 'dragging'].includes(currentUserIntent || '')) {
@@ -0,0 +1,10 @@
1
+ import { type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { FormatNodeTargetType } from './transforms/types';
3
+ /**
4
+ * Sets the appropriate selection after transforming a node to a target type
5
+ * @param newTr - The transaction containing the transformed node
6
+ * @param nodePos - The position of the transformed node
7
+ * @param targetType - The target type the node was transformed to
8
+ * @returns The transaction with the updated selection, or the original transaction if no selection change needed
9
+ */
10
+ export declare const setSelectionAfterTransform: (newTr: Transaction, nodePos: number, targetType: FormatNodeTargetType) => Transaction;
@@ -0,0 +1,10 @@
1
+ import { type Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import type { FormatNodeTargetType } from './transforms/types';
3
+ /**
4
+ * Sets the appropriate selection after transforming a node to a target type
5
+ * @param newTr - The transaction containing the transformed node
6
+ * @param nodePos - The position of the transformed node
7
+ * @param targetType - The target type the node was transformed to
8
+ * @returns The transaction with the updated selection, or the original transaction if no selection change needed
9
+ */
10
+ export declare const setSelectionAfterTransform: (newTr: Transaction, nodePos: number, targetType: FormatNodeTargetType) => Transaction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-menu",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "description": "BlockMenu plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -42,7 +42,7 @@
42
42
  "@atlaskit/icon-lab": "^5.7.0",
43
43
  "@atlaskit/platform-feature-flags": "^1.1.0",
44
44
  "@atlaskit/primitives": "^14.15.0",
45
- "@atlaskit/tmp-editor-statsig": "^12.27.0",
45
+ "@atlaskit/tmp-editor-statsig": "^12.28.0",
46
46
  "@atlaskit/tokens": "^6.3.0",
47
47
  "@babel/runtime": "^7.0.0"
48
48
  },
@@ -90,6 +90,9 @@
90
90
  "platform-feature-flags": {
91
91
  "platform_editor_adf_with_localid": {
92
92
  "type": "boolean"
93
+ },
94
+ "platform_editor_block_menu_selection_fix": {
95
+ "type": "boolean"
93
96
  }
94
97
  }
95
98
  }