@atlaskit/editor-plugin-text-formatting 3.0.6 → 3.0.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 (53) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/editor-commands/clear-formatting.js +94 -1
  3. package/dist/cjs/{pm-plugins/commands.js → editor-commands/toggle-mark.js} +1 -1
  4. package/dist/cjs/editor-commands/types.js +5 -0
  5. package/dist/cjs/pm-plugins/clear-formatting-keymap.js +2 -2
  6. package/dist/cjs/pm-plugins/keymap.js +15 -15
  7. package/dist/cjs/textFormattingPlugin.js +24 -15
  8. package/dist/cjs/ui/Toolbar/components/Component.js +144 -0
  9. package/dist/cjs/ui/Toolbar/components/utils.js +127 -0
  10. package/dist/cjs/ui/Toolbar/hooks/formatting-icons.js +8 -8
  11. package/dist/cjs/ui/Toolbar/types.js +11 -1
  12. package/dist/cjs/ui/toolbar-components.js +130 -0
  13. package/dist/es2019/editor-commands/clear-formatting.js +94 -1
  14. package/dist/es2019/{pm-plugins/commands.js → editor-commands/toggle-mark.js} +1 -1
  15. package/dist/es2019/editor-commands/types.js +1 -0
  16. package/dist/es2019/pm-plugins/clear-formatting-keymap.js +4 -4
  17. package/dist/es2019/pm-plugins/keymap.js +1 -1
  18. package/dist/es2019/textFormattingPlugin.js +17 -8
  19. package/dist/es2019/ui/Toolbar/components/Component.js +145 -0
  20. package/dist/es2019/ui/Toolbar/components/utils.js +121 -0
  21. package/dist/es2019/ui/Toolbar/hooks/formatting-icons.js +1 -1
  22. package/dist/es2019/ui/Toolbar/types.js +10 -0
  23. package/dist/es2019/ui/toolbar-components.js +122 -0
  24. package/dist/esm/editor-commands/clear-formatting.js +93 -1
  25. package/dist/esm/{pm-plugins/commands.js → editor-commands/toggle-mark.js} +1 -1
  26. package/dist/esm/editor-commands/types.js +1 -0
  27. package/dist/esm/pm-plugins/clear-formatting-keymap.js +4 -4
  28. package/dist/esm/pm-plugins/keymap.js +1 -1
  29. package/dist/esm/textFormattingPlugin.js +17 -8
  30. package/dist/esm/ui/Toolbar/components/Component.js +137 -0
  31. package/dist/esm/ui/Toolbar/components/utils.js +120 -0
  32. package/dist/esm/ui/Toolbar/hooks/formatting-icons.js +1 -1
  33. package/dist/esm/ui/Toolbar/types.js +10 -0
  34. package/dist/esm/ui/toolbar-components.js +123 -0
  35. package/dist/types/editor-commands/clear-formatting.d.ts +6 -0
  36. package/dist/{types-ts4.5/pm-plugins/commands.d.ts → types/editor-commands/toggle-mark.d.ts} +2 -5
  37. package/dist/types/editor-commands/types.d.ts +6 -0
  38. package/dist/types/index.d.ts +1 -1
  39. package/dist/types/textFormattingPluginType.d.ts +4 -2
  40. package/dist/types/ui/Toolbar/components/Component.d.ts +11 -0
  41. package/dist/types/ui/Toolbar/components/utils.d.ts +38 -0
  42. package/dist/types/ui/Toolbar/types.d.ts +14 -0
  43. package/dist/types/ui/toolbar-components.d.ts +4 -0
  44. package/dist/types-ts4.5/editor-commands/clear-formatting.d.ts +6 -0
  45. package/dist/{types/pm-plugins/commands.d.ts → types-ts4.5/editor-commands/toggle-mark.d.ts} +2 -5
  46. package/dist/types-ts4.5/editor-commands/types.d.ts +6 -0
  47. package/dist/types-ts4.5/index.d.ts +1 -1
  48. package/dist/types-ts4.5/textFormattingPluginType.d.ts +4 -2
  49. package/dist/types-ts4.5/ui/Toolbar/components/Component.d.ts +11 -0
  50. package/dist/types-ts4.5/ui/Toolbar/components/utils.d.ts +38 -0
  51. package/dist/types-ts4.5/ui/Toolbar/types.d.ts +14 -0
  52. package/dist/types-ts4.5/ui/toolbar-components.d.ts +4 -0
  53. package/package.json +9 -7
