@atlaskit/editor-plugin-floating-toolbar 1.1.1 → 1.2.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,15 @@
1
1
  # @atlaskit/editor-plugin-floating-toolbar
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#70153](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70153) [`3a34e7545f18`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3a34e7545f18) - ECA11Y-36: Flaoting toolbar group buttons into radiogroup buttons structure
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 1.1.1
4
14
 
5
15
  ### Patch Changes
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = void 0;
9
+ exports.groupItems = groupItems;
9
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
11
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -25,6 +26,7 @@ var _uiColor = require("@atlaskit/editor-common/ui-color");
25
26
  var _uiMenu = require("@atlaskit/editor-common/ui-menu");
26
27
  var _editorPalette = require("@atlaskit/editor-palette");
27
28
  var _commands = require("@atlaskit/editor-plugin-table/commands");
29
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
28
30
  var _forceFocus = require("../pm-plugins/force-focus");
29
31
  var _commands2 = require("../pm-plugins/toolbar-data/commands");
30
32
  var _Dropdown = _interopRequireDefault(require("./Dropdown"));
@@ -40,6 +42,35 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
40
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
43
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
42
44
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
45
+ function groupItems(items) {
46
+ var groupItems = items.reduce(function (accumulator, item, i) {
47
+ var finalOutput = accumulator.finalOutput,
48
+ buttonGroup = accumulator.buttonGroup;
49
+ if (item.type === 'button') {
50
+ var notLastItem = i < items.length - 1;
51
+ var nextItemIsButton = items[i + 1] && items[i + 1].type === 'button';
52
+ var wasPreviousButton = items[i - 1] && items[i - 1].type === 'button';
53
+ var isRadioButton = notLastItem && nextItemIsButton || wasPreviousButton;
54
+ if (isRadioButton) {
55
+ item.isRadioButton = true;
56
+ buttonGroup.push(item);
57
+ if (!nextItemIsButton && wasPreviousButton) {
58
+ finalOutput.push(buttonGroup);
59
+ accumulator.buttonGroup = [];
60
+ }
61
+ } else {
62
+ finalOutput.push(item);
63
+ }
64
+ } else {
65
+ finalOutput.push(item);
66
+ }
67
+ return accumulator;
68
+ }, {
69
+ buttonGroup: [],
70
+ finalOutput: []
71
+ });
72
+ return groupItems.finalOutput;
73
+ }
43
74
  var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
44
75
  var items = _ref.items,
45
76
  dispatchCommand = _ref.dispatchCommand,
@@ -56,9 +87,7 @@ var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
56
87
  mountRef = _ref.mountRef,
57
88
  api = _ref.api;
58
89
  var emojiAndColourPickerMountPoint = scrollable ? popupsMountPoint || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.fabric-editor-popup-scroll-parent')) || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.ak-editor-content-area')) || undefined : popupsMountPoint;
