@atlaskit/editor-plugin-alignment 4.1.3 → 4.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/alignmentPlugin.js +15 -7
  3. package/dist/cjs/editor-commands/index.js +71 -3
  4. package/dist/cjs/ui/Toolbar/AlignmentMenu.js +41 -0
  5. package/dist/cjs/ui/Toolbar/AlignmentMenuItem.js +46 -0
  6. package/dist/cjs/ui/Toolbar/options.js +38 -0
  7. package/dist/cjs/ui/Toolbar/types.js +5 -0
  8. package/dist/cjs/ui/toolbar-components.js +75 -0
  9. package/dist/es2019/alignmentPlugin.js +15 -7
  10. package/dist/es2019/editor-commands/index.js +70 -3
  11. package/dist/es2019/ui/Toolbar/AlignmentMenu.js +38 -0
  12. package/dist/es2019/ui/Toolbar/AlignmentMenuItem.js +43 -0
  13. package/dist/es2019/ui/Toolbar/options.js +30 -0
  14. package/dist/es2019/ui/Toolbar/types.js +1 -0
  15. package/dist/es2019/ui/toolbar-components.js +67 -0
  16. package/dist/esm/alignmentPlugin.js +15 -7
  17. package/dist/esm/editor-commands/index.js +71 -3
  18. package/dist/esm/ui/Toolbar/AlignmentMenu.js +34 -0
  19. package/dist/esm/ui/Toolbar/AlignmentMenuItem.js +39 -0
  20. package/dist/esm/ui/Toolbar/options.js +32 -0
  21. package/dist/esm/ui/Toolbar/types.js +1 -0
  22. package/dist/esm/ui/toolbar-components.js +68 -0
  23. package/dist/types/alignmentPluginType.d.ts +3 -1
  24. package/dist/types/editor-commands/index.d.ts +6 -1
  25. package/dist/types/ui/Alignment/index.d.ts +0 -1
  26. package/dist/types/ui/Toolbar/AlignmentMenu.d.ts +7 -0
  27. package/dist/types/ui/Toolbar/AlignmentMenuItem.d.ts +12 -0
  28. package/dist/types/ui/Toolbar/options.d.ts +3 -0
  29. package/dist/types/ui/Toolbar/types.d.ts +11 -0
  30. package/dist/types/ui/toolbar-components.d.ts +4 -0
  31. package/dist/types-ts4.5/alignmentPluginType.d.ts +3 -1
  32. package/dist/types-ts4.5/editor-commands/index.d.ts +6 -1
  33. package/dist/types-ts4.5/ui/Alignment/index.d.ts +0 -1
  34. package/dist/types-ts4.5/ui/Toolbar/AlignmentMenu.d.ts +7 -0
  35. package/dist/types-ts4.5/ui/Toolbar/AlignmentMenuItem.d.ts +12 -0
  36. package/dist/types-ts4.5/ui/Toolbar/options.d.ts +3 -0
  37. package/dist/types-ts4.5/ui/Toolbar/types.d.ts +11 -0
  38. package/dist/types-ts4.5/ui/toolbar-components.d.ts +4 -0
  39. package/package.json +7 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-alignment
2
2
 
3
+ ## 4.1.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f22ce89845e1e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f22ce89845e1e) -
8
+ [ED-28686] Register alignment toolbar component
9
+ - Updated dependencies
10
+
3
11
  ## 4.1.3
4
12
 
5
13
  ### Patch Changes
@@ -8,17 +8,19 @@ exports.defaultConfig = exports.alignmentPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
11
12
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var _keymap = require("./pm-plugins/keymap");
13
14
  var _main = require("./pm-plugins/main");
14
15
  var _FloatingToolbarComponent = require("./ui/FloatingToolbarComponent");
15
16
  var _PrimaryToolbarComponent = require("./ui/PrimaryToolbarComponent");
17
+ var _toolbarComponents = require("./ui/toolbar-components");
16
18
  var defaultConfig = exports.defaultConfig = {
17
19
  align: 'start'
18
20
  };
