@atlaskit/editor-plugin-rule 30.0.2 → 30.1.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,26 @@
1
1
  # @atlaskit/editor-plugin-rule
2
2
 
3
+ ## 30.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`85d826388ed61`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/85d826388ed61) -
8
+ [ux] [EDITOR-8341] introduce `Add text` and `Align text` to the divider toolbar controls behind
9
+ `platform_editor_lovability_dividers` and `platform_editor_lovability_dividers_m2`.
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 30.0.3
16
+
17
+ ### Patch Changes
18
+
19
+ - [`16d59dad238c4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/16d59dad238c4) -
20
+ [EDITOR-8351] fix focus ring and arrow-key behaviour for the divider options dropdown menu behind
21
+ `platform_editor_lovability_dividers` and `platform_editor_lovability_dividers_patch_1`.
22
+ - Updated dependencies
23
+
3
24
  ## 30.0.2
4
25
 
5
26
  ### Patch Changes
package/compass.yml CHANGED
@@ -35,7 +35,7 @@ customFields:
35
35
  value: true
36
36
  - name: Reviewer Selection Mechanism
37
37
  type: text
38
- value: random(2)
38
+ value: randomTZIgnored(2)
39
39
  - name: Required Reviewer Approvals
40
40
  type: number
41
41
  value: 1
@@ -1,4 +1,4 @@
1
- /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  "use strict";
3
3
 
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
@@ -13,9 +13,11 @@ var _react = _interopRequireWildcard(require("react"));
13
13
  var _reactIntl = require("react-intl");
14
14
  var _button = _interopRequireDefault(require("@atlaskit/button/icon/button"));
15
15
  var _rule = require("@atlaskit/editor-common/messages/rule");
16
+ var _ReactEditorViewContext = _interopRequireDefault(require("@atlaskit/editor-common/ui-react/ReactEditorViewContext"));
16
17
  var _strokeWeightLarge = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-large"));
17
18
  var _strokeWeightMedium = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-medium"));
18
19
  var _strokeWeightSmall = _interopRequireDefault(require("@atlaskit/icon/core/stroke-weight-small"));
20
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
19
21
  var _box = require("@atlaskit/primitives/compiled/box");
20
22
  var _text = require("@atlaskit/primitives/compiled/text");
21
23
  var _constants = require("./constants");
@@ -32,6 +34,7 @@ var styles = {
32
34
  dividerOptionsButtonContainer: "_1rjc1b66"
33
35
  };
34
36
  var dividerOptionsButtonStyles = null;
37
+ var dividerOptionsButtonStylesOld = null;
35
38
  var SmallWeightIcon = function SmallWeightIcon(iconProps) {
36
39
  return /*#__PURE__*/_react.default.createElement(_strokeWeightSmall.default, {
37
40
  color: "var(--ds-icon-subtle, #505258)",
@@ -89,21 +92,25 @@ var styleOptionRows = [
89
92
  value: 'fade'
90
93
  }]];
91
94
  var DividerOptionButton = function DividerOptionButton(_ref) {
92
- var icon = _ref.icon,
95
+ var autoFocus = _ref.autoFocus,
96
+ icon = _ref.icon,
93
97
  isSelected = _ref.isSelected,
94
98
  label = _ref.label,
99
+ onKeyDownCapture = _ref.onKeyDownCapture,
95
100
  onSelect = _ref.onSelect,
96
101
  value = _ref.value;
97
102
  var handleClick = (0, _react.useCallback)(function () {
98
103
  return onSelect === null || onSelect === void 0 ? void 0 : onSelect(value);
99
104
  }, [onSelect, value]);
100
105
  return /*#__PURE__*/_react.default.createElement("div", {
101
- className: (0, _runtime.ax)(["_2rko1mok _1reo15vq _18m915vq _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq"])
106
+ className: (0, _runtime.ax)(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
102
107
  }, /*#__PURE__*/_react.default.createElement(_button.default, {
108
+ autoFocus: autoFocus,
103
109
  icon: icon,
104
110
  isSelected: isSelected,
105
111
  label: label,
106
- onClick: handleClick
112
+ onClick: handleClick,
113
+ onKeyDownCapture: onKeyDownCapture
107
114
  }));
108
115
  };
109
116
  var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
@@ -113,10 +120,50 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
113
120
  weight = _ref2.weight;
114
121
  var _useIntl = (0, _reactIntl.useIntl)(),
115
122
  formatMessage = _useIntl.formatMessage;
123
+ var _useContext = (0, _react.useContext)(_ReactEditorViewContext.default),
124
+ popupsMountPoint = _useContext.popupsMountPoint;
125
+ var containerRef = (0, _react.useRef)(null);
126
+ var handleKeyDown = (0, _react.useCallback)(function (event) {
127
+ var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
128
+ var buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
129
+ var index = buttons.indexOf(event.currentTarget);
130
+ if (index === -1) {
131
+ return;
132
+ }
133
+ var columns = weightOptions.length;
134
+ var row = Math.floor(index / columns);
135
+ var column = index % columns;
136
+ var rows = [weightOptions].concat(styleOptionRows);
137
+ var nextIndex;
138
+ switch (event.key) {
139
+ case 'ArrowDown':
140
+ case 'ArrowUp':
141
+ {
142
+ var nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
143
+ nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
144
+ break;
145
+ }
146
+ case 'ArrowRight':
147
+ nextIndex = (index + 1) % buttons.length;
148
+ break;
149
+ case 'ArrowLeft':
150
+ nextIndex = (index - 1 + buttons.length) % buttons.length;
151
+ break;
152
+ default:
153
+ return;
154
+ }
155
+ event.preventDefault();
156
+ event.stopPropagation();
157
+ (_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 || _buttons$nextIndex.focus();
158
+ }, []);
116
159
  var selectedStyle = style !== null && style !== void 0 ? style : _constants.DEFAULT_DIVIDER_STYLE;
117
160
  var selectedWeight = weight !== null && weight !== void 0 ? weight : _constants.DEFAULT_DIVIDER_WEIGHT;
161
+ var isPatchEnabled = (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers_patch_1');
118
162
  return /*#__PURE__*/_react.default.createElement(_box.Box, {
119
- xcss: styles.container
163
+ xcss: styles.container,
164
+ ref: isPatchEnabled ? containerRef : undefined,
165
+ role: isPatchEnabled ? 'group' : undefined,
166
+ "aria-label": isPatchEnabled ? formatMessage(_rule.ruleMessages.dividerOptions) : undefined
120
167
  }, /*#__PURE__*/_react.default.createElement(_box.Box, {
121
168
  xcss: styles.section
122
169
  }, /*#__PURE__*/_react.default.createElement(_text.Text, {
@@ -132,9 +179,14 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
132
179
  value = _ref3.value;
133
180
  return /*#__PURE__*/_react.default.createElement(DividerOptionButton, {
134
181
  key: value,
182
+ autoFocus:
183
+ // when there is no custom mount point, Dropdown sends ArrowDown
184
+ // on keyboard open so autofocusing is not required.
185
+ isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
135
186
  icon: icon,
136
187
  isSelected: selectedWeight === value,
137
188
  label: formatMessage(label),
189
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
138
190
  onSelect: onWeightChange,
139
191
  value: value
140
192
  });
@@ -158,6 +210,7 @@ var DividerOptions = exports.DividerOptions = function DividerOptions(_ref2) {
158
210
  icon: icon,
159
211
  isSelected: selectedStyle === value,
160
212
  label: formatMessage(label),
213
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
161
214
  onSelect: onStyleChange,
162
215
  value: value
163
216
  });
@@ -7,21 +7,36 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getToolbarConfig = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _react = _interopRequireDefault(require("react"));
10
+ var _alignment = require("@atlaskit/editor-common/alignment");
11
+ var _alignmentIconMap = require("@atlaskit/editor-common/alignment-icon-map");
10
12
  var _enums = require("@atlaskit/editor-common/analytics/types/enums");
13
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
11
14
  var _messages = _interopRequireDefault(require("@atlaskit/editor-common/messages"));
12
15
  var _rule = require("@atlaskit/editor-common/messages/rule");
16
+ var _Shortcut = require("@atlaskit/editor-common/Shortcut");
13
17
  var _text = require("@atlaskit/editor-palette/text");
14
18
  var _utils = require("@atlaskit/editor-prosemirror/utils");
15
19
  var _constants = require("@atlaskit/editor-shared-styles/constants");
20
+ var _alignTextCenterIcon = require("@atlaskit/editor-toolbar/align-text-center-icon");
21
+ var _alignTextLeftIcon = require("@atlaskit/editor-toolbar/align-text-left-icon");
22
+ var _alignTextRightIcon = require("@atlaskit/editor-toolbar/align-text-right-icon");
23
+ var _fieldTextIcon = require("@atlaskit/editor-toolbar/field-text-icon");
16
24
  var _copy = _interopRequireDefault(require("@atlaskit/icon/core/copy"));
17
25
  var _customize = _interopRequireDefault(require("@atlaskit/icon/core/customize"));
18
26
  var _delete = _interopRequireDefault(require("@atlaskit/icon/core/delete"));
27
+ var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
19
28
  var _commands = require("../pm-plugins/commands");
20
29
  var _dividerColorPalette = require("./dividerColorPalette");
21
30
  var _dividerColorPaletteMessages = require("./dividerColorPaletteMessages");
22
31
  var _DividerOptions = require("./DividerOptions");
23
32
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
24
33
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
34
+ var DividerAlignmentIcon = function DividerAlignmentIcon() {
35
+ return /*#__PURE__*/_react.default.createElement(_alignmentIconMap.AlignmentIconMap, {
36
+ alignment: "center",
37
+ size: "small"
38
+ });
39
+ };
25
40
  var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, ruleAttrs, api) {
26
41
  var _api$decorations, _api$analytics4;
27
42
  var hoverDecoration = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
@@ -87,6 +102,66 @@ var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, rule
87
102
  type: 'separator',
88
103
  fullHeight: true
89
104
  }];
105
+ if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_lovability_dividers_m2')) {
106
+ items.push({
107
+ id: 'divider-add-text',
108
+ testId: 'divider-add-text',
109
+ type: 'button',
110
+ showTitle: true,
111
+ title: formatMessage(_rule.ruleMessages.addText),
112
+ ariaLabel: formatMessage(_rule.ruleMessages.addText),
113
+ icon: _fieldTextIcon.FieldTextIcon,
114
+ onClick: function onClick() {
115
+ return false;
116
+ }
117
+ });
118
+ items.push({
119
+ id: 'divider-align-text',
120
+ testId: 'divider-align-text',
121
+ type: 'dropdown',
122
+ title: formatMessage(_rule.ruleMessages.alignText),
123
+ icon: DividerAlignmentIcon,
124
+ showSelected: false,
125
+ options: [{
126
+ id: 'divider-align-left',
127
+ title: formatMessage(_alignment.alignmentMessages.alignLeft),
128
+ icon: /*#__PURE__*/_react.default.createElement(_alignTextLeftIcon.AlignTextLeftIcon, {
129
+ label: "",
130
+ size: "small"
131
+ }),
132
+ elemAfter: /*#__PURE__*/_react.default.createElement(_Shortcut.Shortcut, null, (0, _keymaps.tooltip)(_keymaps.alignLeft)),
133
+ selected: false,
134
+ onClick: function onClick() {
135
+ return false;
136
+ }
137
+ }, {
138
+ id: 'divider-align-center',
139
+ title: formatMessage(_alignment.alignmentMessages.alignCenter),
140
+ icon: /*#__PURE__*/_react.default.createElement(_alignTextCenterIcon.AlignTextCenterIcon, {
141
+ label: "",
142
+ size: "small"
143
+ }),
144
+ elemAfter: /*#__PURE__*/_react.default.createElement(_Shortcut.Shortcut, null, (0, _keymaps.tooltip)(_keymaps.alignCenter)),
145
+ // TODO: EDITOR-8349 - center align is the default until alignment is implemented
146
+ selected: true,
147
+ onClick: function onClick() {
148
+ return false;
149
+ }
150
+ }, {
151
+ id: 'divider-align-right',
152
+ title: formatMessage(_alignment.alignmentMessages.alignRight),
153
+ icon: /*#__PURE__*/_react.default.createElement(_alignTextRightIcon.AlignTextRightIcon, {
154
+ label: "",
155
+ size: "small"
156
+ }),
157
+ elemAfter: /*#__PURE__*/_react.default.createElement(_Shortcut.Shortcut, null, (0, _keymaps.tooltip)(_keymaps.alignRight)),
158
+ selected: false,
159
+ onClick: function onClick() {
160
+ return false;
161
+ }
162
+ }]
163
+ });
164
+ }
90
165
  var overflowMenuItems = [{
91
166
  type: 'overflow-dropdown',
92
167
  options: [_objectSpread({
@@ -1,13 +1,15 @@
1
- /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./DividerOptions.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useCallback } from 'react';
4
+ import React, { useCallback, useContext, useRef } from 'react';
5
5
  import { useIntl } from 'react-intl';
6
6
  import IconButton from '@atlaskit/button/icon/button';
7
7
  import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
8
+ import ReactEditorViewContext from '@atlaskit/editor-common/ui-react/ReactEditorViewContext';
8
9
  import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
9
10
  import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
10
11
  import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
12
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
11
13
  import { Box } from '@atlaskit/primitives/compiled/box';
12
14
  import { Text } from '@atlaskit/primitives/compiled/text';
13
15
  import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
@@ -23,6 +25,7 @@ const styles = {
23
25
  dividerOptionsButtonContainer: "_1rjc1b66"
24
26
  };
25
27
  const dividerOptionsButtonStyles = null;
28
+ const dividerOptionsButtonStylesOld = null;
26
29
  const SmallWeightIcon = iconProps => /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
27
30
  color: "var(--ds-icon-subtle, #505258)",
28
31
  label: iconProps.label
@@ -74,20 +77,24 @@ const styleOptionRows = [
74
77
  value: 'fade'
75
78
  }]];
76
79
  const DividerOptionButton = ({
80
+ autoFocus,
77
81
  icon,
78
82
  isSelected,
79
83
  label,
84
+ onKeyDownCapture,
80
85
  onSelect,
81
86
  value
82
87
  }) => {
83
88
  const handleClick = useCallback(() => onSelect === null || onSelect === void 0 ? void 0 : onSelect(value), [onSelect, value]);
84
89
  return /*#__PURE__*/React.createElement("div", {
85
- className: ax(["_2rko1mok _1reo15vq _18m915vq _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq"])
90
+ className: ax(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !isExperimentEnabled('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
86
91
  }, /*#__PURE__*/React.createElement(IconButton, {
92
+ autoFocus: autoFocus,
87
93
  icon: icon,
88
94
  isSelected: isSelected,
89
95
  label: label,
90
- onClick: handleClick
96
+ onClick: handleClick,
97
+ onKeyDownCapture: onKeyDownCapture
91
98
  }));
92
99
  };
93
100
  export const DividerOptions = ({
@@ -99,10 +106,51 @@ export const DividerOptions = ({
99
106
  const {
100
107
  formatMessage
101
108
  } = useIntl();
109
+ const {
110
+ popupsMountPoint
111
+ } = useContext(ReactEditorViewContext);
112
+ const containerRef = useRef(null);
113
+ const handleKeyDown = useCallback(event => {
114
+ var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
115
+ const buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
116
+ const index = buttons.indexOf(event.currentTarget);
117
+ if (index === -1) {
118
+ return;
119
+ }
120
+ const columns = weightOptions.length;
121
+ const row = Math.floor(index / columns);
122
+ const column = index % columns;
123
+ const rows = [weightOptions, ...styleOptionRows];
124
+ let nextIndex;
125
+ switch (event.key) {
126
+ case 'ArrowDown':
127
+ case 'ArrowUp':
128
+ {
129
+ const nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
130
+ nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
131
+ break;
132
+ }
133
+ case 'ArrowRight':
134
+ nextIndex = (index + 1) % buttons.length;
135
+ break;
136
+ case 'ArrowLeft':
137
+ nextIndex = (index - 1 + buttons.length) % buttons.length;
138
+ break;
139
+ default:
140
+ return;
141
+ }
142
+ event.preventDefault();
143
+ event.stopPropagation();
144
+ (_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 ? void 0 : _buttons$nextIndex.focus();
145
+ }, []);
102
146
  const selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
103
147
  const selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
148
+ const isPatchEnabled = isExperimentEnabled('platform_editor_lovability_dividers_patch_1');
104
149
  return /*#__PURE__*/React.createElement(Box, {
105
- xcss: styles.container
150
+ xcss: styles.container,
151
+ ref: isPatchEnabled ? containerRef : undefined,
152
+ role: isPatchEnabled ? 'group' : undefined,
153
+ "aria-label": isPatchEnabled ? formatMessage(messages.dividerOptions) : undefined
106
154
  }, /*#__PURE__*/React.createElement(Box, {
107
155
  xcss: styles.section
108
156
  }, /*#__PURE__*/React.createElement(Text, {
@@ -118,9 +166,14 @@ export const DividerOptions = ({
118
166
  value
119
167
  }) => /*#__PURE__*/React.createElement(DividerOptionButton, {
120
168
  key: value,
169
+ autoFocus:
170
+ // when there is no custom mount point, Dropdown sends ArrowDown
171
+ // on keyboard open so autofocusing is not required.
172
+ isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
121
173
  icon: icon,
122
174
  isSelected: selectedWeight === value,
123
175
  label: formatMessage(label),
176
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
124
177
  onSelect: onWeightChange,
125
178
  value: value
126
179
  }))))), /*#__PURE__*/React.createElement(Box, {
@@ -142,6 +195,7 @@ export const DividerOptions = ({
142
195
  icon: icon,
143
196
  isSelected: selectedStyle === value,
144
197
  label: formatMessage(label),
198
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
145
199
  onSelect: onStyleChange,
146
200
  value: value
147
201
  })))))));
@@ -1,17 +1,30 @@
1
1
  import React from 'react';
2
+ import { alignmentMessages } from '@atlaskit/editor-common/alignment';
3
+ import { AlignmentIconMap } from '@atlaskit/editor-common/alignment-icon-map';
2
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums';
5
+ import { alignLeft, alignCenter, alignRight, tooltip } from '@atlaskit/editor-common/keymaps';
3
6
  import commonMessages from '@atlaskit/editor-common/messages';
4
7
  import { ruleMessages } from '@atlaskit/editor-common/messages/rule';
8
+ import { Shortcut } from '@atlaskit/editor-common/Shortcut';
5
9
  import { hexToEditorTextPaletteColor } from '@atlaskit/editor-palette/text';
6
10
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
7
11
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles/constants';
12
+ import { AlignTextCenterIcon } from '@atlaskit/editor-toolbar/align-text-center-icon';
13
+ import { AlignTextLeftIcon } from '@atlaskit/editor-toolbar/align-text-left-icon';
14
+ import { AlignTextRightIcon } from '@atlaskit/editor-toolbar/align-text-right-icon';
15
+ import { FieldTextIcon } from '@atlaskit/editor-toolbar/field-text-icon';
8
16
  import CopyIcon from '@atlaskit/icon/core/copy';
9
17
  import CustomizeIcon from '@atlaskit/icon/core/customize';
10
18
  import DeleteIcon from '@atlaskit/icon/core/delete';
19
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
11
20
  import { removeHorizontalRule, updateHorizontalRuleColor, updateHorizontalRuleStyle, updateHorizontalRuleWeight } from '../pm-plugins/commands';
12
21
  import { dividerColorPalette } from './dividerColorPalette';
13
22
  import { dividerPaletteTooltipMessages } from './dividerColorPaletteMessages';
14
23
  import { DividerOptions } from './DividerOptions';
24
+ const DividerAlignmentIcon = () => /*#__PURE__*/React.createElement(AlignmentIconMap, {
25
+ alignment: "center",
26
+ size: "small"
27
+ });
15
28
  const getToolbarItems = (formatMessage, ruleNodeType, ruleAttrs, api) => {
16
29
  var _api$decorations, _api$analytics4;
17
30
  const hoverDecoration = api === null || api === void 0 ? void 0 : (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
@@ -70,6 +83,58 @@ const getToolbarItems = (formatMessage, ruleNodeType, ruleAttrs, api) => {
70
83
  type: 'separator',
71
84
  fullHeight: true
72
85
  }];
86
+ if (isExperimentEnabled('platform_editor_lovability_dividers_m2')) {
87
+ items.push({
88
+ id: 'divider-add-text',
89
+ testId: 'divider-add-text',
90
+ type: 'button',
91
+ showTitle: true,
92
+ title: formatMessage(ruleMessages.addText),
93
+ ariaLabel: formatMessage(ruleMessages.addText),
94
+ icon: FieldTextIcon,
95
+ onClick: () => false
96
+ });
97
+ items.push({
98
+ id: 'divider-align-text',
99
+ testId: 'divider-align-text',
100
+ type: 'dropdown',
101
+ title: formatMessage(ruleMessages.alignText),
102
+ icon: DividerAlignmentIcon,
103
+ showSelected: false,
104
+ options: [{
105
+ id: 'divider-align-left',
106
+ title: formatMessage(alignmentMessages.alignLeft),
107
+ icon: /*#__PURE__*/React.createElement(AlignTextLeftIcon, {
108
+ label: "",
109
+ size: "small"
110
+ }),
111
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignLeft)),
112
+ selected: false,
113
+ onClick: () => false
114
+ }, {
115
+ id: 'divider-align-center',
116
+ title: formatMessage(alignmentMessages.alignCenter),
117
+ icon: /*#__PURE__*/React.createElement(AlignTextCenterIcon, {
118
+ label: "",
119
+ size: "small"
120
+ }),
121
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignCenter)),
122
+ // TODO: EDITOR-8349 - center align is the default until alignment is implemented
123
+ selected: true,
124
+ onClick: () => false
125
+ }, {
126
+ id: 'divider-align-right',
127
+ title: formatMessage(alignmentMessages.alignRight),
128
+ icon: /*#__PURE__*/React.createElement(AlignTextRightIcon, {
129
+ label: "",
130
+ size: "small"
131
+ }),
132
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignRight)),
133
+ selected: false,
134
+ onClick: () => false
135
+ }]
136
+ });
137
+ }
73
138
  const overflowMenuItems = [{
74
139
  type: 'overflow-dropdown',
75
140
  options: [{
@@ -1,13 +1,15 @@
1
- /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.2 */
1
+ /* DividerOptions.tsx generated by @compiled/babel-plugin v3.0.4 */
2
2
  import "./DividerOptions.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useCallback } from 'react';
4
+ import React, { useCallback, useContext, useRef } from 'react';
5
5
  import { useIntl } from 'react-intl';
6
6
  import IconButton from '@atlaskit/button/icon/button';
7
7
  import { ruleMessages as messages } from '@atlaskit/editor-common/messages/rule';
8
+ import ReactEditorViewContext from '@atlaskit/editor-common/ui-react/ReactEditorViewContext';
8
9
  import StrokeWeightLargeIcon from '@atlaskit/icon/core/stroke-weight-large';
9
10
  import StrokeWeightMediumIcon from '@atlaskit/icon/core/stroke-weight-medium';
10
11
  import StrokeWeightSmallIcon from '@atlaskit/icon/core/stroke-weight-small';
12
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
11
13
  import { Box } from '@atlaskit/primitives/compiled/box';
12
14
  import { Text } from '@atlaskit/primitives/compiled/text';
13
15
  import { DEFAULT_DIVIDER_STYLE, DEFAULT_DIVIDER_WEIGHT } from './constants';
@@ -23,6 +25,7 @@ var styles = {
23
25
  dividerOptionsButtonContainer: "_1rjc1b66"
24
26
  };
25
27
  var dividerOptionsButtonStyles = null;
28
+ var dividerOptionsButtonStylesOld = null;
26
29
  var SmallWeightIcon = function SmallWeightIcon(iconProps) {
27
30
  return /*#__PURE__*/React.createElement(StrokeWeightSmallIcon, {
28
31
  color: "var(--ds-icon-subtle, #505258)",
@@ -80,21 +83,25 @@ var styleOptionRows = [
80
83
  value: 'fade'
81
84
  }]];
82
85
  var DividerOptionButton = function DividerOptionButton(_ref) {
83
- var icon = _ref.icon,
86
+ var autoFocus = _ref.autoFocus,
87
+ icon = _ref.icon,
84
88
  isSelected = _ref.isSelected,
85
89
  label = _ref.label,
90
+ onKeyDownCapture = _ref.onKeyDownCapture,
86
91
  onSelect = _ref.onSelect,
87
92
  value = _ref.value;
88
93
  var handleClick = useCallback(function () {
89
94
  return onSelect === null || onSelect === void 0 ? void 0 : onSelect(value);
90
95
  }, [onSelect, value]);
91
96
  return /*#__PURE__*/React.createElement("div", {
92
- className: ax(["_2rko1mok _1reo15vq _18m915vq _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq"])
97
+ className: ax(["_2rko1mok _16jlkb7n _1vy41mok _ug5l1h6o _r55q1osq", !isExperimentEnabled('platform_editor_lovability_dividers_patch_1') && "_1reo15vq _18m915vq"])
93
98
  }, /*#__PURE__*/React.createElement(IconButton, {
99
+ autoFocus: autoFocus,
94
100
  icon: icon,
95
101
  isSelected: isSelected,
96
102
  label: label,
97
- onClick: handleClick
103
+ onClick: handleClick,
104
+ onKeyDownCapture: onKeyDownCapture
98
105
  }));
99
106
  };
100
107
  export var DividerOptions = function DividerOptions(_ref2) {
@@ -104,10 +111,50 @@ export var DividerOptions = function DividerOptions(_ref2) {
104
111
  weight = _ref2.weight;
105
112
  var _useIntl = useIntl(),
106
113
  formatMessage = _useIntl.formatMessage;
114
+ var _useContext = useContext(ReactEditorViewContext),
115
+ popupsMountPoint = _useContext.popupsMountPoint;
116
+ var containerRef = useRef(null);
117
+ var handleKeyDown = useCallback(function (event) {
118
+ var _containerRef$current, _containerRef$current2, _buttons$nextIndex;
119
+ var buttons = Array.from((_containerRef$current = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.querySelectorAll('button')) !== null && _containerRef$current !== void 0 ? _containerRef$current : []);
120
+ var index = buttons.indexOf(event.currentTarget);
121
+ if (index === -1) {
122
+ return;
123
+ }
124
+ var columns = weightOptions.length;
125
+ var row = Math.floor(index / columns);
126
+ var column = index % columns;
127
+ var rows = [weightOptions].concat(styleOptionRows);
128
+ var nextIndex;
129
+ switch (event.key) {
130
+ case 'ArrowDown':
131
+ case 'ArrowUp':
132
+ {
133
+ var nextRow = (row + (event.key === 'ArrowDown' ? 1 : -1) + rows.length) % rows.length;
134
+ nextIndex = nextRow * columns + Math.min(column, rows[nextRow].length - 1);
135
+ break;
136
+ }
137
+ case 'ArrowRight':
138
+ nextIndex = (index + 1) % buttons.length;
139
+ break;
140
+ case 'ArrowLeft':
141
+ nextIndex = (index - 1 + buttons.length) % buttons.length;
142
+ break;
143
+ default:
144
+ return;
145
+ }
146
+ event.preventDefault();
147
+ event.stopPropagation();
148
+ (_buttons$nextIndex = buttons[nextIndex]) === null || _buttons$nextIndex === void 0 || _buttons$nextIndex.focus();
149
+ }, []);
107
150
  var selectedStyle = style !== null && style !== void 0 ? style : DEFAULT_DIVIDER_STYLE;
108
151
  var selectedWeight = weight !== null && weight !== void 0 ? weight : DEFAULT_DIVIDER_WEIGHT;
152
+ var isPatchEnabled = isExperimentEnabled('platform_editor_lovability_dividers_patch_1');
109
153
  return /*#__PURE__*/React.createElement(Box, {
110
- xcss: styles.container
154
+ xcss: styles.container,
155
+ ref: isPatchEnabled ? containerRef : undefined,
156
+ role: isPatchEnabled ? 'group' : undefined,
157
+ "aria-label": isPatchEnabled ? formatMessage(messages.dividerOptions) : undefined
111
158
  }, /*#__PURE__*/React.createElement(Box, {
112
159
  xcss: styles.section
113
160
  }, /*#__PURE__*/React.createElement(Text, {
@@ -123,9 +170,14 @@ export var DividerOptions = function DividerOptions(_ref2) {
123
170
  value = _ref3.value;
124
171
  return /*#__PURE__*/React.createElement(DividerOptionButton, {
125
172
  key: value,
173
+ autoFocus:
174
+ // when there is no custom mount point, Dropdown sends ArrowDown
175
+ // on keyboard open so autofocusing is not required.
176
+ isPatchEnabled && Boolean(popupsMountPoint) && value === weightOptions[0].value,
126
177
  icon: icon,
127
178
  isSelected: selectedWeight === value,
128
179
  label: formatMessage(label),
180
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
129
181
  onSelect: onWeightChange,
130
182
  value: value
131
183
  });
@@ -149,6 +201,7 @@ export var DividerOptions = function DividerOptions(_ref2) {
149
201
  icon: icon,
150
202
  isSelected: selectedStyle === value,
151
203
  label: formatMessage(label),
204
+ onKeyDownCapture: isPatchEnabled ? handleKeyDown : undefined,
152
205
  onSelect: onStyleChange,
153
206
  value: value
154
207
  });
@@ -2,19 +2,34 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import React from 'react';
5
+ import { alignmentMessages } from '@atlaskit/editor-common/alignment';
6
+ import { AlignmentIconMap } from '@atlaskit/editor-common/alignment-icon-map';
5
7
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics/types/enums';
8
+ import { alignLeft, alignCenter, alignRight, tooltip } from '@atlaskit/editor-common/keymaps';
6
9
  import commonMessages from '@atlaskit/editor-common/messages';
7
10
  import { ruleMessages } from '@atlaskit/editor-common/messages/rule';
11
+ import { Shortcut } from '@atlaskit/editor-common/Shortcut';
8
12
  import { hexToEditorTextPaletteColor } from '@atlaskit/editor-palette/text';
9
13
  import { findDomRefAtPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
10
14
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles/constants';
15
+ import { AlignTextCenterIcon } from '@atlaskit/editor-toolbar/align-text-center-icon';
16
+ import { AlignTextLeftIcon } from '@atlaskit/editor-toolbar/align-text-left-icon';
17
+ import { AlignTextRightIcon } from '@atlaskit/editor-toolbar/align-text-right-icon';
18
+ import { FieldTextIcon } from '@atlaskit/editor-toolbar/field-text-icon';
11
19
  import CopyIcon from '@atlaskit/icon/core/copy';
12
20
  import CustomizeIcon from '@atlaskit/icon/core/customize';
13
21
  import DeleteIcon from '@atlaskit/icon/core/delete';
22
+ import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
14
23
  import { removeHorizontalRule, updateHorizontalRuleColor, updateHorizontalRuleStyle, updateHorizontalRuleWeight } from '../pm-plugins/commands';
15
24
  import { dividerColorPalette } from './dividerColorPalette';
16
25
  import { dividerPaletteTooltipMessages } from './dividerColorPaletteMessages';
17
26
  import { DividerOptions } from './DividerOptions';
27
+ var DividerAlignmentIcon = function DividerAlignmentIcon() {
28
+ return /*#__PURE__*/React.createElement(AlignmentIconMap, {
29
+ alignment: "center",
30
+ size: "small"
31
+ });
32
+ };
18
33
  var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, ruleAttrs, api) {
19
34
  var _api$decorations, _api$analytics4;
20
35
  var hoverDecoration = api === null || api === void 0 || (_api$decorations = api.decorations) === null || _api$decorations === void 0 ? void 0 : _api$decorations.actions.hoverDecoration;
@@ -80,6 +95,66 @@ var getToolbarItems = function getToolbarItems(formatMessage, ruleNodeType, rule
80
95
  type: 'separator',
81
96
  fullHeight: true
82
97
  }];
98
+ if (isExperimentEnabled('platform_editor_lovability_dividers_m2')) {
99
+ items.push({
100
+ id: 'divider-add-text',
101
+ testId: 'divider-add-text',
102
+ type: 'button',
103
+ showTitle: true,
104
+ title: formatMessage(ruleMessages.addText),
105
+ ariaLabel: formatMessage(ruleMessages.addText),
106
+ icon: FieldTextIcon,
107
+ onClick: function onClick() {
108
+ return false;
109
+ }
110
+ });
111
+ items.push({
112
+ id: 'divider-align-text',
113
+ testId: 'divider-align-text',
114
+ type: 'dropdown',
115
+ title: formatMessage(ruleMessages.alignText),
116
+ icon: DividerAlignmentIcon,
117
+ showSelected: false,
118
+ options: [{
119
+ id: 'divider-align-left',
120
+ title: formatMessage(alignmentMessages.alignLeft),
121
+ icon: /*#__PURE__*/React.createElement(AlignTextLeftIcon, {
122
+ label: "",
123
+ size: "small"
124
+ }),
125
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignLeft)),
126
+ selected: false,
127
+ onClick: function onClick() {
128
+ return false;
129
+ }
130
+ }, {
131
+ id: 'divider-align-center',
132
+ title: formatMessage(alignmentMessages.alignCenter),
133
+ icon: /*#__PURE__*/React.createElement(AlignTextCenterIcon, {
134
+ label: "",
135
+ size: "small"
136
+ }),
137
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignCenter)),
138
+ // TODO: EDITOR-8349 - center align is the default until alignment is implemented
139
+ selected: true,
140
+ onClick: function onClick() {
141
+ return false;
142
+ }
143
+ }, {
144
+ id: 'divider-align-right',
145
+ title: formatMessage(alignmentMessages.alignRight),
146
+ icon: /*#__PURE__*/React.createElement(AlignTextRightIcon, {
147
+ label: "",
148
+ size: "small"
149
+ }),
150
+ elemAfter: /*#__PURE__*/React.createElement(Shortcut, null, tooltip(alignRight)),
151
+ selected: false,
152
+ onClick: function onClick() {
153
+ return false;
154
+ }
155
+ }]
156
+ });
157
+ }
83
158
  var overflowMenuItems = [{
84
159
  type: 'overflow-dropdown',
85
160
  options: [_objectSpread({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-rule",
3
- "version": "30.0.2",
3
+ "version": "30.1.0",
4
4
  "description": "Rule plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "atlaskit:src": "src/index.ts",
21
21
  "dependencies": {
22
22
  "@atlaskit/adf-schema": "^57.7.0",
23
- "@atlaskit/button": "^25.7.0",
23
+ "@atlaskit/button": "^25.8.0",
24
24
  "@atlaskit/css": "^1.1.0",
25
25
  "@atlaskit/docs": "^12.3.0",
26
26
  "@atlaskit/editor-palette": "^3.5.0",
@@ -28,24 +28,26 @@
28
28
  "@atlaskit/editor-plugin-floating-toolbar": "^32.0.0",
29
29
  "@atlaskit/editor-plugin-ui-control-registry": "^24.0.0",
30
30
  "@atlaskit/editor-prosemirror": "^9.0.0",
31
- "@atlaskit/editor-shared-styles": "^5.0.0",
32
- "@atlaskit/icon": "^38.0.0",
31
+ "@atlaskit/editor-shared-styles": "^5.1.0",
32
+ "@atlaskit/editor-toolbar": "^2.11.0",
33
+ "@atlaskit/icon": "^38.1.0",
33
34
  "@atlaskit/platform-feature-experiments": "^0.3.0",
34
35
  "@atlaskit/platform-feature-flags": "^2.2.0",
35
- "@atlaskit/primitives": "^22.6.0",
36
+ "@atlaskit/primitives": "^22.7.0",
36
37
  "@atlaskit/prosemirror-input-rules": "^4.1.0",
37
- "@atlaskit/tokens": "^20.9.0",
38
+ "@atlaskit/tokens": "^20.12.0",
38
39
  "@babel/runtime": "^7.0.0",
39
40
  "@compiled/react": "^1.0.2",
40
41
  "bind-event-listener": "^3.0.0",
41
42
  "react-intl": "^7.0.0"
42
43
  },
43
44
  "peerDependencies": {
44
- "@atlaskit/editor-common": "^134.4.0",
45
+ "@atlaskit/editor-common": "^134.19.0",
45
46
  "react": "^18.2.0 || ^19.2.0",
46
47
  "react-dom": "^18.2.0 || ^19.2.0"
47
48
  },
48
49
  "devDependencies": {
50
+ "@atlaskit/editor-common": "^134.19.0",
49
51
  "@testing-library/react": "^16.3.0",
50
52
  "react": "^19.2.0",
51
53
  "react-dom": "^19.2.0"