59
- return (0, _react2.jsx)(_buttonGroup.default, null, items.filter(function (item) {
60
- return !item.hidden;
61
- }).map(function (item, idx) {
90
+ var renderItem = function renderItem(item, idx) {
62
91
  var _api$contextPanel, _api$extension;
63
92
  switch (item.type) {
64
93
  case 'button':
@@ -102,7 +131,8 @@ var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
102
131
  testId: item.testId,
103
132
  hideTooltipOnClick: item.hideTooltipOnClick,
104
133
  ariaHasPopup: item.ariaHasPopup,
105
- tabIndex: item.tabIndex
134
+ tabIndex: item.tabIndex,
135
+ isRadioButton: item.isRadioButton
106
136
  }, item.showTitle && item.title);
107
137
  case 'input':
108
138
  return (0, _react2.jsx)(_Input.default, {
@@ -229,7 +259,32 @@ var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
229
259
  key: idx
230
260
  });
231
261
  }
232
- }));
262
+ };
263
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.editor.a11y-floating-toolbar-markup_vexmo')) {
264
+ var groupedItems = groupItems(items.filter(function (item) {
265
+ return !item.hidden;
266
+ }));
267
+ return (0, _react2.jsx)(_buttonGroup.default, null, groupedItems.map(function (element, index) {
268
+ var isGroup = Array.isArray(element);
269
+ if (isGroup) {
270
+ return (0, _react2.jsx)("div", {
271
+ key: index,
272
+ css: buttonGroupStyles,
273
+ role: "radiogroup"
274
+ }, element.map(function (item, idx) {
275
+ return renderItem(item, idx);
276
+ }));
277
+ } else {
278
+ return renderItem(element, index);
279
+ }
280
+ }));
281
+ } else {
282
+ return (0, _react2.jsx)(_buttonGroup.default, null, items.filter(function (item) {
283
+ return !item.hidden;
284
+ }).map(function (item, index) {
285
+ return renderItem(item, index);
286
+ }));
287
+ }
233
288
  }, function (prevProps, nextProps) {
234
289
  if (!nextProps.node) {
235
290
  return false;
@@ -238,6 +293,10 @@ var ToolbarItems = /*#__PURE__*/_react.default.memo(function (_ref) {
238
293
  // otherwise it causes an issue where multiple popups stays open
239
294
  return !(prevProps.node.type !== nextProps.node.type || prevProps.node.attrs.localId !== nextProps.node.attrs.localId || !(0, _floatingToolbar.areSameItems)(prevProps.items, nextProps.items) || !prevProps.mounted !== !nextProps.mounted);
240
295
  });
296
+ var buttonGroupStyles = (0, _react2.css)({
297
+ display: 'flex',
298
+ gap: "var(--ds-space-050, 4px)"
299
+ });
241
300
 
242
301
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
243
302
  var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstElementIsSelect) {
@@ -11,6 +11,7 @@ import { backgroundPaletteTooltipMessages } from '@atlaskit/editor-common/ui-col
11
11
  import { ColorPickerButton, ToolbarArrowKeyNavigationProvider } from '@atlaskit/editor-common/ui-menu';
12
12
  import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
13
13
  import { clearHoverSelection } from '@atlaskit/editor-plugin-table/commands';
14
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
14
15
  import { checkShouldForceFocusAndApply, forceFocusSelector } from '../pm-plugins/force-focus';
15
16
  import { showConfirmDialog } from '../pm-plugins/toolbar-data/commands';
16
17
  import Dropdown from './Dropdown';
@@ -20,6 +21,37 @@ import Input from './Input';
20
21
  import { ScrollButtons } from './ScrollButtons';
21
22
  import Select from './Select';
22
23
  import Separator from './Separator';
24
+ export function groupItems(items) {
25
+ const groupItems = items.reduce((accumulator, item, i) => {
26
+ let {
27
+ finalOutput,
28
+ buttonGroup
29
+ } = accumulator;
30
+ if (item.type === 'button') {
31
+ const notLastItem = i < items.length - 1;
32
+ const nextItemIsButton = items[i + 1] && items[i + 1].type === 'button';
33
+ const wasPreviousButton = items[i - 1] && items[i - 1].type === 'button';
34
+ const isRadioButton = notLastItem && nextItemIsButton || wasPreviousButton;
35
+ if (isRadioButton) {
36
+ item.isRadioButton = true;
37
+ buttonGroup.push(item);
38
+ if (!nextItemIsButton && wasPreviousButton) {
39
+ finalOutput.push(buttonGroup);
40
+ accumulator.buttonGroup = [];
41
+ }
42
+ } else {
43
+ finalOutput.push(item);
44
+ }
45
+ } else {
46
+ finalOutput.push(item);
47
+ }
48
+ return accumulator;
49
+ }, {
50
+ buttonGroup: [],
51
+ finalOutput: []
52
+ });
53
+ return groupItems.finalOutput;
54
+ }
23
55
  const ToolbarItems = /*#__PURE__*/React.memo(({
24
56
  items,
25
57
  dispatchCommand,
@@ -37,7 +69,7 @@ const ToolbarItems = /*#__PURE__*/React.memo(({
37
69
  api
38
70
  }) => {
39
71
  const emojiAndColourPickerMountPoint = scrollable ? popupsMountPoint || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.fabric-editor-popup-scroll-parent')) || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.ak-editor-content-area')) || undefined : popupsMountPoint;
40
- return jsx(ButtonGroup, null, items.filter(item => !item.hidden).map((item, idx) => {
72
+ const renderItem = (item, idx) => {
41
73
  var _api$contextPanel, _api$extension;
42
74
  switch (item.type) {
43
75
  case 'button':
@@ -73,7 +105,8 @@ const ToolbarItems = /*#__PURE__*/React.memo(({
73
105
  testId: item.testId,
74
106
  hideTooltipOnClick: item.hideTooltipOnClick,
75
107
  ariaHasPopup: item.ariaHasPopup,
76
- tabIndex: item.tabIndex
108
+ tabIndex: item.tabIndex,
109
+ isRadioButton: item.isRadioButton
77
110
  }, item.showTitle && item.title);
78
111
  case 'input':
79
112
  return jsx(Input, {
@@ -192,7 +225,28 @@ const ToolbarItems = /*#__PURE__*/React.memo(({
192
225
  key: idx
193
226
  });
194
227
  }
195
- }));
228
+ };
229
+ if (getBooleanFF('platform.editor.a11y-floating-toolbar-markup_vexmo')) {
230
+ const groupedItems = groupItems(items.filter(item => !item.hidden));
231
+ return jsx(ButtonGroup, null, groupedItems.map((element, index) => {
232
+ const isGroup = Array.isArray(element);
233
+ if (isGroup) {
234
+ return jsx("div", {
235
+ key: index,
236
+ css: buttonGroupStyles,
237
+ role: "radiogroup"
238
+ }, element.map((item, idx) => {
239
+ return renderItem(item, idx);
240
+ }));
241
+ } else {
242
+ return renderItem(element, index);
243
+ }
244
+ }));
245
+ } else {
246
+ return jsx(ButtonGroup, null, items.filter(item => !item.hidden).map((item, index) => {
247
+ return renderItem(item, index);
248
+ }));
249
+ }
196
250
  }, (prevProps, nextProps) => {
197
251
  if (!nextProps.node) {
198
252
  return false;
@@ -201,6 +255,10 @@ const ToolbarItems = /*#__PURE__*/React.memo(({
201
255
  // otherwise it causes an issue where multiple popups stays open
202
256
  return !(prevProps.node.type !== nextProps.node.type || prevProps.node.attrs.localId !== nextProps.node.attrs.localId || !areSameItems(prevProps.items, nextProps.items) || !prevProps.mounted !== !nextProps.mounted);
203
257
  });
258
+ const buttonGroupStyles = css({
259
+ display: 'flex',
260
+ gap: "var(--ds-space-050, 4px)"
261
+ });
204
262
 
205
263
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
206
264
  const toolbarContainer = (scrollable, hasSelect, firstElementIsSelect) => css`
@@ -21,6 +21,7 @@ import { backgroundPaletteTooltipMessages } from '@atlaskit/editor-common/ui-col
21
21
  import { ColorPickerButton, ToolbarArrowKeyNavigationProvider } from '@atlaskit/editor-common/ui-menu';
22
22
  import { hexToEditorBackgroundPaletteColor } from '@atlaskit/editor-palette';
23
23
  import { clearHoverSelection } from '@atlaskit/editor-plugin-table/commands';
24
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
24
25
  import { checkShouldForceFocusAndApply, forceFocusSelector } from '../pm-plugins/force-focus';
25
26
  import { showConfirmDialog } from '../pm-plugins/toolbar-data/commands';
26
27
  import Dropdown from './Dropdown';
@@ -30,6 +31,35 @@ import Input from './Input';
30
31
  import { ScrollButtons } from './ScrollButtons';
31
32
  import Select from './Select';
32
33
  import Separator from './Separator';
34
+ export function groupItems(items) {
35
+ var groupItems = items.reduce(function (accumulator, item, i) {
36
+ var finalOutput = accumulator.finalOutput,
37
+ buttonGroup = accumulator.buttonGroup;
38
+ if (item.type === 'button') {
39
+ var notLastItem = i < items.length - 1;
40
+ var nextItemIsButton = items[i + 1] && items[i + 1].type === 'button';
41
+ var wasPreviousButton = items[i - 1] && items[i - 1].type === 'button';
42
+ var isRadioButton = notLastItem && nextItemIsButton || wasPreviousButton;
43
+ if (isRadioButton) {
44
+ item.isRadioButton = true;
45
+ buttonGroup.push(item);
46
+ if (!nextItemIsButton && wasPreviousButton) {
47
+ finalOutput.push(buttonGroup);
48
+ accumulator.buttonGroup = [];
49
+ }
50
+ } else {
51
+ finalOutput.push(item);
52
+ }
53
+ } else {
54
+ finalOutput.push(item);
55
+ }
56
+ return accumulator;
57
+ }, {
58
+ buttonGroup: [],
59
+ finalOutput: []
60
+ });
61
+ return groupItems.finalOutput;
62
+ }
33
63
  var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
34
64
  var items = _ref.items,
35
65
  dispatchCommand = _ref.dispatchCommand,
@@ -46,9 +76,7 @@ var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
46
76
  mountRef = _ref.mountRef,
47
77
  api = _ref.api;
48
78
  var emojiAndColourPickerMountPoint = scrollable ? popupsMountPoint || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.fabric-editor-popup-scroll-parent')) || (editorView === null || editorView === void 0 ? void 0 : editorView.dom.closest('.ak-editor-content-area')) || undefined : popupsMountPoint;
49
- return jsx(ButtonGroup, null, items.filter(function (item) {
50
- return !item.hidden;
51
- }).map(function (item, idx) {
79
+ var renderItem = function renderItem(item, idx) {
52
80
  var _api$contextPanel, _api$extension;
53
81
  switch (item.type) {
54
82
  case 'button':
@@ -92,7 +120,8 @@ var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
92
120
  testId: item.testId,
93
121
  hideTooltipOnClick: item.hideTooltipOnClick,
94
122
  ariaHasPopup: item.ariaHasPopup,
95
- tabIndex: item.tabIndex
123
+ tabIndex: item.tabIndex,
124
+ isRadioButton: item.isRadioButton
96
125
  }, item.showTitle && item.title);
97
126
  case 'input':
98
127
  return jsx(Input, {
@@ -219,7 +248,32 @@ var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
219
248
  key: idx
220
249
  });
221
250
  }
222
- }));
251
+ };
252
+ if (getBooleanFF('platform.editor.a11y-floating-toolbar-markup_vexmo')) {
253
+ var groupedItems = groupItems(items.filter(function (item) {
254
+ return !item.hidden;
255
+ }));
256
+ return jsx(ButtonGroup, null, groupedItems.map(function (element, index) {
257
+ var isGroup = Array.isArray(element);
258
+ if (isGroup) {
259
+ return jsx("div", {
260
+ key: index,
261
+ css: buttonGroupStyles,
262
+ role: "radiogroup"
263
+ }, element.map(function (item, idx) {
264
+ return renderItem(item, idx);
265
+ }));
266
+ } else {
267
+ return renderItem(element, index);
268
+ }
269
+ }));
270
+ } else {
271
+ return jsx(ButtonGroup, null, items.filter(function (item) {
272
+ return !item.hidden;
273
+ }).map(function (item, index) {
274
+ return renderItem(item, index);
275
+ }));
276
+ }
223
277
  }, function (prevProps, nextProps) {
224
278
  if (!nextProps.node) {
225
279
  return false;
@@ -228,6 +282,10 @@ var ToolbarItems = /*#__PURE__*/React.memo(function (_ref) {
228
282
  // otherwise it causes an issue where multiple popups stays open
229
283
  return !(prevProps.node.type !== nextProps.node.type || prevProps.node.attrs.localId !== nextProps.node.attrs.localId || !areSameItems(prevProps.items, nextProps.items) || !prevProps.mounted !== !nextProps.mounted);
230
284
  });
285
+ var buttonGroupStyles = css({
286
+ display: 'flex',
287
+ gap: "var(--ds-space-050, 4px)"
288
+ });
231
289
 
232
290
  // eslint-disable-next-line @atlaskit/design-system/consistent-css-prop-usage
233
291
  var toolbarContainer = function toolbarContainer(scrollable, hasSelect, firstElementIsSelect) {
@@ -34,6 +34,8 @@ export interface Props {
34
34
  ]> | undefined;
35
35
  mediaAssistiveMessage?: string;
36
36
  }
37
+ type GroupedItems = (Item | Item[])[];
38
+ export declare function groupItems(items: Item[]): GroupedItems;
37
39
  export interface State {
38
40
  scrollDisabled: boolean;
39
41
  mounted: boolean;
@@ -34,6 +34,8 @@ export interface Props {
34
34
  ]> | undefined;
35
35
  mediaAssistiveMessage?: string;
36
36
  }
37
+ type GroupedItems = (Item | Item[])[];
38
+ export declare function groupItems(items: Item[]): GroupedItems;
37
39
  export interface State {
38
40
  scrollDisabled: boolean;
39
41
  mounted: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-floating-toolbar",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Floating toolbar plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,7 +27,7 @@
27
27
  "@atlaskit/adf-utils": "^19.0.0",
28
28
  "@atlaskit/button": "^17.4.0",
29
29
  "@atlaskit/checkbox": "^13.0.0",
30
- "@atlaskit/editor-common": "^78.0.0",
30
+ "@atlaskit/editor-common": "^78.4.0",
31
31
  "@atlaskit/editor-palette": "1.5.2",
32
32
  "@atlaskit/editor-plugin-context-panel": "^1.0.0",
33
33
  "@atlaskit/editor-plugin-copy-button": "^1.0.0",
@@ -38,12 +38,13 @@
38
38
  "@atlaskit/editor-plugin-table": "^7.3.0",
39
39
  "@atlaskit/editor-prosemirror": "3.0.0",
40
40
  "@atlaskit/emoji": "^67.6.0",
41
- "@atlaskit/icon": "^22.0.0",
41
+ "@atlaskit/icon": "^22.1.0",
42
42
  "@atlaskit/menu": "^2.1.0",
43
43
  "@atlaskit/modal-dialog": "^12.10.0",
44
+ "@atlaskit/platform-feature-flags": "^0.2.5",
44
45
  "@atlaskit/select": "^17.1.0",
45
46
  "@atlaskit/theme": "^12.6.0",
46
- "@atlaskit/tokens": "^1.37.0",
47
+ "@atlaskit/tokens": "^1.38.0",
47
48
  "@atlaskit/tooltip": "^18.1.0",
48
49
  "@babel/runtime": "^7.0.0",
49
50
  "@emotion/react": "^11.7.1",
@@ -106,5 +107,10 @@
106
107
  ]
107
108
  }
108
109
  },
109
- "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0"
110
+ "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0",
111
+ "platform-feature-flags": {
112
+ "platform.editor.a11y-floating-toolbar-markup_vexmo": {
113
+ "type": "boolean"
114
+ }
115
+ }
110
116
  }