19
21
  var alignmentPlugin = exports.alignmentPlugin = function alignmentPlugin(_ref) {
20
- var _api$primaryToolbar;
21
22
  var api = _ref.api;
23
+ var isToolbarAIFCEnabled = (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true);
22
24
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
23
25
  var editorView = _ref2.editorView,
24
26
  popupsMountPoint = _ref2.popupsMountPoint,
@@ -36,10 +38,16 @@ var alignmentPlugin = exports.alignmentPlugin = function alignmentPlugin(_ref) {
36
38
  isToolbarReducedSpacing: isToolbarReducedSpacing
37
39
  });
38
40
  };
39
- api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
40
- name: 'alignment',
41
- component: primaryToolbarComponent
42
- });
41
+ if (isToolbarAIFCEnabled) {
42
+ var _api$toolbar;
43
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getToolbarComponents)(api));
44
+ } else {
45
+ var _api$primaryToolbar;
46
+ api === null || api === void 0 || (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 || _api$primaryToolbar.actions.registerComponent({
47
+ name: 'alignment',
48
+ component: primaryToolbarComponent
49
+ });
50
+ }
43
51
  return {
44
52
  name: 'alignment',
45
53
  marks: function marks() {
@@ -73,7 +81,7 @@ var alignmentPlugin = exports.alignmentPlugin = function alignmentPlugin(_ref) {
73
81
  }];
74
82
  },
75
83
  pluginsOptions: {
76
- selectionToolbar: function selectionToolbar() {
84
+ selectionToolbar: isToolbarAIFCEnabled ? undefined : function () {
77
85
  var _api$userPreferences, _api$selectionToolbar;
78
86
  var toolbarDocking = (0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin') ? api === null || api === void 0 || (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences === void 0 || (_api$userPreferences = _api$userPreferences.preferences) === null || _api$userPreferences === void 0 ? void 0 : _api$userPreferences.toolbarDockingPosition : api === null || api === void 0 || (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar === void 0 || (_api$selectionToolbar = _api$selectionToolbar.currentState()) === null || _api$selectionToolbar === void 0 ? void 0 : _api$selectionToolbar.toolbarDocking;
79
87
  if (toolbarDocking === 'none' && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
@@ -103,6 +111,6 @@ var alignmentPlugin = exports.alignmentPlugin = function alignmentPlugin(_ref) {
103
111
  }
104
112
  }
105
113
  },
106
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
114
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !isToolbarAIFCEnabled ? primaryToolbarComponent : undefined
107
115
  };
108
116
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isAlignable = exports.changeAlignment = void 0;
6
+ exports.isAlignable = exports.changeAlignmentTr = exports.changeAlignment = void 0;
7
7
  var _analytics = require("@atlaskit/editor-common/analytics");
8
8
  var _commands = require("@atlaskit/editor-common/commands");
9
9
  var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
@@ -71,6 +71,35 @@ var changeBlockAlignmentWithAnalytics = function changeBlockAlignmentWithAnalyti
71
71
  }, [paragraph, heading]))(state, dispatch);
72
72
  };
73
73
  };
