@atlaskit/editor-plugin-text-formatting 2.3.3 → 2.4.0

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,17 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 2.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#173138](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/173138)
8
+ [`62d4e3ae11127`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/62d4e3ae11127) -
9
+ [ux] [ED-27997] Change text formatting state to only consider whole selections active for marks
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 2.3.3
4
16
 
5
17
  ### Patch Changes
@@ -1,28 +1,32 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.plugin = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
8
10
  var _keymaps = require("@atlaskit/editor-common/keymaps");
9
11
  var _mark = require("@atlaskit/editor-common/mark");
10
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
13
  var _utils = require("@atlaskit/editor-common/utils");
12
14
  var _commands = require("@atlaskit/editor-prosemirror/commands");
15
+ var _model = require("@atlaskit/editor-prosemirror/model");
13
16
  var _state = require("@atlaskit/editor-prosemirror/state");
14
17
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
18
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
15
19
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
16
20
  var _textFormatting = _interopRequireWildcard(require("../editor-commands/text-formatting"));
17
21
  var commands = _textFormatting;
18
22
  var _pluginKey = require("./plugin-key");
19
23
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
20
- // TODO: ED-26962 - Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
24
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
25
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
26
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } // TODO: ED-26962 - Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
21
27
  // import { toggleMark } from '@atlaskit/editor-common/mark';
22
-
23
28
  // Ignored via go/ees005
24
29
  // eslint-disable-next-line import/no-namespace
25
-
26
30
  var isSelectionInlineCursor = function isSelectionInlineCursor(selection) {
27
31
  if (selection instanceof _state.NodeSelection) {
28
32
  return true;
@@ -34,12 +38,9 @@ var checkNodeSelection = function checkNodeSelection(mark, editorState, type) {
34
38
  if (isSelectionInlineCursor(selection)) {
35
39
  return false;
36
40
  }
37
- if (type !== null || type !== undefined) {
38
- return (0, _commands.toggleMark)(mark, {
39
- type: type
40
- })(editorState);
41
- }
42
- return (0, _commands.toggleMark)(mark)(editorState);
41
+ return (0, _commands.toggleMark)(mark, {
42
+ type: type
43
+ })(editorState);
43
44
  };
44
45
  var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
45
46
  var _editorState$schema$m = editorState.schema.marks,
@@ -52,6 +53,49 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
52
53
  var state = {
53
54
  isInitialised: true
54
55
  };
56
+ var showOnlyCommonMarks = (0, _expValEquals.expValEquals)('platform_editor_controls', 'cohort', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_common_marks');
57
+ if (showOnlyCommonMarks) {
58
+ // Code marks will disable all other formatting options when they are included in a
59
+ // selection but (for now) we do not want to make it behave differently in regards to which
60
+ // toolbar items are highlighted on selection. We need to track code in selection seperately
61
+ // to ensure all other formatting options are disabled appropriately.
62
+ if (code) {
63
+ state.codeInSelection = (0, _mark.anyMarkActive)(editorState, code.create());
64
+ }
65
+ var marks = [[code, 'code'], [em, 'em'], [strike, 'strike'], [strong, 'strong'], [underline, 'underline'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
66
+ type: 'sub'
67
+ }), 'subscript'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
68
+ type: 'sup'
69
+ }), 'superscript']].filter(function (_ref) {
70
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 1),
71
+ mark = _ref2[0];
72
+ return mark;
73
+ });
74
+ var marksToName = new Map(marks);
75
+ var activeMarks = (0, _mark.wholeSelectionHasMarks)(editorState, Array.from(marksToName.keys()));
76
+ var _iterator = _createForOfIteratorHelper(marks),
77
+ _step;
78
+ try {
79
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
80
+ var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
81
+ mark = _step$value[0],
82
+ markName = _step$value[1];
83
+ var active = activeMarks.get(mark);
84
+ if (active !== undefined) {
85
+ state["".concat(markName, "Active")] = active;
86
+ }
87
+ state["".concat(markName, "Disabled")] =
88
+ // Disable when code is active, except for code itself which should not be disabled
89
+ // when code is in selection 😅
90
+ state.codeInSelection && markName !== 'code' ? true : !checkNodeSelection(mark instanceof _model.MarkType ? mark : mark.type, editorState);
91
+ }
92
+ } catch (err) {
93
+ _iterator.e(err);
94
+ } finally {
95
+ _iterator.f();
96
+ }
97
+ return state;
98
+ }
55
99
  if (code) {
56
100
  state.codeActive = (0, _mark.anyMarkActive)(editorState, code.create());
57
101
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -76,8 +120,8 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
76
120
  type: 'sup'
77
121
  });
