@atlaskit/editor-plugin-text-formatting 2.2.7 → 2.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/ui/FloatingToolbarComponent.js +18 -10
  3. package/dist/cjs/ui/Toolbar/dropdown-menu.js +2 -2
  4. package/dist/cjs/ui/Toolbar/formatting-in-selection-utils.js +27 -1
  5. package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +18 -13
  6. package/dist/cjs/ui/Toolbar/hooks/use-icon-list.js +3 -1
  7. package/dist/cjs/ui/Toolbar/single-toolbar-buttons.js +7 -3
  8. package/dist/es2019/ui/FloatingToolbarComponent.js +19 -11
  9. package/dist/es2019/ui/Toolbar/dropdown-menu.js +2 -2
  10. package/dist/es2019/ui/Toolbar/formatting-in-selection-utils.js +19 -0
  11. package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +18 -13
  12. package/dist/es2019/ui/Toolbar/hooks/use-icon-list.js +3 -1
  13. package/dist/es2019/ui/Toolbar/single-toolbar-buttons.js +7 -3
  14. package/dist/esm/ui/FloatingToolbarComponent.js +19 -11
  15. package/dist/esm/ui/Toolbar/dropdown-menu.js +2 -2
  16. package/dist/esm/ui/Toolbar/formatting-in-selection-utils.js +26 -0
  17. package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +18 -13
  18. package/dist/esm/ui/Toolbar/hooks/use-icon-list.js +3 -1
  19. package/dist/esm/ui/Toolbar/single-toolbar-buttons.js +7 -3
  20. package/dist/types/ui/Toolbar/dropdown-menu.d.ts +2 -2
  21. package/dist/types/ui/Toolbar/formatting-in-selection-utils.d.ts +3 -0
  22. package/dist/types/ui/Toolbar/hooks/formatting-icons.d.ts +3 -1
  23. package/dist/types/ui/Toolbar/single-toolbar-buttons.d.ts +2 -2
  24. package/dist/types-ts4.5/ui/Toolbar/dropdown-menu.d.ts +2 -2
  25. package/dist/types-ts4.5/ui/Toolbar/formatting-in-selection-utils.d.ts +3 -0
  26. package/dist/types-ts4.5/ui/Toolbar/hooks/formatting-icons.d.ts +3 -1
  27. package/dist/types-ts4.5/ui/Toolbar/single-toolbar-buttons.d.ts +2 -2
  28. package/package.json +8 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 2.2.8
4
+
5
+ ### Patch Changes
6
+
7
+ - [#159038](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/159038)
8
+ [`939f37dbeeb94`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/939f37dbeeb94) -
9
+ [ux] Highlight the common formatting mark button when selection has mixed style but share a common
10
+ one
11
+
3
12
  ## 2.2.7
4
13
 
5
14
  ### Patch Changes
@@ -127,15 +127,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
127
127
  var textFormattingState = useSharedState(api);
128
128
  var formattingIsPresent = textFormattingState.formattingIsPresent,
129
129
  formattingIconState = (0, _objectWithoutProperties2.default)(textFormattingState, _excluded);
130
- var defaultIcons = (0, _formattingIcons.useFormattingIcons)({
131
- schema: editorView.state.schema,
132
- intl: intl,
133
- isToolbarDisabled: FloatingToolbarSettings.disabled,
134
- editorAnalyticsAPI: editorAnalyticsAPI,
135
- textFormattingState: formattingIconState,
136
- toolbarType: FloatingToolbarSettings.toolbarType
137
- });
138
130
  var hasMultiplePartsWithFormattingSelected;
131
+ var commonActiveMarks = [];
139
132
  if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
140
133
  var selection = editorView.state.selection;
141
134
  var from = selection.from,
@@ -144,7 +137,22 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
144
137
  hasMultiplePartsWithFormattingSelected = (0, _formattingInSelectionUtils.hasMultiplePartsWithFormattingInSelection)({
145
138
  selectedContent: selectedContent
146
139
  });
140
+ if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10')) {
141
+ commonActiveMarks = (0, _formattingInSelectionUtils.getCommonActiveMarks)({
142
+ selectedContent: selectedContent
143
+ });
144
+ }
147
145
  }
146
+ var defaultIcons = (0, _formattingIcons.useFormattingIcons)({
147
+ schema: editorView.state.schema,
148
+ intl: intl,
149
+ isToolbarDisabled: FloatingToolbarSettings.disabled,
150
+ editorAnalyticsAPI: editorAnalyticsAPI,
151
+ textFormattingState: formattingIconState,
152
+ toolbarType: FloatingToolbarSettings.toolbarType,
153
+ hasMultiplePartsWithFormattingSelected: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? hasMultiplePartsWithFormattingSelected : undefined,
154
+ commonActiveMarks: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? commonActiveMarks : undefined
155
+ });
148
156
  var _useIconList = (0, _useIconList2.useIconList)({
149
157
  icons: defaultIcons,
150
158
  iconTypeList: _constants.DefaultFloatingToolbarButtonsNext,
@@ -175,7 +183,7 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
175
183
  items: singleItems,
176
184
  editorView: editorView,
177
185
  isReducedSpacing: false,
178
- shouldUnselect: hasMultiplePartsWithFormattingSelected
186
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
179
187
  }), (0, _react2.jsx)(_dropdownMenu.FormattingTextDropdownMenu, {
180
188
  editorView: editorView,
181
189
  items: items,
@@ -185,7 +193,7 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
185
193
  hasMoreButton: FloatingToolbarSettings.hasMoreButton,
186
194
  intl: intl,
187
195
  toolbarType: FloatingToolbarSettings.toolbarType,
188
- shouldUnselect: hasMultiplePartsWithFormattingSelected
196
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
189
197
  }));
190
198
  };
191
199
  var FloatingToolbarTextFormalWithIntl = exports.FloatingToolbarTextFormalWithIntl = (0, _reactIntlNext.injectIntl)(FloatingToolbarTextFormat);