74
+ var changeBlockAlignmentWithAnalyticsTr = function changeBlockAlignmentWithAnalyticsTr(api, align, inputMethod) {
75
+ return function (_ref) {
76
+ var tr = _ref.tr;
77
+ var _tr$doc$type$schema = tr.doc.type.schema,
78
+ _tr$doc$type$schema$n = _tr$doc$type$schema.nodes,
79
+ paragraph = _tr$doc$type$schema$n.paragraph,
80
+ heading = _tr$doc$type$schema$n.heading,
81
+ alignment = _tr$doc$type$schema.marks.alignment;
82
+ var alignmentApplied = (0, _commands.toggleBlockMarkNext)(alignment, function () {
83
+ return !align ? undefined : align === 'start' ? false : {
84
+ align: align
85
+ };
86
+ }, [paragraph, heading])(tr);
87
+ if (alignmentApplied) {
88
+ var _api$analytics;
89
+ api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
90
+ eventType: _analytics.EVENT_TYPE.TRACK,
91
+ actionSubject: _analytics.ACTION_SUBJECT.ALIGNMENT,
92
+ action: _analytics.ACTION.UPDATED,
93
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TEXT,
94
+ attributes: {
95
+ alignmentType: align,
96
+ inputMethod: inputMethod
97
+ }
98
+ })(tr);
99
+ }
100
+ return tr;
101
+ };
102
+ };
74
103
  var changeImageAlignmentWithAnalytics = function changeImageAlignmentWithAnalytics(editorAnalyticsApi, align, inputMethod) {
75
104
  return function (state, dispatch) {
76
105
  return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, {
@@ -85,9 +114,48 @@ var changeImageAlignmentWithAnalytics = function changeImageAlignmentWithAnalyti
85
114
  })((0, _commands.changeImageAlignment)(align))(state, dispatch);
86
115
  };
87
116
  };
117
+ var changeImageAlignmentWithAnalyticsTr = function changeImageAlignmentWithAnalyticsTr(api, align, inputMethod) {
118
+ return function (_ref2) {
119
+ var tr = _ref2.tr;
120
+ var alignmentApplied = (0, _commands.changeImageAlignmentNext)(align)(tr);
121
+ if (alignmentApplied) {
122
+ var _api$analytics2;
123
+ api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.attachAnalyticsEvent({
124
+ eventType: _analytics.EVENT_TYPE.TRACK,
125
+ actionSubject: _analytics.ACTION_SUBJECT.ALIGNMENT,
126
+ action: _analytics.ACTION.UPDATED,
127
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.MEDIA_SINGLE,
128
+ attributes: {
129
+ alignmentType: align,
130
+ inputMethod: inputMethod
131
+ }
132
+ })(tr);
133
+ }
134
+ return tr;
135
+ };
136
+ };
137
+
138
+ // Remove this when cleaning up platform_editor_toolbar_aifc
139
+ // eslint-disable-next-line @repo/internal/deprecations/deprecation-ticket-required
140
+ /**
141
+ *
142
+ * @deprecated use changeAlignmentTr instead
143
+ */
88
144
  var changeAlignment = exports.changeAlignment = function changeAlignment(align, api, inputMethod) {
89
145
  return function (state, dispatch) {
90
- var _api$analytics, _api$analytics2;
91
- return cascadeCommands([changeImageAlignmentWithAnalytics(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, align, inputMethod), changeBlockAlignmentWithAnalytics(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, align, inputMethod)])(state, dispatch);
146
+ var _api$analytics3, _api$analytics4;
147
+ return cascadeCommands([changeImageAlignmentWithAnalytics(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, align, inputMethod), changeBlockAlignmentWithAnalytics(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, align, inputMethod)])(state, dispatch);
148
+ };
149
+ };
150
+ var changeAlignmentTr = exports.changeAlignmentTr = function changeAlignmentTr(api, align, inputMethod) {
151
+ return function (_ref3) {
152
+ var tr = _ref3.tr;
153
+ changeBlockAlignmentWithAnalyticsTr(api, align, inputMethod)({
154
+ tr: tr
155
+ });
156
+ changeImageAlignmentWithAnalyticsTr(api, align, inputMethod)({
157
+ tr: tr
158
+ });
159
+ return tr;
92
160
  };
93
161
  };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AlignmentMenu = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