@@ -19,7 +19,7 @@ var _textItalicEditorItalic = _interopRequireDefault(require("@atlaskit/icon/cor
19
19
  var _textStrikethrough = _interopRequireDefault(require("@atlaskit/icon/core/text-strikethrough"));
20
20
  var _textUnderline = _interopRequireDefault(require("@atlaskit/icon/core/text-underline"));
21
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
22
- var _commands = require("../../../pm-plugins/commands");
22
+ var _toggleMark = require("../../../editor-commands/toggle-mark");
23
23
  var _icons = require("../icons");
24
24
  var _inputMethodUtils = require("../input-method-utils");
25
25
  var _types = require("../types");
@@ -37,7 +37,7 @@ var IconButtons = function IconButtons(editorAnalyticsAPI, toolbarType) {
37
37
  return {
38
38
  strong: {
39
39
  buttonId: _analytics.TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_STRONG,
40
- command: withInputMethod(toolbarType, (0, _commands.toggleStrongWithAnalytics)(editorAnalyticsAPI)),
40
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleStrongWithAnalytics)(editorAnalyticsAPI)),
41
41
  message: _messages.toolbarMessages.bold,
42
42
  tooltipKeymap: _keymaps.toggleBold,
43
43
  component: function component() {
@@ -50,7 +50,7 @@ var IconButtons = function IconButtons(editorAnalyticsAPI, toolbarType) {
50
50
  },
51
51
  em: {
52
52
  buttonId: _analytics.TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_ITALIC,
53
- command: withInputMethod(toolbarType, (0, _commands.toggleEmWithAnalytics)(editorAnalyticsAPI)),
53
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleEmWithAnalytics)(editorAnalyticsAPI)),
54
54
  message: _messages.toolbarMessages.italic,
55
55
  tooltipKeymap: _keymaps.toggleItalic,
56
56
  component: function component() {
@@ -63,7 +63,7 @@ var IconButtons = function IconButtons(editorAnalyticsAPI, toolbarType) {
63
63
  },
64
64
  underline: {
65
65
  buttonId: _analytics.TOOLBAR_ACTION_SUBJECT_ID.TEXT_FORMATTING_UNDERLINE,
66
- command: withInputMethod(toolbarType, (0, _commands.toggleUnderlineWithAnalytics)(editorAnalyticsAPI)),
66
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleUnderlineWithAnalytics)(editorAnalyticsAPI)),
67
67
  message: _messages.toolbarMessages.underline,
68
68
  tooltipKeymap: _keymaps.toggleUnderline,
69
69
  component: function component() {
@@ -75,22 +75,22 @@ var IconButtons = function IconButtons(editorAnalyticsAPI, toolbarType) {
75
75
  }
76
76
  },
77
77
  strike: {
78
- command: withInputMethod(toolbarType, (0, _commands.toggleStrikeWithAnalytics)(editorAnalyticsAPI)),
78
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleStrikeWithAnalytics)(editorAnalyticsAPI)),
79
79
  message: _messages.toolbarMessages.strike,
80
80
  tooltipKeymap: _keymaps.toggleStrikethrough
81
81
  },
82
82
  code: {
83
- command: withInputMethod(toolbarType, (0, _commands.toggleCodeWithAnalytics)(editorAnalyticsAPI)),
83
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleCodeWithAnalytics)(editorAnalyticsAPI)),
84
84
  message: _messages.toolbarMessages.code,
85
85
  tooltipKeymap: _keymaps.toggleCode
86
86
  },