@@ -31,7 +31,7 @@ var FormattingTextDropdownMenu = exports.FormattingTextDropdownMenu = /*#__PURE_
31
31
  hasMoreButton = _ref.hasMoreButton,
32
32
  intl = _ref.intl,
33
33
  toolbarType = _ref.toolbarType,
34
- shouldUnselect = _ref.shouldUnselect;
34
+ hasMultiplePartsWithFormattingSelected = _ref.hasMultiplePartsWithFormattingSelected;
35
35
  var _useMenuState = (0, _menuState.useMenuState)(),
36
36
  _useMenuState2 = (0, _slicedToArray2.default)(_useMenuState, 3),
37
37
  isMenuOpen = _useMenuState2[0],
@@ -59,7 +59,7 @@ var FormattingTextDropdownMenu = exports.FormattingTextDropdownMenu = /*#__PURE_
59
59
  var defaultIconName = (_items$0$items$2 = items[0].items[0]) === null || _items$0$items$2 === void 0 ? void 0 : _items$0$items$2.value.name;
60
60
  var iconBefore;
61
61
  var activeIconName = defaultIconName;
62
- if (shouldUnselect && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
62
+ if (hasMultiplePartsWithFormattingSelected && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
63
63
  iconBefore = defaultIcon;
64
64
  } else {
65
65
  iconBefore = activeItem ? activeItem === null || activeItem === void 0 ? void 0 : activeItem.elemBefore : defaultIcon;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.hasMultiplePartsWithFormattingInSelection = void 0;
6
+ exports.hasMultiplePartsWithFormattingInSelection = exports.getCommonActiveMarks = void 0;
7
7
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
8
8
  var _types = require("./types");
9
9
  var isMarkInIconTypes = function isMarkInIconTypes(node) {
@@ -29,4 +29,30 @@ var hasMultiplePartsWithFormattingInSelection = exports.hasMultiplePartsWithForm
29
29
  return isMarkInIconTypes(child) ? child.marks : undefined;
30
30
  }).filter(Boolean);
31
31
  return marks.length > 1;
32
+ };
33
+ var getCommonActiveMarks = exports.getCommonActiveMarks = function getCommonActiveMarks(_ref2) {
34
+ var selectedContent = _ref2.selectedContent;
35
+ if (!selectedContent) {
36
+ return [];
37
+ }
38
+ // filter out fragment node contains only spaces
39
+ var filteredSelectedContent = selectedContent.filter(function (child) {
40
+ var _child$text;
41
+ return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
42
+ });
43
+
44
+ // find the active mark type in first part
45
+ var firstPartMarks = selectedContent[0].marks.map(function (mark) {
46
+ return mark.type.name;
47
+ });
48
+
49
+ // check if all other parts have the same mark type as the first part and return the common mark types
50
+ var commonMarkTypes = firstPartMarks.filter(function (mark) {
51
+ return filteredSelectedContent.every(function (child) {
52
+ return child.marks.some(function (m) {
53
+ return m.type.name === mark;
54
+ });
55
+ });
56
+ });
57
+ return commonMarkTypes;
32
58
  };
@@ -17,6 +17,7 @@ var _angleBracketsEditorCode = _interopRequireDefault(require("@atlaskit/icon/co
17
17
  var _textBoldEditorBold = _interopRequireDefault(require("@atlaskit/icon/core/migration/text-bold--editor-bold"));
18
18
  var _textItalicEditorItalic = _interopRequireDefault(require("@atlaskit/icon/core/migration/text-italic--editor-italic"));
19
19
  var _textUnderline = _interopRequireDefault(require("@atlaskit/icon/core/text-underline"));
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
21
22
  var _commands = require("../../../pm-plugins/commands");
22
23
  var _icons = require("../icons");
@@ -172,7 +173,7 @@ var getIcon = function getIcon(_ref) {
172
173
  };
173
174
  };
174
175
  var IconsMarkSchema = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.IconTypes.strong, 'strong'), _types.IconTypes.em, 'em'), _types.IconTypes.strike, 'strike'), _types.IconTypes.code, 'code'), _types.IconTypes.underline, 'underline'), _types.IconTypes.superscript, 'subsup'), _types.IconTypes.subscript, 'subsup');
175
- var buildMenuIconState = function buildMenuIconState(iconMark) {
176
+ var buildMenuIconState = function buildMenuIconState(iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks) {
176
177
  return function (_ref2) {
177
178
  var schema = _ref2.schema,
178
179
  textFormattingState = _ref2.textFormattingState;
@@ -187,7 +188,7 @@ var buildMenuIconState = function buildMenuIconState(iconMark) {
187
188
  hasSchemaMark: hasSchemaMark
188
189
  };
189
190
  }
190
- var isActive = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Active")];
191
+ var isActive = hasMultiplePartsWithFormattingSelected && !(commonActiveMarks !== null && commonActiveMarks !== void 0 && commonActiveMarks.includes(iconMark)) && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? false : textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Active")];
191
192
  var isDisabled = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Disabled")];
192
193
  var isHidden = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Hidden")];
193
194
  return {
@@ -198,8 +199,8 @@ var buildMenuIconState = function buildMenuIconState(iconMark) {
198
199
  };
199
200
  };
200
201
  };
201
- var buildIcon = function buildIcon(iconMark, editorAnalyticsAPI, toolbarType) {
202
- var getState = buildMenuIconState(iconMark);
202
+ var buildIcon = function buildIcon(iconMark, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks) {
203
+ var getState = buildMenuIconState(iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
203
204
  return function (_ref3) {
204
205
  var schema = _ref3.schema,
205
206
  textFormattingState = _ref3.textFormattingState,
@@ -235,21 +236,25 @@ var useFormattingIcons = exports.useFormattingIcons = function useFormattingIcon
235
236
  schema = _ref4.schema,
236
237
  intl = _ref4.intl,
237
238
  editorAnalyticsAPI = _ref4.editorAnalyticsAPI,
238
- toolbarType = _ref4.toolbarType;
239
+ toolbarType = _ref4.toolbarType,
240
+ hasMultiplePartsWithFormattingSelected = _ref4.hasMultiplePartsWithFormattingSelected,
241
+ commonActiveMarks = _ref4.commonActiveMarks;
239
242
  var props = {
240
243
  schema: schema,
241
244
  textFormattingState: textFormattingState,
242
245
  intl: intl,
243
246
  isToolbarDisabled: Boolean(isToolbarDisabled),
244
- toolbarType: toolbarType
247
+ toolbarType: toolbarType,
248
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected,
249
+ commonActiveMarks: commonActiveMarks
245
250
  };
246
- var buildStrongIcon = buildIcon(_types.IconTypes.strong, editorAnalyticsAPI, toolbarType);
247
- var buildEmIcon = buildIcon(_types.IconTypes.em, editorAnalyticsAPI, toolbarType);
248
- var buildUnderlineIcon = buildIcon(_types.IconTypes.underline, editorAnalyticsAPI, toolbarType);
249
- var buildStrikeIcon = buildIcon(_types.IconTypes.strike, editorAnalyticsAPI, toolbarType);
250
- var buildCodeIcon = buildIcon(_types.IconTypes.code, editorAnalyticsAPI, toolbarType);
251
- var buildSubscriptIcon = buildIcon(_types.IconTypes.subscript, editorAnalyticsAPI, toolbarType);
252
- var buildSuperscriptIcon = buildIcon(_types.IconTypes.superscript, editorAnalyticsAPI, toolbarType);
251
+ var buildStrongIcon = buildIcon(_types.IconTypes.strong, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
252
+ var buildEmIcon = buildIcon(_types.IconTypes.em, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
253
+ var buildUnderlineIcon = buildIcon(_types.IconTypes.underline, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
254
+ var buildStrikeIcon = buildIcon(_types.IconTypes.strike, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
255
+ var buildCodeIcon = buildIcon(_types.IconTypes.code, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
256
+ var buildSubscriptIcon = buildIcon(_types.IconTypes.subscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
257
+ var buildSuperscriptIcon = buildIcon(_types.IconTypes.superscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
253
258
  var strongIcon = buildStrongIcon(props);
254
259
  var emIcon = buildEmIcon(props);
255
260
  var underlineIcon = buildUnderlineIcon(props);
@@ -18,7 +18,9 @@ var useIconList = exports.useIconList = function useIconList(_ref) {
18
18
  if (!icon || !icon.iconMark) {
19
19
  return acc;
20
20
  }
21
- if (shouldUnselect && icon.isActive && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7')) {
21
+ if (
22
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
23
+ shouldUnselect && icon.isActive && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') && !(0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10')) {
22
24
  icon.isActive = false;
23
25
  }
24
26
  var isIconSingleButton = iconTypeList.includes(icon.iconMark);
@@ -24,7 +24,7 @@ var SingleToolbarButtons = exports.SingleToolbarButtons = /*#__PURE__*/_react.de
24
24
  var items = _ref.items,