13
+ var _options = require("./options");
14
+ var AlignmentMenu = exports.AlignmentMenu = function AlignmentMenu(_ref) {
15
+ var children = _ref.children,
16
+ api = _ref.api;
17
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['alignment'], function (states) {
18
+ var _states$alignmentStat, _states$alignmentStat2;
19
+ return {
20
+ align: (_states$alignmentStat = states.alignmentState) === null || _states$alignmentStat === void 0 ? void 0 : _states$alignmentStat.align,
21
+ isEnabled: (_states$alignmentStat2 = states.alignmentState) === null || _states$alignmentStat2 === void 0 ? void 0 : _states$alignmentStat2.isEnabled
22
+ };
23
+ }),
24
+ _useSharedPluginState2 = _useSharedPluginState.align,
25
+ align = _useSharedPluginState2 === void 0 ? 'start' : _useSharedPluginState2,
26
+ isEnabled = _useSharedPluginState.isEnabled;
27
+ var Icon = (0, _options.alignmentOptions)()[align].icon;
28
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
29
+ formatMessage = _useIntl.formatMessage;
30
+ var title = formatMessage(_messages.alignmentMessages.alignment);
31
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
32
+ content: title
33
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenu, {
34
+ iconBefore: /*#__PURE__*/_react.default.createElement(Icon, {
35
+ label: ""
36
+ }),
37
+ isDisabled: !isEnabled,
38
+ testId: "text-alignment-menu",
39
+ label: title
40
+ }, children));
41
+ };
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AlignmentMenuItem = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _hooks = require("@atlaskit/editor-common/hooks");
11
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
12
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
13
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
14
+ var _editorCommands = require("../../editor-commands");
15
+ var AlignmentMenuItem = exports.AlignmentMenuItem = function AlignmentMenuItem(_ref) {
16
+ var _ref$option = _ref.option,
17
+ label = _ref$option.label,
18
+ Icon = _ref$option.icon,
19
+ keymap = _ref$option.keymap,
20
+ api = _ref.api,
21
+ alignment = _ref.alignment,
22
+ parents = _ref.parents;
23
+ var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['alignment'], function (states) {
24
+ var _states$alignmentStat;
25
+ return {
26
+ align: (_states$alignmentStat = states.alignmentState) === null || _states$alignmentStat === void 0 ? void 0 : _states$alignmentStat.align
27
+ };
28
+ }),
29
+ align = _useSharedPluginState.align;
30
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
31
+ formatMessage = _useIntl.formatMessage;
32
+ var shortcut = (0, _keymaps.tooltip)(keymap);
33
+ return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
34
+ isSelected: align === alignment,
35
+ elemBefore: /*#__PURE__*/_react.default.createElement(Icon, {
36
+ label: ""
37
+ }),
38
+ elemAfter: shortcut && /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarKeyboardShortcutHint, {
39
+ shortcut: shortcut
40
+ }),
41
+ ariaKeyshortcuts: (0, _keymaps.getAriaKeyshortcuts)(keymap),
42
+ onClick: function onClick() {
43
+ api === null || api === void 0 || api.core.actions.execute((0, _editorCommands.changeAlignmentTr)(api, alignment, (0, _toolbar.getInputMethodFromParentKeys)(parents)));
44
+ }
45
+ }, formatMessage(label));
46
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.alignmentOptions = void 0;
7
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
8
+ var _messages = require("@atlaskit/editor-common/messages");
9
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
11
+ var alignmentOptions = exports.alignmentOptions = function alignmentOptions() {
12
+ return {
13
+ start: {
14
+ key: _toolbar.ALIGN_LEFT_MENU_ITEM.key,
15
+ type: _toolbar.ALIGN_LEFT_MENU_ITEM.type,
16
+ rank: _toolbar.ALIGNMENT_MENU_SECTION_RANK[_toolbar.ALIGN_LEFT_MENU_ITEM.key],
17
+ label: _messages.alignmentMessages.alignLeft,
18
+ icon: _editorToolbar.AlignTextLeftIcon,
19
+ keymap: _keymaps.alignLeft
20
+ },
21
+ center: {
22
+ key: _toolbar.ALIGN_CENTER_MENU_ITEM.key,
23
+ type: _toolbar.ALIGN_CENTER_MENU_ITEM.type,
24
+ rank: _toolbar.ALIGNMENT_MENU_SECTION_RANK[_toolbar.ALIGN_CENTER_MENU_ITEM.key],
25
+ label: _messages.alignmentMessages.alignCenter,
26
+ icon: _editorToolbar.AlignTextCenterIcon,
27
+ keymap: _keymaps.alignCenter
28
+ },
29
+ end: {
30
+ key: _toolbar.ALIGN_RIGHT_MENU_ITEM.key,
31
+ type: _toolbar.ALIGN_RIGHT_MENU_ITEM.type,
32
+ rank: _toolbar.ALIGNMENT_MENU_SECTION_RANK[_toolbar.ALIGN_RIGHT_MENU_ITEM.key],
33
+ label: _messages.alignmentMessages.alignRight,
34
+ icon: _editorToolbar.AlignTextRightIcon,
35
+ keymap: _keymaps.alignRight
36
+ }
37
+ };
38
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,75 @@
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 _AlignmentMenu = require("./Toolbar/AlignmentMenu");
13
+ var _AlignmentMenuItem = require("./Toolbar/AlignmentMenuItem");
14
+ var _options = require("./Toolbar/options");
15
+ var getAlignmentMenuItems = function getAlignmentMenuItems(api) {
16
+ return Object.entries((0, _options.alignmentOptions)()).map(function (_ref) {
17
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
18
+ alignment = _ref2[0],
19
+ item = _ref2[1];
20
+ var key = item.key,
21
+ type = item.type,
22
+ rank = item.rank;
23
+ return {
24
+ type: type,
25
+ key: key,
26
+ parents: [{
27
+ type: _toolbar.ALIGNMENT_MENU_SECTION.type,
28
+ key: _toolbar.ALIGNMENT_MENU_SECTION.key,
29
+ rank: rank
30
+ }],
31
+ component: function component(_ref3) {
32
+ var parents = _ref3.parents;
33
+ return /*#__PURE__*/_react.default.createElement(_AlignmentMenuItem.AlignmentMenuItem, {
34
+ api: api,
35
+ option: item,
36
+ alignment: alignment,
37
+ parents: parents
38
+ });
39
+ }
40
+ };
41
+ });
42
+ };
43
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
44
+ return [{
45
+ type: _toolbar.ALIGNMENT_GROUP.type,
46
+ key: _toolbar.ALIGNMENT_GROUP.key,
47
+ parents: [{
48
+ type: _toolbar.TEXT_SECTION.type,
49
+ key: _toolbar.TEXT_SECTION.key,
50
+ rank: _toolbar.TEXT_SECTION_RANK[_toolbar.ALIGNMENT_GROUP.key]
51
+ }]
52
+ }, {
53
+ type: _toolbar.ALIGNMENT_MENU.type,
54
+ key: _toolbar.ALIGNMENT_MENU.key,
55
+ parents: [{
56
+ type: _toolbar.ALIGNMENT_GROUP.type,
57
+ key: _toolbar.ALIGNMENT_GROUP.key,
58
+ rank: _toolbar.ALIGNMENT_GROUP_RANK[_toolbar.ALIGNMENT_MENU.key]
59
+ }],
60
+ component: function component(_ref4) {
61
+ var children = _ref4.children;
62
+ return /*#__PURE__*/_react.default.createElement(_AlignmentMenu.AlignmentMenu, {
63
+ api: api
64
+ }, children);
65
+ }
66
+ }, {
67
+ type: _toolbar.ALIGNMENT_MENU_SECTION.type,
68
+ key: _toolbar.ALIGNMENT_MENU_SECTION.key,
69
+ parents: [{
70
+ type: _toolbar.ALIGNMENT_MENU.type,
71
+ key: _toolbar.ALIGNMENT_MENU.key,
72
+ rank: _toolbar.ALIGNMENT_MENU_RANK[_toolbar.ALIGNMENT_MENU_SECTION.key]
73
+ }]
74
+ }].concat((0, _toConsumableArray2.default)(getAlignmentMenuItems(api)));
75
+ };
@@ -1,18 +1,20 @@
1
1
  import React from 'react';