87
87
  subscript: {
88
- command: withInputMethod(toolbarType, (0, _commands.toggleSubscriptWithAnalytics)(editorAnalyticsAPI)),
88
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleSubscriptWithAnalytics)(editorAnalyticsAPI)),
89
89
  message: _messages.toolbarMessages.subscript,
90
90
  tooltipKeymap: _keymaps.toggleSubscript
91
91
  },
92
92
  superscript: {
93
- command: withInputMethod(toolbarType, (0, _commands.toggleSuperscriptWithAnalytics)(editorAnalyticsAPI)),
93
+ command: withInputMethod(toolbarType, (0, _toggleMark.toggleSuperscriptWithAnalytics)(editorAnalyticsAPI)),
94
94
  message: _messages.toolbarMessages.superscript,
95
95
  tooltipKeymap: _keymaps.toggleSuperscript
96
96
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ToolbarType = exports.IconTypes = void 0;
6
+ exports.ToolbarType = exports.IconTypes = exports.FormatOptions = void 0;
7
7
  var IconTypes = exports.IconTypes = /*#__PURE__*/function (IconTypes) {
8
8
  IconTypes["strong"] = "strong";
9
9
  IconTypes["em"] = "em";
@@ -14,6 +14,16 @@ var IconTypes = exports.IconTypes = /*#__PURE__*/function (IconTypes) {
14
14
  IconTypes["superscript"] = "superscript";
15
15
  return IconTypes;
16
16
  }({});
17
+ var FormatOptions = exports.FormatOptions = /*#__PURE__*/function (FormatOptions) {
18
+ FormatOptions["strong"] = "strong";
19
+ FormatOptions["em"] = "em";
20
+ FormatOptions["underline"] = "underline";
21
+ FormatOptions["strike"] = "strike";
22
+ FormatOptions["code"] = "code";
23
+ FormatOptions["subscript"] = "subscript";
24
+ FormatOptions["superscript"] = "superscript";
25
+ return FormatOptions;
26
+ }({});
17
27
  var ToolbarType = exports.ToolbarType = /*#__PURE__*/function (ToolbarType) {
18
28
  ToolbarType["PRIMARY"] = "primaryToolbar";
19
29
  ToolbarType["FLOATING"] = "floatingToolbar";
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarComponents = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
12
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
13
+ var _Component = require("./Toolbar/components/Component");
14
+ var _utils = require("./Toolbar/components/utils");
15
+ var _types = require("./Toolbar/types");
16
+ var getFormatMenuItems = function getFormatMenuItems(api) {
17
+ return Object.entries(_utils.formatOptions).map(function (_ref) {
18
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
19
+ optionType = _ref2[0],
20
+ _ref2$ = _ref2[1],
21
+ icon = _ref2$.icon,
22
+ shortcut = _ref2$.shortcut,
23
+ title = _ref2$.title,
24
+ command = _ref2$.command,
25
+ rank = _ref2$.rank;
26
+ return {
27
+ type: 'menu-item',
28
+ key: optionType,
29
+ parents: [{
30
+ type: 'menu-section',
31
+ key: 'text-formatting-section',
32
+ rank: rank
33
+ }],
34
+ component: function component(_ref3) {
35
+ var parents = _ref3.parents;
36
+ return /*#__PURE__*/_react.default.createElement(_Component.FormatMenuItem, {
37
+ api: api,
38
+ parents: parents,
39
+ icon: icon,
40
+ shortcut: shortcut,
41
+ title: title,
42
+ optionType: optionType,
43
+ toggleMarkWithAnalyticsCallback: command
44
+ });
45
+ }
46
+ };
47
+ });
48
+ };
49
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
50
+ return [{
51
+ type: 'group',
52
+ key: 'text-formatting',
53
+ parents: [{
54
+ type: 'section',
55
+ key: 'text-section',
56
+ rank: _toolbar.TEXT_SECTION_RANK.FORMAT
57
+ }]
58
+ }, {
59
+ type: 'button',
60
+ key: 'bold',
61
+ parents: [{
62
+ type: 'group',
63
+ key: 'text-formatting',
64
+ rank: _toolbar.TEXT_FORMAT_GROUP_RANK.FORMAT_BUTTON
65
+ }],
66
+ component: function component(_ref4) {
67
+ var parents = _ref4.parents;
68
+ var _formatOptions$strong = _utils.formatOptions.strong,
69
+ icon = _formatOptions$strong.icon,
70
+ command = _formatOptions$strong.command,
71
+ shortcut = _formatOptions$strong.shortcut,
72
+ title = _formatOptions$strong.title;
73
+ return /*#__PURE__*/_react.default.createElement(_Component.FormatButton, {
74
+ api: api,
75
+ parents: parents,
76
+ icon: icon,
77
+ title: title,
78
+ shortcut: shortcut,
79
+ optionType: _types.FormatOptions.strong,
80
+ toggleMarkWithAnalyticsCallback: command
81
+ });
82
+ }
83
+ }, {
84
+ type: 'menu',
85
+ key: 'more-formatting',
86
+ parents: [{
87
+ type: 'group',
88
+ key: 'text-formatting',
89
+ rank: _toolbar.TEXT_FORMAT_GROUP_RANK.MORE_FORMATTING
90
+ }],
91
+ component: function component(_ref5) {
92
+ var children = _ref5.children,
93
+ groupLocation = _ref5.groupLocation;
94
+ return /*#__PURE__*/_react.default.createElement(_Component.MoreFormattingMenu, {
95
+ groupLocation: groupLocation
96
+ }, children);
97
+ }
98
+ }, {
99
+ type: 'menu-section',
100
+ key: 'text-formatting-section',
101
+ parents: [{
102
+ type: 'menu',
103
+ key: 'more-formatting',
104
+ rank: _toolbar.TEXT_FORMAT_MENU_SECTION_RANK.FORMAT_OPTIONS
105
+ }]
106
+ }].concat((0, _toConsumableArray2.default)(getFormatMenuItems(api)), [{
107
+ type: 'menu-section',
108
+ key: 'clear-formatting-section',
109
+ parents: [{
110
+ type: 'menu',
111
+ key: 'more-formatting',
112
+ rank: _toolbar.TEXT_FORMAT_MENU_SECTION_RANK.CLEAR_FORMAT
113
+ }]
114
+ }, {
115
+ type: 'menu-item',
116
+ key: 'clear-formatting',
117
+ parents: [{
118
+ type: 'menu-section',
119
+ key: 'clear-formatting-section',
120
+ rank: _toolbar.TEXT_FORMAT_CLEAR_MENU_RANK.CLEAR_FORMAT
121
+ }],
122
+ component: function component(_ref6) {
123
+ var parents = _ref6.parents;
124
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownDivider, null), /*#__PURE__*/_react.default.createElement(_Component.ClearFormatMenuItem, {
125
+ parents: parents,
126
+ api: api
127
+ }));
128
+ }
129
+ }]);
130
+ };
@@ -14,9 +14,41 @@ const formatTypes = {
14
14
  subsup: 'subsup',
15
15
  backgroundColor: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR
16
16
  };