25
25
  isReducedSpacing = _ref.isReducedSpacing,
26
26
  editorView = _ref.editorView,
27
- shouldUnselect = _ref.shouldUnselect;
27
+ hasMultiplePartsWithFormattingSelected = _ref.hasMultiplePartsWithFormattingSelected;
28
28
  var onClick = (0, _react.useCallback)(function (command) {
29
29
  return function () {
30
30
  command(editorView.state, editorView.dispatch);
@@ -49,11 +49,15 @@ var SingleToolbarButtons = exports.SingleToolbarButtons = /*#__PURE__*/_react.de
49
49
  buttonId: item.buttonId,
50
50
  spacing: isReducedSpacing ? 'none' : 'default',
51
51
  onClick: onClick(item.command),
52
- selected: shouldUnselect && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') ? false : item.isActive,
52
+ selected:
53
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
54
+ hasMultiplePartsWithFormattingSelected && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') && !(0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? false : item.isActive,
53
55
  disabled: item.isDisabled,
54
56
  title: item.tooltipElement,
55
57
  iconBefore: item.iconElement,
56
- "aria-pressed": shouldUnselect && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') ? false : item.isActive,
58
+ "aria-pressed":
59
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
60
+ hasMultiplePartsWithFormattingSelected && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_7') && !(0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? false : item.isActive,
57
61
  "aria-label": (_item$ariaLabel = item['aria-label']) !== null && _item$ariaLabel !== void 0 ? _item$ariaLabel : String(item.content),
58
62
  "aria-keyshortcuts": item['aria-keyshortcuts']
59
63
  });
@@ -15,7 +15,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
15
15
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
16
16
  import { DefaultFloatingToolbarButtonsNext } from './Toolbar/constants';
17
17
  import { FormattingTextDropdownMenu } from './Toolbar/dropdown-menu';
18
- import { hasMultiplePartsWithFormattingInSelection } from './Toolbar/formatting-in-selection-utils';
18
+ import { getCommonActiveMarks, hasMultiplePartsWithFormattingInSelection } from './Toolbar/formatting-in-selection-utils';
19
19
  import { useClearIcon } from './Toolbar/hooks/clear-formatting-icon';
20
20
  import { useFormattingIcons } from './Toolbar/hooks/formatting-icons';
21
21
  import { useIconList } from './Toolbar/hooks/use-icon-list';
@@ -120,15 +120,8 @@ const FloatingToolbarTextFormat = ({
120
120
  formattingIsPresent,
121
121
  ...formattingIconState
122
122
  } = textFormattingState;
123
- const defaultIcons = useFormattingIcons({
124
- schema: editorView.state.schema,
125
- intl,
126
- isToolbarDisabled: FloatingToolbarSettings.disabled,
127
- editorAnalyticsAPI,
128
- textFormattingState: formattingIconState,
129
- toolbarType: FloatingToolbarSettings.toolbarType
130
- });
131
123
  let hasMultiplePartsWithFormattingSelected;
124
+ let commonActiveMarks = [];
132
125
  if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
133
126
  const {
134
127
  selection
@@ -141,7 +134,22 @@ const FloatingToolbarTextFormat = ({
141
134
  hasMultiplePartsWithFormattingSelected = hasMultiplePartsWithFormattingInSelection({
142
135
  selectedContent
143
136
  });
137
+ if (fg('platform_editor_controls_patch_10')) {
138
+ commonActiveMarks = getCommonActiveMarks({
139
+ selectedContent
140
+ });
141
+ }
144
142
  }
143
+ const defaultIcons = useFormattingIcons({
144
+ schema: editorView.state.schema,
145
+ intl,
146
+ isToolbarDisabled: FloatingToolbarSettings.disabled,
147
+ editorAnalyticsAPI,
148
+ textFormattingState: formattingIconState,
149
+ toolbarType: FloatingToolbarSettings.toolbarType,
150
+ hasMultiplePartsWithFormattingSelected: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? hasMultiplePartsWithFormattingSelected : undefined,
151
+ commonActiveMarks: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? commonActiveMarks : undefined
152
+ });
145
153
  const {
146
154
  dropdownItems,
147
155
  singleItems
@@ -173,7 +181,7 @@ const FloatingToolbarTextFormat = ({
173
181
  items: singleItems,
174
182
  editorView: editorView,
175
183
  isReducedSpacing: false,
176
- shouldUnselect: hasMultiplePartsWithFormattingSelected
184
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
177
185
  }), jsx(FormattingTextDropdownMenu, {
178
186
  editorView: editorView,
179
187
  items: items,
@@ -183,7 +191,7 @@ const FloatingToolbarTextFormat = ({
183
191
  hasMoreButton: FloatingToolbarSettings.hasMoreButton,
184
192
  intl: intl,
185
193
  toolbarType: FloatingToolbarSettings.toolbarType,
186
- shouldUnselect: hasMultiplePartsWithFormattingSelected
194
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
187
195
  }));
188
196
  };
189
197
  export const FloatingToolbarTextFormalWithIntl = injectIntl(FloatingToolbarTextFormat);
@@ -19,7 +19,7 @@ export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
19
19
  hasMoreButton,
20
20
  intl,
21
21
  toolbarType,
22
- shouldUnselect
22
+ hasMultiplePartsWithFormattingSelected
23
23
  }) => {
24
24
  var _items$0$items$, _items$0$items$2;
25
25
  const [isMenuOpen, toggleMenu, closeMenu] = useMenuState();
@@ -40,7 +40,7 @@ export const FormattingTextDropdownMenu = /*#__PURE__*/React.memo(({
40
40
  const defaultIconName = (_items$0$items$2 = items[0].items[0]) === null || _items$0$items$2 === void 0 ? void 0 : _items$0$items$2.value.name;
41
41
  let iconBefore;
42
42
  let activeIconName = defaultIconName;
43
- if (shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
43
+ if (hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
44
44
  iconBefore = defaultIcon;
45
45
  } else {
46
46
  iconBefore = activeItem ? activeItem === null || activeItem === void 0 ? void 0 : activeItem.elemBefore : defaultIcon;
@@ -16,4 +16,23 @@ export const hasMultiplePartsWithFormattingInSelection = ({
16
16
  }
17
17
  const marks = selectedContent.map(child => isMarkInIconTypes(child) ? child.marks : undefined).filter(Boolean);
18
18
  return marks.length > 1;
19
+ };
20
+ export const getCommonActiveMarks = ({
21
+ selectedContent
22
+ }) => {
23
+ if (!selectedContent) {
24
+ return [];
25
+ }
26
+ // filter out fragment node contains only spaces
27
+ const filteredSelectedContent = selectedContent.filter(child => {
28
+ var _child$text;
29
+ return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
30
+ });
31
+
32
+ // find the active mark type in first part
33
+ const firstPartMarks = selectedContent[0].marks.map(mark => mark.type.name);
34
+
35
+ // check if all other parts have the same mark type as the first part and return the common mark types
36
+ const commonMarkTypes = firstPartMarks.filter(mark => filteredSelectedContent.every(child => child.marks.some(m => m.type.name === mark)));
37
+ return commonMarkTypes;
19
38
  };
@@ -15,6 +15,7 @@ import AngleBracketsIcon from '@atlaskit/icon/core/migration/angle-brackets--edi
15
15
  import BoldIcon from '@atlaskit/icon/core/migration/text-bold--editor-bold';
16
16
  import ItalicIcon from '@atlaskit/icon/core/migration/text-italic--editor-italic';
17
17
  import UnderlineIcon from '@atlaskit/icon/core/text-underline';
18
+ import { fg } from '@atlaskit/platform-feature-flags';
18
19
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
19
20
  import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../pm-plugins/commands';
20
21
  import { Strikethrough, Subscript, Superscript } from '../icons';
@@ -164,7 +165,7 @@ const IconsMarkSchema = {
164
165
  [IconTypes.superscript]: 'subsup',
165
166
  [IconTypes.subscript]: 'subsup'
166
167
  };
167
- const buildMenuIconState = iconMark => ({
168
+ const buildMenuIconState = (iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks) => ({
168
169
  schema,
169
170
  textFormattingState
170
171
  }) => {
@@ -179,7 +180,7 @@ const buildMenuIconState = iconMark => ({
179
180
  hasSchemaMark
180
181
  };
181
182
  }
182
- const isActive = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState[`${iconMark}Active`];
183
+ const isActive = hasMultiplePartsWithFormattingSelected && !(commonActiveMarks !== null && commonActiveMarks !== void 0 && commonActiveMarks.includes(iconMark)) && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? false : textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState[`${iconMark}Active`];
183
184
  const isDisabled = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState[`${iconMark}Disabled`];
184
185
  const isHidden = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState[`${iconMark}Hidden`];
185
186
  return {
@@ -189,8 +190,8 @@ const buildMenuIconState = iconMark => ({
189
190
  hasSchemaMark
190
191
  };
191
192
  };
192
- const buildIcon = (iconMark, editorAnalyticsAPI, toolbarType) => {
193
- const getState = buildMenuIconState(iconMark);
193
+ const buildIcon = (iconMark, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks) => {
194
+ const getState = buildMenuIconState(iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
194
195
  return ({
195
196
  schema,
196
197
  textFormattingState,
@@ -225,22 +226,26 @@ export const useFormattingIcons = ({
225
226
  schema,
226
227
  intl,
227
228
  editorAnalyticsAPI,
228
- toolbarType
229
+ toolbarType,
230
+ hasMultiplePartsWithFormattingSelected,
231
+ commonActiveMarks
229
232
  }) => {
230
233
  const props = {
231
234
  schema,
232
235
  textFormattingState,
233
236
  intl,
234
237
  isToolbarDisabled: Boolean(isToolbarDisabled),
235
- toolbarType
238
+ toolbarType,
239
+ hasMultiplePartsWithFormattingSelected,
240
+ commonActiveMarks
236
241
  };
237
- const buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI, toolbarType);
238
- const buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI, toolbarType);
239
- const buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI, toolbarType);
240
- const buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI, toolbarType);
241
- const buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI, toolbarType);
242
- const buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI, toolbarType);
243
- const buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI, toolbarType);
242
+ const buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
243
+ const buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
244
+ const buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
245
+ const buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
246
+ const buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
247
+ const buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
248
+ const buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
244
249
  const strongIcon = buildStrongIcon(props);
245
250
  const emIcon = buildEmIcon(props);
246
251
  const underlineIcon = buildUnderlineIcon(props);
@@ -11,7 +11,9 @@ export const useIconList = ({
11
11
  if (!icon || !icon.iconMark) {
12
12
  return acc;
13
13
  }
14
- if (shouldUnselect && icon.isActive && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
14
+ if (
15
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
16
+ shouldUnselect && icon.isActive && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10')) {
15
17
  icon.isActive = false;
16
18
  }
17
19
  const isIconSingleButton = iconTypeList.includes(icon.iconMark);
@@ -14,7 +14,7 @@ export const SingleToolbarButtons = /*#__PURE__*/React.memo(({
14
14
  items,
15
15
  isReducedSpacing,
16
16
  editorView,
17
- shouldUnselect
17
+ hasMultiplePartsWithFormattingSelected
18
18
  }) => {
19
19
  const onClick = useCallback(command => {
20
20
  return () => {
@@ -40,11 +40,15 @@ export const SingleToolbarButtons = /*#__PURE__*/React.memo(({
40
40
  buttonId: item.buttonId,
41
41
  spacing: isReducedSpacing ? 'none' : 'default',
42
42
  onClick: onClick(item.command),
43
- selected: shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') ? false : item.isActive,
43
+ selected:
44
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
45
+ hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10') ? false : item.isActive,
44
46
  disabled: item.isDisabled,
45
47
  title: item.tooltipElement,
46
48
  iconBefore: item.iconElement,
47
- "aria-pressed": shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') ? false : item.isActive,
49
+ "aria-pressed":
50
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
51
+ hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10') ? false : item.isActive,
48
52
  "aria-label": (_item$ariaLabel = item['aria-label']) !== null && _item$ariaLabel !== void 0 ? _item$ariaLabel : String(item.content),
49
53
  "aria-keyshortcuts": item['aria-keyshortcuts']
50
54
  });
@@ -17,7 +17,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
17
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
18
18
  import { DefaultFloatingToolbarButtonsNext } from './Toolbar/constants';
19
19
  import { FormattingTextDropdownMenu } from './Toolbar/dropdown-menu';
20
- import { hasMultiplePartsWithFormattingInSelection } from './Toolbar/formatting-in-selection-utils';
20
+ import { getCommonActiveMarks, hasMultiplePartsWithFormattingInSelection } from './Toolbar/formatting-in-selection-utils';
21
21
  import { useClearIcon } from './Toolbar/hooks/clear-formatting-icon';
22
22
  import { useFormattingIcons } from './Toolbar/hooks/formatting-icons';
23
23
  import { useIconList } from './Toolbar/hooks/use-icon-list';
@@ -118,15 +118,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
118
118
  var textFormattingState = useSharedState(api);
119
119
  var formattingIsPresent = textFormattingState.formattingIsPresent,
120
120
  formattingIconState = _objectWithoutProperties(textFormattingState, _excluded);
121
- var defaultIcons = useFormattingIcons({
122
- schema: editorView.state.schema,
123
- intl: intl,
124
- isToolbarDisabled: FloatingToolbarSettings.disabled,
125
- editorAnalyticsAPI: editorAnalyticsAPI,
126
- textFormattingState: formattingIconState,
127
- toolbarType: FloatingToolbarSettings.toolbarType
128
- });
129
121
  var hasMultiplePartsWithFormattingSelected;
122
+ var commonActiveMarks = [];
130
123
  if (editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
131
124
  var selection = editorView.state.selection;
132
125
  var from = selection.from,
@@ -135,7 +128,22 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
135
128
  hasMultiplePartsWithFormattingSelected = hasMultiplePartsWithFormattingInSelection({
136
129
  selectedContent: selectedContent
137
130
  });
131
+ if (fg('platform_editor_controls_patch_10')) {
132
+ commonActiveMarks = getCommonActiveMarks({
133
+ selectedContent: selectedContent
134
+ });
135
+ }
138
136
  }
137
+ var defaultIcons = useFormattingIcons({
138
+ schema: editorView.state.schema,
139
+ intl: intl,
140
+ isToolbarDisabled: FloatingToolbarSettings.disabled,
141
+ editorAnalyticsAPI: editorAnalyticsAPI,
142
+ textFormattingState: formattingIconState,
143
+ toolbarType: FloatingToolbarSettings.toolbarType,
144
+ hasMultiplePartsWithFormattingSelected: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? hasMultiplePartsWithFormattingSelected : undefined,
145
+ commonActiveMarks: editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? commonActiveMarks : undefined
146
+ });
139
147
  var _useIconList = useIconList({
140
148
  icons: defaultIcons,
141
149
  iconTypeList: DefaultFloatingToolbarButtonsNext,
@@ -166,7 +174,7 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
166
174
  items: singleItems,
167
175
  editorView: editorView,
168
176
  isReducedSpacing: false,
169
- shouldUnselect: hasMultiplePartsWithFormattingSelected
177
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
170
178
  }), jsx(FormattingTextDropdownMenu, {
171
179
  editorView: editorView,
172
180
  items: items,
@@ -176,7 +184,7 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
176
184
  hasMoreButton: FloatingToolbarSettings.hasMoreButton,
177
185
  intl: intl,
178
186
  toolbarType: FloatingToolbarSettings.toolbarType,
179
- shouldUnselect: hasMultiplePartsWithFormattingSelected
187
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected
180
188
  }));
181
189
  };
182
190
  export var FloatingToolbarTextFormalWithIntl = injectIntl(FloatingToolbarTextFormat);
@@ -21,7 +21,7 @@ export var FormattingTextDropdownMenu = /*#__PURE__*/React.memo(function (_ref)
21
21
  hasMoreButton = _ref.hasMoreButton,
22
22
  intl = _ref.intl,
23
23
  toolbarType = _ref.toolbarType,
24
- shouldUnselect = _ref.shouldUnselect;
24
+ hasMultiplePartsWithFormattingSelected = _ref.hasMultiplePartsWithFormattingSelected;
25
25
  var _useMenuState = useMenuState(),
26
26
  _useMenuState2 = _slicedToArray(_useMenuState, 3),
27
27
  isMenuOpen = _useMenuState2[0],
@@ -49,7 +49,7 @@ export var FormattingTextDropdownMenu = /*#__PURE__*/React.memo(function (_ref)
49
49
  var defaultIconName = (_items$0$items$2 = items[0].items[0]) === null || _items$0$items$2 === void 0 ? void 0 : _items$0$items$2.value.name;
50
50
  var iconBefore;
51
51
  var activeIconName = defaultIconName;
52
- if (shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
52
+ if (hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
53
53
  iconBefore = defaultIcon;
54
54
  } else {
55
55
  iconBefore = activeItem ? activeItem === null || activeItem === void 0 ? void 0 : activeItem.elemBefore : defaultIcon;
@@ -23,4 +23,30 @@ export var hasMultiplePartsWithFormattingInSelection = function hasMultipleParts
23
23
  return isMarkInIconTypes(child) ? child.marks : undefined;
24
24
  }).filter(Boolean);
25
25
  return marks.length > 1;
26
+ };
27
+ export var getCommonActiveMarks = function getCommonActiveMarks(_ref2) {
28
+ var selectedContent = _ref2.selectedContent;
29
+ if (!selectedContent) {
30
+ return [];
31
+ }
32
+ // filter out fragment node contains only spaces
33
+ var filteredSelectedContent = selectedContent.filter(function (child) {
34
+ var _child$text;
35
+ return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
36
+ });
37
+
38
+ // find the active mark type in first part
39
+ var firstPartMarks = selectedContent[0].marks.map(function (mark) {
40
+ return mark.type.name;
41
+ });
42
+
43
+ // check if all other parts have the same mark type as the first part and return the common mark types
44
+ var commonMarkTypes = firstPartMarks.filter(function (mark) {
45
+ return filteredSelectedContent.every(function (child) {
46
+ return child.marks.some(function (m) {
47
+ return m.type.name === mark;
48
+ });
49
+ });
50
+ });
51
+ return commonMarkTypes;
26
52
  };
@@ -16,6 +16,7 @@ import AngleBracketsIcon from '@atlaskit/icon/core/migration/angle-brackets--edi
16
16
  import BoldIcon from '@atlaskit/icon/core/migration/text-bold--editor-bold';
17
17
  import ItalicIcon from '@atlaskit/icon/core/migration/text-italic--editor-italic';
18
18
  import UnderlineIcon from '@atlaskit/icon/core/text-underline';
19
+ import { fg } from '@atlaskit/platform-feature-flags';
19
20
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
20
21
  import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../../../pm-plugins/commands';
21
22
  import { Strikethrough, Subscript, Superscript } from '../icons';
@@ -164,7 +165,7 @@ var getIcon = function getIcon(_ref) {
164
165
  };
165
166
  };
166
167
  var IconsMarkSchema = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, IconTypes.strong, 'strong'), IconTypes.em, 'em'), IconTypes.strike, 'strike'), IconTypes.code, 'code'), IconTypes.underline, 'underline'), IconTypes.superscript, 'subsup'), IconTypes.subscript, 'subsup');
167
- var buildMenuIconState = function buildMenuIconState(iconMark) {
168
+ var buildMenuIconState = function buildMenuIconState(iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks) {
168
169
  return function (_ref2) {
169
170
  var schema = _ref2.schema,
170
171
  textFormattingState = _ref2.textFormattingState;
@@ -179,7 +180,7 @@ var buildMenuIconState = function buildMenuIconState(iconMark) {
179
180
  hasSchemaMark: hasSchemaMark
180
181
  };
181
182
  }
182
- var isActive = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Active")];
183
+ var isActive = hasMultiplePartsWithFormattingSelected && !(commonActiveMarks !== null && commonActiveMarks !== void 0 && commonActiveMarks.includes(iconMark)) && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_10') ? false : textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Active")];
183
184
  var isDisabled = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Disabled")];
184
185
  var isHidden = textFormattingState === null || textFormattingState === void 0 ? void 0 : textFormattingState["".concat(iconMark, "Hidden")];
185
186
  return {
@@ -190,8 +191,8 @@ var buildMenuIconState = function buildMenuIconState(iconMark) {
190
191
  };
191
192
  };
192
193
  };
193
- var buildIcon = function buildIcon(iconMark, editorAnalyticsAPI, toolbarType) {
194
- var getState = buildMenuIconState(iconMark);
194
+ var buildIcon = function buildIcon(iconMark, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks) {
195
+ var getState = buildMenuIconState(iconMark, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
195
196
  return function (_ref3) {
196
197
  var schema = _ref3.schema,
197
198
  textFormattingState = _ref3.textFormattingState,
@@ -227,21 +228,25 @@ export var useFormattingIcons = function useFormattingIcons(_ref4) {
227
228
  schema = _ref4.schema,
228
229
  intl = _ref4.intl,
229
230
  editorAnalyticsAPI = _ref4.editorAnalyticsAPI,
230
- toolbarType = _ref4.toolbarType;
231
+ toolbarType = _ref4.toolbarType,
232
+ hasMultiplePartsWithFormattingSelected = _ref4.hasMultiplePartsWithFormattingSelected,
233
+ commonActiveMarks = _ref4.commonActiveMarks;
231
234
  var props = {
232
235
  schema: schema,
233
236
  textFormattingState: textFormattingState,
234
237
  intl: intl,
235
238
  isToolbarDisabled: Boolean(isToolbarDisabled),
236
- toolbarType: toolbarType
239
+ toolbarType: toolbarType,
240
+ hasMultiplePartsWithFormattingSelected: hasMultiplePartsWithFormattingSelected,
241
+ commonActiveMarks: commonActiveMarks
237
242
  };
238
- var buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI, toolbarType);
239
- var buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI, toolbarType);
240
- var buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI, toolbarType);
241
- var buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI, toolbarType);
242
- var buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI, toolbarType);
243
- var buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI, toolbarType);
244
- var buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI, toolbarType);
243
+ var buildStrongIcon = buildIcon(IconTypes.strong, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
244
+ var buildEmIcon = buildIcon(IconTypes.em, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
245
+ var buildUnderlineIcon = buildIcon(IconTypes.underline, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
246
+ var buildStrikeIcon = buildIcon(IconTypes.strike, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
247
+ var buildCodeIcon = buildIcon(IconTypes.code, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
248
+ var buildSubscriptIcon = buildIcon(IconTypes.subscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
249
+ var buildSuperscriptIcon = buildIcon(IconTypes.superscript, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks);
245
250
  var strongIcon = buildStrongIcon(props);
246
251
  var emIcon = buildEmIcon(props);
247
252
  var underlineIcon = buildUnderlineIcon(props);
@@ -11,7 +11,9 @@ export var useIconList = function useIconList(_ref) {
11
11
  if (!icon || !icon.iconMark) {
12
12
  return acc;
13
13
  }
14
- if (shouldUnselect && icon.isActive && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7')) {
14
+ if (
15
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
16
+ shouldUnselect && icon.isActive && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10')) {
15
17
  icon.isActive = false;
16
18
  }
17
19
  var isIconSingleButton = iconTypeList.includes(icon.iconMark);
@@ -14,7 +14,7 @@ export var SingleToolbarButtons = /*#__PURE__*/React.memo(function (_ref) {
14
14
  var items = _ref.items,
15
15
  isReducedSpacing = _ref.isReducedSpacing,
16
16
  editorView = _ref.editorView,
17
- shouldUnselect = _ref.shouldUnselect;
17
+ hasMultiplePartsWithFormattingSelected = _ref.hasMultiplePartsWithFormattingSelected;
18
18
  var onClick = useCallback(function (command) {
19
19
  return function () {
20
20
  command(editorView.state, editorView.dispatch);
@@ -39,11 +39,15 @@ export var SingleToolbarButtons = /*#__PURE__*/React.memo(function (_ref) {
39
39
  buttonId: item.buttonId,
40
40
  spacing: isReducedSpacing ? 'none' : 'default',
41
41
  onClick: onClick(item.command),
42
- selected: shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') ? false : item.isActive,
42
+ selected:
43
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
44
+ hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10') ? false : item.isActive,
43
45
  disabled: item.isDisabled,
44
46
  title: item.tooltipElement,
45
47
  iconBefore: item.iconElement,
46
- "aria-pressed": shouldUnselect && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') ? false : item.isActive,
48
+ "aria-pressed":
49
+ // eslint-disable-next-line @atlaskit/platform/no-preconditioning
50
+ hasMultiplePartsWithFormattingSelected && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_7') && !fg('platform_editor_controls_patch_10') ? false : item.isActive,
47
51
  "aria-label": (_item$ariaLabel = item['aria-label']) !== null && _item$ariaLabel !== void 0 ? _item$ariaLabel : String(item.content),
48
52
  "aria-keyshortcuts": item['aria-keyshortcuts']
49
53
  });
@@ -15,7 +15,7 @@ type DropdownMenuProps = {
15
15
  popupsScrollableElement?: HTMLElement;
16
16
  hasMoreButton: boolean;
17
17
  toolbarType: ToolbarType;
18
- shouldUnselect?: boolean;
18
+ hasMultiplePartsWithFormattingSelected?: boolean;
19
19
  } & WrappedComponentProps;
20
- export declare const FormattingTextDropdownMenu: React.MemoExoticComponent<({ editorView, moreButtonLabel, isReducedSpacing, items, hasFormattingActive, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, hasMoreButton, intl, toolbarType, shouldUnselect, }: DropdownMenuProps) => React.JSX.Element>;
20
+ export declare const FormattingTextDropdownMenu: React.MemoExoticComponent<({ editorView, moreButtonLabel, isReducedSpacing, items, hasFormattingActive, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, hasMoreButton, intl, toolbarType, hasMultiplePartsWithFormattingSelected, }: DropdownMenuProps) => React.JSX.Element>;
21
21
  export {};
@@ -2,3 +2,6 @@ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  export declare const hasMultiplePartsWithFormattingInSelection: ({ selectedContent, }: {
3
3
  selectedContent?: PMNode[] | undefined;
4
4
  }) => boolean;
5
+ export declare const getCommonActiveMarks: ({ selectedContent }: {
6
+ selectedContent?: PMNode[] | undefined;
7
+ }) => string[];
@@ -8,8 +8,10 @@ interface FormattingIconHookProps extends IconHookProps {
8
8
  textFormattingState: TextFormattingState | undefined;
9
9
  schema: Schema;
10
10
  toolbarType: ToolbarType;
11
+ hasMultiplePartsWithFormattingSelected?: boolean;
12
+ commonActiveMarks?: string[];
11
13
  }
12
- export declare const useFormattingIcons: ({ isToolbarDisabled, textFormattingState, schema, intl, editorAnalyticsAPI, toolbarType, }: FormattingIconHookProps) => Array<MenuIconItem | null>;
14
+ export declare const useFormattingIcons: ({ isToolbarDisabled, textFormattingState, schema, intl, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks, }: FormattingIconHookProps) => Array<MenuIconItem | null>;
13
15
  type Props = {
14
16
  textFormattingState: TextFormattingState | undefined;
15
17
  iconTypeList: IconTypes[];
@@ -6,9 +6,9 @@ import React from 'react';
6
6
  import { jsx } from '@emotion/react';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import type { MenuIconItem } from './types';
9
- export declare const SingleToolbarButtons: React.MemoExoticComponent<({ items, isReducedSpacing, editorView, shouldUnselect, }: {
9
+ export declare const SingleToolbarButtons: React.MemoExoticComponent<({ items, isReducedSpacing, editorView, hasMultiplePartsWithFormattingSelected, }: {
10
10
  items: MenuIconItem[];
11
11
  isReducedSpacing: boolean;
12
12
  editorView: EditorView;
13
- shouldUnselect?: boolean | undefined;
13
+ hasMultiplePartsWithFormattingSelected?: boolean | undefined;
14
14
  }) => jsx.JSX.Element>;
@@ -15,7 +15,7 @@ type DropdownMenuProps = {
15
15
  popupsScrollableElement?: HTMLElement;
16
16
  hasMoreButton: boolean;
17
17
  toolbarType: ToolbarType;
18
- shouldUnselect?: boolean;
18
+ hasMultiplePartsWithFormattingSelected?: boolean;
19
19
  } & WrappedComponentProps;
20
- export declare const FormattingTextDropdownMenu: React.MemoExoticComponent<({ editorView, moreButtonLabel, isReducedSpacing, items, hasFormattingActive, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, hasMoreButton, intl, toolbarType, shouldUnselect, }: DropdownMenuProps) => React.JSX.Element>;
20
+ export declare const FormattingTextDropdownMenu: React.MemoExoticComponent<({ editorView, moreButtonLabel, isReducedSpacing, items, hasFormattingActive, popupsBoundariesElement, popupsMountPoint, popupsScrollableElement, hasMoreButton, intl, toolbarType, hasMultiplePartsWithFormattingSelected, }: DropdownMenuProps) => React.JSX.Element>;
21
21
  export {};
@@ -2,3 +2,6 @@ import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
2
2
  export declare const hasMultiplePartsWithFormattingInSelection: ({ selectedContent, }: {
3
3
  selectedContent?: PMNode[] | undefined;
4
4
  }) => boolean;
5
+ export declare const getCommonActiveMarks: ({ selectedContent }: {
6
+ selectedContent?: PMNode[] | undefined;
7
+ }) => string[];
@@ -8,8 +8,10 @@ interface FormattingIconHookProps extends IconHookProps {
8
8
  textFormattingState: TextFormattingState | undefined;
9
9
  schema: Schema;
10
10
  toolbarType: ToolbarType;
11
+ hasMultiplePartsWithFormattingSelected?: boolean;
12
+ commonActiveMarks?: string[];
11
13
  }
12
- export declare const useFormattingIcons: ({ isToolbarDisabled, textFormattingState, schema, intl, editorAnalyticsAPI, toolbarType, }: FormattingIconHookProps) => Array<MenuIconItem | null>;
14
+ export declare const useFormattingIcons: ({ isToolbarDisabled, textFormattingState, schema, intl, editorAnalyticsAPI, toolbarType, hasMultiplePartsWithFormattingSelected, commonActiveMarks, }: FormattingIconHookProps) => Array<MenuIconItem | null>;
13
15
  type Props = {
14
16
  textFormattingState: TextFormattingState | undefined;
15
17
  iconTypeList: IconTypes[];
@@ -6,9 +6,9 @@ import React from 'react';
6
6
  import { jsx } from '@emotion/react';
7
7
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
8
8
  import type { MenuIconItem } from './types';
9
- export declare const SingleToolbarButtons: React.MemoExoticComponent<({ items, isReducedSpacing, editorView, shouldUnselect, }: {
9
+ export declare const SingleToolbarButtons: React.MemoExoticComponent<({ items, isReducedSpacing, editorView, hasMultiplePartsWithFormattingSelected, }: {
10
10
  items: MenuIconItem[];
11
11
  isReducedSpacing: boolean;
12
12
  editorView: EditorView;
13
- shouldUnselect?: boolean | undefined;
13
+ hasMultiplePartsWithFormattingSelected?: boolean | undefined;
14
14
  }) => jsx.JSX.Element>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-text-formatting",
3
- "version": "2.2.7",
3
+ "version": "2.2.8",
4
4
  "description": "Text-formatting plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^47.6.0",
37
- "@atlaskit/editor-common": "^105.3.0",
37
+ "@atlaskit/editor-common": "^105.8.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^2.3.0",
39
39
  "@atlaskit/editor-plugin-base": "^3.0.0",
40
40
  "@atlaskit/editor-plugin-primary-toolbar": "^3.2.0",
@@ -42,11 +42,11 @@
42
42
  "@atlaskit/editor-prosemirror": "7.0.0",
43
43
  "@atlaskit/editor-shared-styles": "^3.4.0",
44
44
  "@atlaskit/editor-tables": "^2.9.0",
45
- "@atlaskit/icon": "^26.0.0",
45
+ "@atlaskit/icon": "^26.1.0",
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
47
  "@atlaskit/prosemirror-input-rules": "^3.3.0",
48
- "@atlaskit/tmp-editor-statsig": "^4.22.0",
49
- "@atlaskit/tokens": "^4.8.0",
48
+ "@atlaskit/tmp-editor-statsig": "^4.24.0",
49
+ "@atlaskit/tokens": "^4.9.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1",
52
52
  "react-intl-next": "npm:react-intl@^5.18.1"
@@ -113,6 +113,9 @@
113
113
  "platform_editor_controls_patch_9": {
114
114
  "type": "boolean"
115
115
  },
116
+ "platform_editor_controls_patch_10": {
117
+ "type": "boolean"
118
+ },
116
119
  "editor_inline_comments_on_inline_nodes": {
117
120
  "type": "boolean"
118
121
  },