2
2
  import { alignment } 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';
5
6
  import { keymapPlugin } from './pm-plugins/keymap';
6
7
  import { createPlugin, pluginKey } from './pm-plugins/main';
7
8
  import { FloatingToolbarComponent } from './ui/FloatingToolbarComponent';
8
9
  import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
10
+ import { getToolbarComponents } from './ui/toolbar-components';
9
11
  export const defaultConfig = {
10
12
  align: 'start'
11
13
  };
12
14
  export const alignmentPlugin = ({
13
15
  api
14
16
  }) => {
15
- var _api$primaryToolbar;
17
+ const isToolbarAIFCEnabled = expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true);
16
18
  const primaryToolbarComponent = ({
17
19
  editorView,
18
20
  popupsMountPoint,
@@ -31,10 +33,16 @@ export const alignmentPlugin = ({
31
33
  isToolbarReducedSpacing: isToolbarReducedSpacing
32
34
  });
33
35
  };
34
- api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
35
- name: 'alignment',
36
- component: primaryToolbarComponent
37
- });
36
+ if (isToolbarAIFCEnabled) {
37
+ var _api$toolbar;
38
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api));
39
+ } else {
40
+ var _api$primaryToolbar;
41
+ api === null || api === void 0 ? void 0 : (_api$primaryToolbar = api.primaryToolbar) === null || _api$primaryToolbar === void 0 ? void 0 : _api$primaryToolbar.actions.registerComponent({
42
+ name: 'alignment',
43
+ component: primaryToolbarComponent
44
+ });
45
+ }
38
46
  return {
39
47
  name: 'alignment',
40
48
  marks() {
@@ -65,7 +73,7 @@ export const alignmentPlugin = ({
65
73
  }];
66
74
  },
67
75
  pluginsOptions: {
68
- selectionToolbar: () => {
76
+ selectionToolbar: isToolbarAIFCEnabled ? undefined : () => {
69
77
  var _api$userPreferences, _api$userPreferences$, _api$userPreferences$2, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
70
78
  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;
71
79
  if (toolbarDocking === 'none' && editorExperiment('platform_editor_controls', 'variant1', {
@@ -95,6 +103,6 @@ export const alignmentPlugin = ({
95
103
  }
96
104
  }
97
105
  },
98
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
106
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && !isToolbarAIFCEnabled ? primaryToolbarComponent : undefined
99
107
  };
100
108
  };
@@ -1,5 +1,5 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
- import { changeImageAlignment, toggleBlockMark } from '@atlaskit/editor-common/commands';
2
+ import { changeImageAlignment, changeImageAlignmentNext, toggleBlockMark, toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
3
3
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
5
5
  /**
@@ -65,6 +65,36 @@ const changeBlockAlignmentWithAnalytics = (editorAnalyticsApi, align, inputMetho
65
65
  align
66
66
  }, [paragraph, heading]))(state, dispatch);
67
67
  };
68
+ const changeBlockAlignmentWithAnalyticsTr = (api, align, inputMethod) => ({
69
+ tr
70
+ }) => {
71
+ const {
72
+ nodes: {
73
+ paragraph,
74
+ heading
75
+ },
76
+ marks: {
77
+ alignment
78
+ }
79
+ } = tr.doc.type.schema;
80
+ const alignmentApplied = toggleBlockMarkNext(alignment, () => !align ? undefined : align === 'start' ? false : {
81
+ align
82
+ }, [paragraph, heading])(tr);
83
+ if (alignmentApplied) {
84
+ var _api$analytics;
85
+ api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
86
+ eventType: EVENT_TYPE.TRACK,
87
+ actionSubject: ACTION_SUBJECT.ALIGNMENT,
88
+ action: ACTION.UPDATED,
89
+ actionSubjectId: ACTION_SUBJECT_ID.TEXT,
90
+ attributes: {
91
+ alignmentType: align,
92
+ inputMethod
93
+ }
94
+ })(tr);
95
+ }
96
+ return tr;
97
+ };
68
98
  const changeImageAlignmentWithAnalytics = (editorAnalyticsApi, align, inputMethod) => (state, dispatch) => {
69
99
  return withAnalytics(editorAnalyticsApi, {
70
100
  eventType: EVENT_TYPE.TRACK,
@@ -77,7 +107,44 @@ const changeImageAlignmentWithAnalytics = (editorAnalyticsApi, align, inputMetho
77
107
  }
78
108
  })(changeImageAlignment(align))(state, dispatch);
79
109
  };
110
+ const changeImageAlignmentWithAnalyticsTr = (api, align, inputMethod) => ({
111
+ tr
112
+ }) => {
113
+ const alignmentApplied = changeImageAlignmentNext(align)(tr);
114
+ if (alignmentApplied) {
115
+ var _api$analytics2;
116
+ api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.attachAnalyticsEvent({
117
+ eventType: EVENT_TYPE.TRACK,
118
+ actionSubject: ACTION_SUBJECT.ALIGNMENT,
119
+ action: ACTION.UPDATED,
120
+ actionSubjectId: ACTION_SUBJECT_ID.MEDIA_SINGLE,
121
+ attributes: {
122
+ alignmentType: align,
123
+ inputMethod
124
+ }
125
+ })(tr);
126
+ }
127
+ return tr;
128
+ };
129
+
130
+ // Remove this when cleaning up platform_editor_toolbar_aifc
131
+ // eslint-disable-next-line @repo/internal/deprecations/deprecation-ticket-required
132
+ /**
133
+ *
134
+ * @deprecated use changeAlignmentTr instead
135
+ */
80
136
  export const changeAlignment = (align, api, inputMethod) => (state, dispatch) => {
81
- var _api$analytics, _api$analytics2;
82
- return cascadeCommands([changeImageAlignmentWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, align, inputMethod), changeBlockAlignmentWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, align, inputMethod)])(state, dispatch);
137
+ var _api$analytics3, _api$analytics4;
138
+ return cascadeCommands([changeImageAlignmentWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, align, inputMethod), changeBlockAlignmentWithAnalytics(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, align, inputMethod)])(state, dispatch);
139
+ };
140
+ export const changeAlignmentTr = (api, align, inputMethod) => ({
141
+ tr
142
+ }) => {
143
+ changeBlockAlignmentWithAnalyticsTr(api, align, inputMethod)({
144
+ tr
145
+ });
146
+ changeImageAlignmentWithAnalyticsTr(api, align, inputMethod)({
147
+ tr
148
+ });
149
+ return tr;
83
150
  };
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { alignmentMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { ToolbarDropdownMenu, ToolbarTooltip } from '@atlaskit/editor-toolbar';
6
+ import { alignmentOptions } from './options';
7
+ export const AlignmentMenu = ({
8
+ children,
9
+ api
10
+ }) => {
11
+ const {
12
+ align = 'start',
13
+ isEnabled
14
+ } = useSharedPluginStateWithSelector(api, ['alignment'], states => {
15
+ var _states$alignmentStat, _states$alignmentStat2;
16
+ return {
17
+ align: (_states$alignmentStat = states.alignmentState) === null || _states$alignmentStat === void 0 ? void 0 : _states$alignmentStat.align,
18
+ isEnabled: (_states$alignmentStat2 = states.alignmentState) === null || _states$alignmentStat2 === void 0 ? void 0 : _states$alignmentStat2.isEnabled
19
+ };
20
+ });
21
+ const {
22
+ icon: Icon
23
+ } = alignmentOptions()[align];
24
+ const {
25
+ formatMessage
26
+ } = useIntl();
27
+ const title = formatMessage(messages.alignment);
28
+ return /*#__PURE__*/React.createElement(ToolbarTooltip, {
29
+ content: title
30
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
31
+ iconBefore: /*#__PURE__*/React.createElement(Icon, {
32
+ label: ""
33
+ }),
34
+ isDisabled: !isEnabled,
35
+ testId: "text-alignment-menu",
36
+ label: title
37
+ }, children));
38
+ };
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
+ import { getAriaKeyshortcuts, tooltip } from '@atlaskit/editor-common/keymaps';
5
+ import { getInputMethodFromParentKeys } from '@atlaskit/editor-common/toolbar';
6
+ import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
7
+ import { changeAlignmentTr } from '../../editor-commands';
8
+ export const AlignmentMenuItem = ({
9
+ option: {
10
+ label,
11
+ icon: Icon,
12
+ keymap
13
+ },
14
+ api,
15
+ alignment,
16
+ parents
17
+ }) => {
18
+ const {
19
+ align
20
+ } = useSharedPluginStateWithSelector(api, ['alignment'], states => {
21
+ var _states$alignmentStat;
22
+ return {
23
+ align: (_states$alignmentStat = states.alignmentState) === null || _states$alignmentStat === void 0 ? void 0 : _states$alignmentStat.align
24
+ };
25
+ });
26
+ const {
27
+ formatMessage
28
+ } = useIntl();
29
+ const shortcut = tooltip(keymap);
30
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
31
+ isSelected: align === alignment,
32
+ elemBefore: /*#__PURE__*/React.createElement(Icon, {
33
+ label: ""
34
+ }),
35
+ elemAfter: shortcut && /*#__PURE__*/React.createElement(ToolbarKeyboardShortcutHint, {
36
+ shortcut: shortcut
37
+ }),
38
+ ariaKeyshortcuts: getAriaKeyshortcuts(keymap),
39
+ onClick: () => {
40
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(changeAlignmentTr(api, alignment, getInputMethodFromParentKeys(parents)));
41
+ }
42
+ }, formatMessage(label));
43
+ };
@@ -0,0 +1,30 @@
1
+ import { alignCenter, alignLeft, alignRight } from '@atlaskit/editor-common/keymaps';
2
+ import { alignmentMessages as messages } from '@atlaskit/editor-common/messages';
3
+ import { ALIGN_LEFT_MENU_ITEM, ALIGN_CENTER_MENU_ITEM, ALIGN_RIGHT_MENU_ITEM, ALIGNMENT_MENU_SECTION_RANK } from '@atlaskit/editor-common/toolbar';
4
+ import { AlignTextLeftIcon, AlignTextCenterIcon, AlignTextRightIcon } from '@atlaskit/editor-toolbar';
5
+ export const alignmentOptions = () => ({
6
+ start: {
7
+ key: ALIGN_LEFT_MENU_ITEM.key,
8
+ type: ALIGN_LEFT_MENU_ITEM.type,
9
+ rank: ALIGNMENT_MENU_SECTION_RANK[ALIGN_LEFT_MENU_ITEM.key],
10
+ label: messages.alignLeft,
11
+ icon: AlignTextLeftIcon,
12
+ keymap: alignLeft
13
+ },
14
+ center: {
15
+ key: ALIGN_CENTER_MENU_ITEM.key,
16
+ type: ALIGN_CENTER_MENU_ITEM.type,
17
+ rank: ALIGNMENT_MENU_SECTION_RANK[ALIGN_CENTER_MENU_ITEM.key],
18
+ label: messages.alignCenter,
19
+ icon: AlignTextCenterIcon,
20
+ keymap: alignCenter
21
+ },
22
+ end: {
23
+ key: ALIGN_RIGHT_MENU_ITEM.key,
24
+ type: ALIGN_RIGHT_MENU_ITEM.type,
25
+ rank: ALIGNMENT_MENU_SECTION_RANK[ALIGN_RIGHT_MENU_ITEM.key],
26
+ label: messages.alignRight,
27
+ icon: AlignTextRightIcon,
28
+ keymap: alignRight
29
+ }
30
+ });
@@ -0,0 +1 @@
1
+ export {};