78
122
  state.subscriptActive = (0, _mark.anyMarkActive)(editorState, subMark);
79
- state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
80
123
  state.superscriptActive = (0, _mark.anyMarkActive)(editorState, supMark);
124
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
81
125
  state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
82
126
  }
83
127
  if (underline) {
@@ -127,16 +127,16 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
127
127
  var formattingIsPresent = textFormattingState.formattingIsPresent,
128
128
  formattingIconState = (0, _objectWithoutProperties2.default)(textFormattingState, _excluded);
129
129
  var hasMultiplePartsWithFormattingSelected;
130
- var commonActiveMarks = [];
130
+ var commonActiveMarks;
131
131
  if ((0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
132
132
  var selection = editorView.state.selection;
133
133
  var from = selection.from,
134
134
  to = selection.to;
135
135
  var selectedContent = selection instanceof _state.TextSelection ? editorView.state.doc.slice(from, to).content.content.slice() : undefined;
136
- hasMultiplePartsWithFormattingSelected = (0, _formattingInSelectionUtils.hasMultiplePartsWithFormattingInSelection)({
136
+ hasMultiplePartsWithFormattingSelected = (0, _platformFeatureFlags.fg)('platform_editor_common_marks') ? false : (0, _formattingInSelectionUtils.hasMultiplePartsWithFormattingInSelection)({
137
137
  selectedContent: selectedContent
138
138
  });
139
- if ((0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10')) {
139
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_common_marks')) {
140
140
  commonActiveMarks = (0, _formattingInSelectionUtils.getCommonActiveMarks)({
141
141
  selectedContent: selectedContent
142
142
  });
@@ -149,8 +149,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
149
149
  editorAnalyticsAPI: editorAnalyticsAPI,
150
150
  textFormattingState: formattingIconState,
151
151
  toolbarType: FloatingToolbarSettings.toolbarType,
152
- hasMultiplePartsWithFormattingSelected: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? hasMultiplePartsWithFormattingSelected : undefined,
153
- commonActiveMarks: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_10') ? commonActiveMarks : undefined
152
+ hasMultiplePartsWithFormattingSelected: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? hasMultiplePartsWithFormattingSelected : undefined,
153
+ commonActiveMarks: (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') ? commonActiveMarks : undefined
154
154
  });
155
155
  var _useIconList = (0, _useIconList2.useIconList)({
156
156
  icons: defaultIcons,
@@ -24,6 +24,8 @@ var hasMultiplePartsWithFormattingInSelection = exports.hasMultiplePartsWithForm
24
24
  var allPartsHaveFormatting = contentWithMarks.length === selectedContent.length;
25
25
  return hasFormatting && (!allPartsHaveFormatting || contentWithMarks.length > 1);
26
26
  };
27
+
28
+ // Clean up when platform_editor_common_marks is removed
27
29
  var getCommonActiveMarks = exports.getCommonActiveMarks = function getCommonActiveMarks(_ref2) {
28
30
  var selectedContent = _ref2.selectedContent;
29
31
  if (!selectedContent || selectedContent.length === 0) {
@@ -34,12 +36,10 @@ var getCommonActiveMarks = exports.getCommonActiveMarks = function getCommonActi
34
36
  var _child$text;
35
37
  return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
36
38
  });
37
-
38
39
  // find the active mark type in first part
39
40
  var firstPartMarks = selectedContent[0].marks.map(function (mark) {
40
41
  return mark.type.name;
41
42
  });
42
-
43
43
  // check if all other parts have the same mark type as the first part and return the common mark types
44
44
  var commonMarkTypes = firstPartMarks.filter(function (mark) {
45
45
  return filteredSelectedContent.every(function (child) {
@@ -2,12 +2,14 @@
2
2
  // import { toggleMark } from '@atlaskit/editor-common/mark';
3
3
 
4
4
  import { moveLeft as keymapMoveLeft, moveRight as keymapMoveRight } from '@atlaskit/editor-common/keymaps';
5
- import { anyMarkActive } from '@atlaskit/editor-common/mark';
5
+ import { anyMarkActive, wholeSelectionHasMarks } from '@atlaskit/editor-common/mark';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { shallowEqual } from '@atlaskit/editor-common/utils';
8
8
  import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
9
+ import { MarkType } from '@atlaskit/editor-prosemirror/model';
9
10
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
10
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
13
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
14
  import { createInlineCodeFromTextInputWithAnalytics } from '../editor-commands/text-formatting';
13
15
  // Ignored via go/ees005
@@ -25,12 +27,9 @@ const checkNodeSelection = (mark, editorState, type) => {
25
27
  if (isSelectionInlineCursor(selection)) {
26
28
  return false;
27
29
  }
28
- if (type !== null || type !== undefined) {
29
- return toggleMark(mark, {
30
- type: type
31
- })(editorState);
32
- }
33
- return toggleMark(mark)(editorState);
30
+ return toggleMark(mark, {
31
+ type: type
32
+ })(editorState);
34
33
  };
35
34
  const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
36
35
  const {
@@ -44,6 +43,34 @@ const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
44
43
  const state = {
45
44
  isInitialised: true
46
45
  };
46
+ const showOnlyCommonMarks = expValEquals('platform_editor_controls', 'cohort', 'variant1') && fg('platform_editor_common_marks');
47
+ if (showOnlyCommonMarks) {
48
+ // Code marks will disable all other formatting options when they are included in a
49
+ // selection but (for now) we do not want to make it behave differently in regards to which
50
+ // toolbar items are highlighted on selection. We need to track code in selection seperately
51
+ // to ensure all other formatting options are disabled appropriately.
52
+ if (code) {
53
+ state.codeInSelection = anyMarkActive(editorState, code.create());
54
+ }
55
+ const marks = [[code, 'code'], [em, 'em'], [strike, 'strike'], [strong, 'strong'], [underline, 'underline'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
56
+ type: 'sub'
57
+ }), 'subscript'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
58
+ type: 'sup'
59
+ }), 'superscript']].filter(([mark]) => mark);
60
+ const marksToName = new Map(marks);
61
+ const activeMarks = wholeSelectionHasMarks(editorState, Array.from(marksToName.keys()));
62
+ for (const [mark, markName] of marks) {
63
+ const active = activeMarks.get(mark);
64
+ if (active !== undefined) {
65
+ state[`${markName}Active`] = active;
66
+ }
67
+ state[`${markName}Disabled`] =
68
+ // Disable when code is active, except for code itself which should not be disabled
69
+ // when code is in selection 😅
70
+ state.codeInSelection && markName !== 'code' ? true : !checkNodeSelection(mark instanceof MarkType ? mark : mark.type, editorState);
71
+ }
72
+ return state;
73
+ }
47
74
  if (code) {
48
75
  state.codeActive = anyMarkActive(editorState, code.create());
49
76
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -68,8 +95,8 @@ const getTextFormattingState = (editorState, editorAnalyticsAPI) => {
68
95
  type: 'sup'
69
96
  });
70
97
  state.subscriptActive = anyMarkActive(editorState, subMark);
71
- state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
72
98
  state.superscriptActive = anyMarkActive(editorState, supMark);
99
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
73
100
  state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
74
101
  }
75
102
  if (underline) {
@@ -121,7 +121,7 @@ const FloatingToolbarTextFormat = ({
121
121
  ...formattingIconState
122
122
  } = textFormattingState;
123
123
  let hasMultiplePartsWithFormattingSelected;
124
- let commonActiveMarks = [];
124
+ let commonActiveMarks;
125
125
  if (editorExperiment('platform_editor_controls', 'variant1')) {
126
126
  const {
127
127
  selection
@@ -131,10 +131,10 @@ const FloatingToolbarTextFormat = ({
131
131
  to
132
132
  } = selection;
133
133
  const selectedContent = selection instanceof TextSelection ? editorView.state.doc.slice(from, to).content.content.slice() : undefined;
134
- hasMultiplePartsWithFormattingSelected = hasMultiplePartsWithFormattingInSelection({
134
+ hasMultiplePartsWithFormattingSelected = fg('platform_editor_common_marks') ? false : hasMultiplePartsWithFormattingInSelection({
135
135
  selectedContent
136
136
  });
137
- if (fg('platform_editor_controls_patch_10')) {
137
+ if (!fg('platform_editor_common_marks')) {
138
138
  commonActiveMarks = getCommonActiveMarks({
139
139
  selectedContent
140
140
  });
@@ -147,8 +147,8 @@ const FloatingToolbarTextFormat = ({
147
147
  editorAnalyticsAPI,
148
148
  textFormattingState: formattingIconState,
149
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
150
+ hasMultiplePartsWithFormattingSelected: editorExperiment('platform_editor_controls', 'variant1') ? hasMultiplePartsWithFormattingSelected : undefined,
151
+ commonActiveMarks: editorExperiment('platform_editor_controls', 'variant1') ? commonActiveMarks : undefined
152
152
  });
153
153
  const {
154
154
  dropdownItems,
@@ -13,6 +13,8 @@ export const hasMultiplePartsWithFormattingInSelection = ({
13
13
  const allPartsHaveFormatting = contentWithMarks.length === selectedContent.length;
14
14
  return hasFormatting && (!allPartsHaveFormatting || contentWithMarks.length > 1);
15
15
  };
16
+
17
+ // Clean up when platform_editor_common_marks is removed
16
18
  export const getCommonActiveMarks = ({
17
19
  selectedContent
18
20
  }) => {
@@ -24,10 +26,8 @@ export const getCommonActiveMarks = ({
24
26
  var _child$text;
25
27
  return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
26
28
  });
27
-
28
29
  // find the active mark type in first part
29
30
  const firstPartMarks = selectedContent[0].marks.map(mark => mark.type.name);
30
-
31
31
  // check if all other parts have the same mark type as the first part and return the common mark types
32
32
  const commonMarkTypes = firstPartMarks.filter(mark => filteredSelectedContent.every(child => child.marks.some(m => m.type.name === mark)));
33
33
  return commonMarkTypes;
@@ -1,13 +1,19 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1
5
  // TODO: ED-26962 - Ideally this should use the custom toggleMark function from @atlaskit/editor-common so we also disable the options when selecting inline nodes but it disables the marks when the selection is empty at this point in time which is undesirable
2
6
  // import { toggleMark } from '@atlaskit/editor-common/mark';
3
7
 
4
8
  import { moveLeft as keymapMoveLeft, moveRight as keymapMoveRight } from '@atlaskit/editor-common/keymaps';
5
- import { anyMarkActive } from '@atlaskit/editor-common/mark';
9
+ import { anyMarkActive, wholeSelectionHasMarks } from '@atlaskit/editor-common/mark';
6
10
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
11
  import { shallowEqual } from '@atlaskit/editor-common/utils';
8
12
  import { toggleMark } from '@atlaskit/editor-prosemirror/commands';
13
+ import { MarkType } from '@atlaskit/editor-prosemirror/model';
9
14
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
10
15
  import { fg } from '@atlaskit/platform-feature-flags';
16
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
17
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
12
18
  import { createInlineCodeFromTextInputWithAnalytics } from '../editor-commands/text-formatting';
13
19
  // Ignored via go/ees005
@@ -25,12 +31,9 @@ var checkNodeSelection = function checkNodeSelection(mark, editorState, type) {
25
31
  if (isSelectionInlineCursor(selection)) {
26
32
  return false;
27
33
  }
28
- if (type !== null || type !== undefined) {
29
- return toggleMark(mark, {
30
- type: type
31
- })(editorState);
32
- }
33
- return toggleMark(mark)(editorState);
34
+ return toggleMark(mark, {
35
+ type: type
36
+ })(editorState);
34
37
  };
35
38
  var getTextFormattingState = function getTextFormattingState(editorState, editorAnalyticsAPI) {
36
39
  var _editorState$schema$m = editorState.schema.marks,
@@ -43,6 +46,49 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
43
46
  var state = {
44
47
  isInitialised: true
45
48
  };
49
+ var showOnlyCommonMarks = expValEquals('platform_editor_controls', 'cohort', 'variant1') && fg('platform_editor_common_marks');
50
+ if (showOnlyCommonMarks) {
51
+ // Code marks will disable all other formatting options when they are included in a
52
+ // selection but (for now) we do not want to make it behave differently in regards to which
53
+ // toolbar items are highlighted on selection. We need to track code in selection seperately
54
+ // to ensure all other formatting options are disabled appropriately.
55
+ if (code) {
56
+ state.codeInSelection = anyMarkActive(editorState, code.create());
57
+ }
58
+ var marks = [[code, 'code'], [em, 'em'], [strike, 'strike'], [strong, 'strong'], [underline, 'underline'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
59
+ type: 'sub'
60
+ }), 'subscript'], [subsup === null || subsup === void 0 ? void 0 : subsup.create({
61
+ type: 'sup'
62
+ }), 'superscript']].filter(function (_ref) {
63
+ var _ref2 = _slicedToArray(_ref, 1),
64
+ mark = _ref2[0];
65
+ return mark;
66
+ });
67
+ var marksToName = new Map(marks);
68
+ var activeMarks = wholeSelectionHasMarks(editorState, Array.from(marksToName.keys()));
69
+ var _iterator = _createForOfIteratorHelper(marks),
70
+ _step;
71
+ try {
72
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
73
+ var _step$value = _slicedToArray(_step.value, 2),
74
+ mark = _step$value[0],
75
+ markName = _step$value[1];
76
+ var active = activeMarks.get(mark);
77
+ if (active !== undefined) {
78
+ state["".concat(markName, "Active")] = active;
79
+ }
80
+ state["".concat(markName, "Disabled")] =
81
+ // Disable when code is active, except for code itself which should not be disabled
82
+ // when code is in selection 😅
83
+ state.codeInSelection && markName !== 'code' ? true : !checkNodeSelection(mark instanceof MarkType ? mark : mark.type, editorState);
84
+ }
85
+ } catch (err) {
86
+ _iterator.e(err);
87
+ } finally {
88
+ _iterator.f();
89
+ }
90
+ return state;
91
+ }
46
92
  if (code) {
47
93
  state.codeActive = anyMarkActive(editorState, code.create());
48
94
  state.codeDisabled = !checkNodeSelection(code, editorState);
@@ -67,8 +113,8 @@ var getTextFormattingState = function getTextFormattingState(editorState, editor
67
113
  type: 'sup'
68
114
  });
69
115
  state.subscriptActive = anyMarkActive(editorState, subMark);
70
- state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
71
116
  state.superscriptActive = anyMarkActive(editorState, supMark);
117
+ state.subscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sub');
72
118
  state.superscriptDisabled = state.codeActive ? true : !checkNodeSelection(subsup, editorState, 'sup');
73
119
  }
74
120
  if (underline) {
@@ -119,16 +119,16 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
119
119
  var formattingIsPresent = textFormattingState.formattingIsPresent,
120
120
  formattingIconState = _objectWithoutProperties(textFormattingState, _excluded);
121
121
  var hasMultiplePartsWithFormattingSelected;
122
- var commonActiveMarks = [];
122
+ var commonActiveMarks;
123
123
  if (editorExperiment('platform_editor_controls', 'variant1')) {
124
124
  var selection = editorView.state.selection;
125
125
  var from = selection.from,
126
126
  to = selection.to;
127
127
  var selectedContent = selection instanceof TextSelection ? editorView.state.doc.slice(from, to).content.content.slice() : undefined;
128
- hasMultiplePartsWithFormattingSelected = hasMultiplePartsWithFormattingInSelection({
128
+ hasMultiplePartsWithFormattingSelected = fg('platform_editor_common_marks') ? false : hasMultiplePartsWithFormattingInSelection({
129
129
  selectedContent: selectedContent
130
130
  });
131
- if (fg('platform_editor_controls_patch_10')) {
131
+ if (!fg('platform_editor_common_marks')) {
132
132
  commonActiveMarks = getCommonActiveMarks({
133
133
  selectedContent: selectedContent
134
134
  });
@@ -141,8 +141,8 @@ var FloatingToolbarTextFormat = function FloatingToolbarTextFormat(_ref) {
141
141
  editorAnalyticsAPI: editorAnalyticsAPI,
142
142
  textFormattingState: formattingIconState,
143
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
144
+ hasMultiplePartsWithFormattingSelected: editorExperiment('platform_editor_controls', 'variant1') ? hasMultiplePartsWithFormattingSelected : undefined,
145
+ commonActiveMarks: editorExperiment('platform_editor_controls', 'variant1') ? commonActiveMarks : undefined
146
146
  });
147
147
  var _useIconList = useIconList({
148
148
  icons: defaultIcons,
@@ -18,6 +18,8 @@ export var hasMultiplePartsWithFormattingInSelection = function hasMultipleParts
18
18
  var allPartsHaveFormatting = contentWithMarks.length === selectedContent.length;
19
19
  return hasFormatting && (!allPartsHaveFormatting || contentWithMarks.length > 1);
20
20
  };
21
+
22
+ // Clean up when platform_editor_common_marks is removed
21
23
  export var getCommonActiveMarks = function getCommonActiveMarks(_ref2) {
22
24
  var selectedContent = _ref2.selectedContent;
23
25
  if (!selectedContent || selectedContent.length === 0) {
@@ -28,12 +30,10 @@ export var getCommonActiveMarks = function getCommonActiveMarks(_ref2) {
28
30
  var _child$text;
29
31
  return ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) !== '';
30
32
  });
31
-
32
33
  // find the active mark type in first part
33
34
  var firstPartMarks = selectedContent[0].marks.map(function (mark) {
34
35
  return mark.type.name;
35
36
  });
36
-
37
37
  // check if all other parts have the same mark type as the first part and return the common mark types
38
38
  var commonMarkTypes = firstPartMarks.filter(function (mark) {
39
39
  return filteredSelectedContent.every(function (child) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-text-formatting",
3
- "version": "2.3.3",
3
+ "version": "2.4.0",
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": "^107.0.0",
37
+ "@atlaskit/editor-common": "^107.1.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",
@@ -46,7 +46,7 @@
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
47
  "@atlaskit/prosemirror-input-rules": "^3.3.0",
48
48
  "@atlaskit/tmp-editor-statsig": "^8.0.0",
49
- "@atlaskit/tokens": "^5.3.0",
49
+ "@atlaskit/tokens": "^5.4.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"
@@ -124,6 +124,9 @@
124
124
  },
125
125
  "platform_editor_use_preferences_plugin": {
126
126
  "type": "boolean"
127
+ },
128
+ "platform_editor_common_marks": {
129
+ "type": "boolean"
127
130
  }
128
131
  }
129
132
  }