17
+
18
+ // eslint-disable-next-line @repo/internal/deprecations/deprecation-ticket-required
19
+ /**
20
+ * Consider removing this function when cleaning up platform_editor–toolbar_aifc
21
+ * @deprecated use `clearFormattingWithAnalyticsNext` instead, which returns EditorCommand
22
+ */
17
23
  export function clearFormattingWithAnalytics(inputMethod, editorAnalyticsAPI) {
18
24
  return clearFormatting(inputMethod, editorAnalyticsAPI);
19
25
  }
26
+ const clearNodeFormattingOnSelectionNext = (schema, tr, formattedNodeType, nodeName, formattingCleared) => {
27
+ return function (node, pos) {
28
+ if (node.type === formattedNodeType) {
29
+ if (formattedNodeType.isTextblock) {
30
+ tr.setNodeMarkup(pos, schema.nodes.paragraph);
31
+ formattingCleared.push(nodeName);
32
+ return false;
33
+ } else {
34
+ // In case of panel or blockquote
35
+ const fromPos = tr.doc.resolve(pos + 1);
36
+ const toPos = tr.doc.resolve(pos + node.nodeSize - 1);
37
+ const nodeRange = fromPos.blockRange(toPos);
38
+ if (nodeRange) {
39
+ const targetLiftDepth = liftTarget(nodeRange);
40
+ if (targetLiftDepth || targetLiftDepth === 0) {
41
+ formattingCleared.push(nodeName);
42
+ // Ignored via go/ees005
43
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
+ tr.lift(nodeRange, targetLiftDepth);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ return true;
50
+ };
51
+ };
20
52
  function clearNodeFormattingOnSelection(state, tr, formattedNodeType, nodeName, formattingCleared) {
21
53
  return function (node, pos) {
22
54
  if (node.type === formattedNodeType) {
@@ -106,4 +138,65 @@ export function clearFormatting(inputMethod, editorAnalyticsAPI) {
106
138
  }
107
139
  return true;
108
140
  };
109
- }
141
+ }
142
+ export const clearFormattingWithAnalyticsNext = editorAnalyticsApi => inputMethod => ({
143
+ tr
144
+ }) => {
145
+ const formattingCleared = [];
146
+ const {
147
+ schema
148
+ } = tr.doc.type;
149
+ FORMATTING_MARK_TYPES.forEach(mark => {
150
+ const {
151
+ from,
152
+ to
153
+ } = tr.selection;
154
+ const markType = schema.marks[mark];
155
+ if (!markType) {
156
+ return;
157
+ }
158
+ if (tr.selection instanceof CellSelection) {
159
+ cellSelectionNodesBetween(tr.selection, tr.doc, (node, pos) => {
160
+ const isTableCell = node.type === tr.doc.type.schema.nodes.tableCell || node.type === schema.nodes.tableHeader;
161
+ if (!isTableCell) {
162
+ return true;
163
+ }
164
+ if (tr.doc.rangeHasMark(pos, pos + node.nodeSize, markType)) {
165
+ formattingCleared.push(formatTypes[mark]);
166
+ tr.removeMark(pos, pos + node.nodeSize, markType);
167
+ }
168
+ return false;
169
+ });
170
+ } else if (tr.doc.rangeHasMark(from, to, markType)) {
171
+ formattingCleared.push(formatTypes[mark]);
172
+ tr.removeMark(from, to, markType);
173
+ }
174
+ });
175
+ FORMATTING_NODE_TYPES.forEach(nodeName => {
176
+ const formattedNodeType = schema.nodes[nodeName];
177
+ const {
178
+ $from,
179
+ $to
180
+ } = tr.selection;
181
+ if (tr.selection instanceof CellSelection) {
182
+ cellSelectionNodesBetween(tr.selection, tr.doc, clearNodeFormattingOnSelectionNext(schema, tr, formattedNodeType, nodeName, formattingCleared));
183
+ } else {
184
+ tr.doc.nodesBetween($from.pos, $to.pos, clearNodeFormattingOnSelectionNext(schema, tr, formattedNodeType, nodeName, formattingCleared));
185
+ }
186
+ });
187
+ tr.setStoredMarks([]);
188
+ if (formattingCleared.length && inputMethod) {
189
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
190
+ action: ACTION.FORMATTED,
191
+ eventType: EVENT_TYPE.TRACK,
192
+ actionSubject: ACTION_SUBJECT.TEXT,
193
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_CLEAR,
194
+ attributes: {
195
+ inputMethod,
196
+ formattingCleared,
197
+ dropdownMenu: inputMethod === INPUT_METHOD.TOOLBAR || inputMethod === INPUT_METHOD.FLOATING_TB ? 'textFormatting' : undefined
198
+ }
199
+ })(tr);
200
+ }
201
+ return tr;
202
+ };
@@ -1,6 +1,6 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { toggleMark } from '@atlaskit/editor-common/mark';
3
- import { nextToggleMark } from '../editor-commands/utils/marks';
3
+ import { nextToggleMark } from './utils/marks';
4
4
  export const toggleEm = ({
5
5
  tr
6
6
  }) => {
@@ -0,0 +1 @@
1
+ export {};
@@ -1,13 +1,13 @@
1
1
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
- import { bindKeymapWithCommand, clearFormatting } from '@atlaskit/editor-common/keymaps';
2
+ import { bindKeymapWithEditorCommand, clearFormatting } from '@atlaskit/editor-common/keymaps';
3
3
  import { keymap } from '@atlaskit/editor-prosemirror/keymap';
4
- import { clearFormattingWithAnalytics } from '../editor-commands/clear-formatting';
4
+ import { clearFormattingWithAnalyticsNext } from '../editor-commands/clear-formatting';
5
5
  export function keymapPlugin(editorAnalyticsAPI) {
6
6
  const list = {};
7
- bindKeymapWithCommand(
7
+ bindKeymapWithEditorCommand(
8
8
  // Ignored via go/ees005
9
9
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10
- clearFormatting.common, clearFormattingWithAnalytics(INPUT_METHOD.SHORTCUT, editorAnalyticsAPI), list);
10
+ clearFormatting.common, clearFormattingWithAnalyticsNext(editorAnalyticsAPI)(INPUT_METHOD.SHORTCUT), list);
11
11
  return keymap(list);
12
12
  }
13
13
  export default keymapPlugin;
@@ -3,7 +3,7 @@ import { bindKeymapWithEditorCommand, isCapsLockOnAndModifyKeyboardEvent, toggle
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { keydownHandler } from '@atlaskit/editor-prosemirror/keymap';
5
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
- import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './commands';
6
+ import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from '../editor-commands/toggle-mark';
7
7
  import { pluginKey } from './plugin-key';
8
8
  export default function keymapPlugin(schema, editorAnalyticsAPI) {
9
9
  const list = {};
@@ -1,10 +1,11 @@
1
1
  import React from 'react';
2
2
  import { code, em, strike, strong, subsup, underline } from '@atlaskit/adf-schema';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
6
+ import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './editor-commands/toggle-mark';
5
7
  import { plugin as clearFormattingPlugin, pluginKey as clearFormattingPluginKey } from './pm-plugins/clear-formatting';
6
8
  import clearFormattingKeymapPlugin from './pm-plugins/clear-formatting-keymap';
7
- import { toggleCodeWithAnalytics, toggleEmWithAnalytics, toggleStrikeWithAnalytics, toggleStrongWithAnalytics, toggleSubscriptWithAnalytics, toggleSuperscriptWithAnalytics, toggleUnderlineWithAnalytics } from './pm-plugins/commands';
8
9
  import textFormattingCursorPlugin from './pm-plugins/cursor';
9
10
  import textFormattingInputRulePlugin from './pm-plugins/input-rule';
10
11
  import keymapPlugin from './pm-plugins/keymap';
@@ -13,6 +14,7 @@ import { pluginKey as textFormattingPluginKey } from './pm-plugins/plugin-key';
13
14
  import textFormattingSmartInputRulePlugin from './pm-plugins/smart-input-rule';
14
15
  import { FloatingToolbarTextFormalWithIntl as FloatingToolbarComponent } from './ui/FloatingToolbarComponent';
15
16
  import { PrimaryToolbarComponent, PrimaryToolbarComponentMemoized } from './ui/PrimaryToolbarComponent';
17
+ import { getToolbarComponents } from './ui/toolbar-components';
16
18
 
17
19
  /**
18
20
  * Text formatting plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
@@ -22,7 +24,8 @@ export const textFormattingPlugin = ({
22
24
  config: options,
23
25
  api
24
26
  }) => {
25
- var _api$primaryToolbar, _api$analytics7, _api$analytics8, _api$analytics9, _api$analytics0, _api$analytics1, _api$analytics10, _api$analytics11;
27
+ var _api$analytics7, _api$analytics8, _api$analytics9, _api$analytics0, _api$analytics1, _api$analytics10, _api$analytics11;
28
+ const isToolbarAIFCEnabled = expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true);
26
29
  const primaryToolbarComponent = ({
27
30
  editorView,
28
31
  popupsMountPoint,
@@ -56,10 +59,16 @@ export const textFormattingPlugin = ({
56
59
  shouldUseResponsiveToolbar: Boolean(options === null || options === void 0 ? void 0 : options.responsiveToolbarMenu)
57
60
  });
58
61
  };
59
- api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
60
- name: 'textFormatting',
61
- component: primaryToolbarComponent
62
- });
62
+ if (isToolbarAIFCEnabled) {
63
+ var _api$toolbar;
64
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api));
65
+ } else {
66
+ var _api$primaryToolbar;
67
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
68
+ name: 'textFormatting',
69
+ component: primaryToolbarComponent
70
+ });
71
+ }
63
72
  return {
64
73
  name: 'textFormatting',
65
74
  marks() {
@@ -142,7 +151,7 @@ export const textFormattingPlugin = ({
142
151
  isInitialised: !!(textFormattingState !== null && textFormattingState !== void 0 && textFormattingState.isInitialised)
143
152
  };
144
153
  },
145
- pluginsOptions: {
154
+ pluginsOptions: isToolbarAIFCEnabled ? {} : {
146
155
  selectionToolbar: () => {
147
156
  var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
148
157
  const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : (_api$userPreferences$ = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences$ === void 0 ? void 0 : (_api$userPreferences$2 = _api$userPreferences$.preferences) === null || _api$userPreferences$2 === void 0 ? void 0 : _api$userPreferences$2.toolbarDockingPosition : api === null || api === void 0 ? void 0 : (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 ? void 0 : (_api$selectionToolbar2 = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.currentState()) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.toolbarDocking;
@@ -175,7 +184,7 @@ export const textFormattingPlugin = ({
175
184
  }
176
185
  }
177
186
  },
178
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined,
187
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !isToolbarAIFCEnabled ? primaryToolbarComponent : undefined,
179
188
  commands: {
180
189
  toggleSuperscript: toggleSuperscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions),
181
190
  toggleSubscript: toggleSubscriptWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics8 = api.analytics) === null || _api$analytics8 === void 0 ? void 0 : _api$analytics8.actions),
@@ -0,0 +1,145 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { clearFormatting, getAriaKeyshortcuts, tooltip } from '@atlaskit/editor-common/keymaps';
5
+ import { toolbarMessages } from '@atlaskit/editor-common/messages';
6
+ import { ToolbarButton, ToolbarDropdownItem, ClearFormattingIcon, ToolbarKeyboardShortcutHint, ToolbarDropdownMenu, MoreItemsIcon, ToolbarTooltip } from '@atlaskit/editor-toolbar';
7
+ import { clearFormattingWithAnalyticsNext } from '../../../editor-commands/clear-formatting';
8
+ import { getInputMethodFromParentKeys, useComponentInfo } from './utils';
9
+ export const FormatMenuItem = ({
10
+ parents,
11
+ api,
12
+ optionType,
13
+ toggleMarkWithAnalyticsCallback,
14
+ icon,
15
+ shortcut,
16
+ title
17
+ }) => {
18
+ const {
19
+ isActive,
20
+ isDisabled,
21
+ isHidden,
22
+ shortcutContent,
23
+ onClick,
24
+ ariaLabel,
25
+ formatTitle
26
+ } = useComponentInfo({
27
+ api,
28
+ optionType,
29
+ title,
30
+ shortcut,
31
+ toggleMarkWithAnalyticsCallback,
32
+ parents
33
+ });
34
+ const Icon = icon;
35
+ if (isHidden) {
36
+ return null;
37
+ }
38
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
39
+ elemBefore: /*#__PURE__*/React.createElement(Icon, {
40
+ label: ""
41
+ }),
42
+ elemAfter: shortcutContent && /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
43
+ shortcut: shortcutContent
44
+ }),
45
+ isDisabled: isDisabled,
46
+ isSelected: isActive,
47
+ onClick: onClick,
48
+ "aria-keyshortcuts": getAriaKeyshortcuts(shortcut),
49
+ "aria-label": ariaLabel
50
+ }, formatTitle);
51
+ };
52
+ export const FormatButton = ({
53
+ parents,
54
+ api,
55
+ optionType,
56
+ toggleMarkWithAnalyticsCallback,
57
+ icon,
58
+ shortcut,
59
+ title,
60
+ groupLocation = 'start'
61
+ }) => {
62
+ const {
63
+ isActive,
64
+ isDisabled,
65
+ onClick,
66
+ ariaLabel,
67
+ formatTitle
68
+ } = useComponentInfo({
69
+ api,
70
+ optionType,
71
+ title,
72
+ shortcut,
73
+ toggleMarkWithAnalyticsCallback,
74
+ parents
75
+ });
76
+ const Icon = icon;
77
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
78
+ content: formatTitle
79
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
80
+ iconBefore: /*#__PURE__*/React.createElement(Icon, {
81
+ label: ariaLabel
82
+ }),
83
+ onClick: onClick,
84
+ isSelected: isActive,
85
+ isDisabled: isDisabled,
86
+ groupLocation: groupLocation,
87
+ ariaKeyshortcuts: getAriaKeyshortcuts(shortcut)
88
+ }));
89
+ };
90
+ export const ClearFormatMenuItem = ({
91
+ api,
92
+ parents
93
+ }) => {
94
+ const {
95
+ isInitialised,
96
+ isFormattingPresent
97
+ } = useSharedPluginStateWithSelector(api, ['textFormatting'], states => {
98
+ var _states$textFormattin, _states$textFormattin2;
99
+ return {
100
+ isInitialised: (_states$textFormattin = states.textFormattingState) === null || _states$textFormattin === void 0 ? void 0 : _states$textFormattin.isInitialised,
101
+ isFormattingPresent: (_states$textFormattin2 = states.textFormattingState) === null || _states$textFormattin2 === void 0 ? void 0 : _states$textFormattin2.formattingIsPresent
102
+ };
103
+ });
104
+ const {
105
+ formatMessage
106
+ } = useIntl();
107
+ if (!isInitialised) {
108
+ return null;
109
+ }
110
+ const formatTitle = formatMessage(toolbarMessages.clearFormatting);
111
+ const shortcutContent = tooltip(clearFormatting);
112
+ const ariaLabel = tooltip(clearFormatting, formatTitle);
113
+ const onClick = () => {
114
+ var _api$analytics;
115
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(clearFormattingWithAnalyticsNext(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(getInputMethodFromParentKeys(parents)));
116
+ };
117
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
118
+ elemBefore: /*#__PURE__*/React.createElement(ClearFormattingIcon, {
119
+ label: ""
120
+ }),
121
+ elemAfter: shortcutContent && /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
122
+ shortcut: shortcutContent
123
+ }),
124
+ isDisabled: !isFormattingPresent,
125
+ onClick: onClick,
126
+ "aria-keyshortcuts": getAriaKeyshortcuts(clearFormatting),
127
+ "aria-label": ariaLabel
128
+ }, formatTitle);
129
+ };
130
+ export const MoreFormattingMenu = ({
131
+ children,
132
+ groupLocation
133
+ }) => {
134
+ const {
135
+ formatMessage
136
+ } = useIntl();
137
+ const content = formatMessage(toolbarMessages.moreFormatting);
138
+ return /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
139
+ iconBefore: /*#__PURE__*/React.createElement(MoreItemsIcon, {
140
+ label: content,
141
+ testId: "more-formatting"
142
+ }),
143
+ groupLocation: groupLocation
144
+ }, children);
145
+ };