@atlaskit/editor-plugin-highlight 1.8.0 → 1.9.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.
Files changed (33) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/plugin.js +11 -3
  3. package/dist/cjs/ui/FloatingToolbarHighlightColor.js +98 -0
  4. package/dist/cjs/ui/PrimaryToolbarHighlightColor.js +107 -0
  5. package/dist/cjs/ui/ToolbarHighlightColor.js +3 -1
  6. package/dist/cjs/ui/shared/PaletteDropdown.js +61 -0
  7. package/dist/cjs/ui/shared/useDropdownEvents.js +55 -0
  8. package/dist/es2019/plugin.js +11 -3
  9. package/dist/es2019/ui/FloatingToolbarHighlightColor.js +89 -0
  10. package/dist/es2019/ui/PrimaryToolbarHighlightColor.js +104 -0
  11. package/dist/es2019/ui/ToolbarHighlightColor.js +3 -1
  12. package/dist/es2019/ui/shared/PaletteDropdown.js +57 -0
  13. package/dist/es2019/ui/shared/useDropdownEvents.js +46 -0
  14. package/dist/esm/plugin.js +11 -3
  15. package/dist/esm/ui/FloatingToolbarHighlightColor.js +90 -0
  16. package/dist/esm/ui/PrimaryToolbarHighlightColor.js +99 -0
  17. package/dist/esm/ui/ToolbarHighlightColor.js +3 -1
  18. package/dist/esm/ui/shared/PaletteDropdown.js +54 -0
  19. package/dist/esm/ui/shared/useDropdownEvents.js +48 -0
  20. package/dist/types/ui/FloatingToolbarHighlightColor.d.ts +24 -0
  21. package/dist/types/ui/PrimaryToolbarHighlightColor.d.ts +24 -0
  22. package/dist/types/ui/shared/PaletteDropdown.d.ts +14 -0
  23. package/dist/types/ui/shared/useDropdownEvents.d.ts +19 -0
  24. package/dist/types-ts4.5/ui/FloatingToolbarHighlightColor.d.ts +24 -0
  25. package/dist/types-ts4.5/ui/PrimaryToolbarHighlightColor.d.ts +24 -0
  26. package/dist/types-ts4.5/ui/shared/PaletteDropdown.d.ts +14 -0
  27. package/dist/types-ts4.5/ui/shared/useDropdownEvents.d.ts +19 -0
  28. package/package.json +46 -17
  29. /package/dist/cjs/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  30. /package/dist/es2019/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  31. /package/dist/esm/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  32. /package/dist/types/ui/{EditorHighlightIcon.d.ts → shared/EditorHighlightIcon.d.ts} +0 -0
  33. /package/dist/types-ts4.5/ui/{EditorHighlightIcon.d.ts → shared/EditorHighlightIcon.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-highlight
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#112947](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112947)
8
+ [`ec865ff1780db`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ec865ff1780db) -
9
+ [ux] [ED-23760] Refactor Editor Highlight toolbar button to facilitate reuse and add a (currently
10
+ unused) Floating toolbar button
11
+
12
+ ## 1.8.1
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 1.8.0
4
19
 
5
20
  ### Minor Changes
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.highlightPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
10
  var _commands = require("./commands");
10
11
  var _keymap = require("./pm-plugins/keymap");
11
12
  var _main = require("./pm-plugins/main");
13
+ var _PrimaryToolbarHighlightColor = require("./ui/PrimaryToolbarHighlightColor");
12
14
  var _ToolbarHighlightColor = require("./ui/ToolbarHighlightColor");
13
15
  var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
14
16
  var _api$analytics;
@@ -20,15 +22,21 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
20
22
  popupsScrollableElement = _ref2.popupsScrollableElement,
21
23
  disabled = _ref2.disabled,
22
24
  isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
23
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
24
25
  editorView = _ref2.editorView;
25
- return /*#__PURE__*/_react.default.createElement(_ToolbarHighlightColor.ToolbarHighlightColorWithIntl, {
26
+ return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.refactor-highlight-toolbar_mo0pj') ? /*#__PURE__*/_react.default.createElement(_PrimaryToolbarHighlightColor.PrimaryToolbarHighlightColorWithIntl, {
27
+ popupsMountPoint: popupsMountPoint,
28
+ popupsBoundariesElement: popupsBoundariesElement,
29
+ popupsScrollableElement: popupsScrollableElement,
30
+ disabled: disabled,
31
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
32
+ pluginInjectionApi: api,
33
+ editorView: editorView
34
+ }) : /*#__PURE__*/_react.default.createElement(_ToolbarHighlightColor.ToolbarHighlightColorWithIntl, {
26
35
  popupsMountPoint: popupsMountPoint,
27
36
  popupsBoundariesElement: popupsBoundariesElement,
28
37
  popupsScrollableElement: popupsScrollableElement,
29
38
  disabled: disabled,
30
39
  isToolbarReducedSpacing: isToolbarReducedSpacing,
31
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
32
40
  pluginInjectionApi: api,
33
41
  editorView: editorView
34
42
  });
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.FloatingToolbarHighlightColorWithIntl = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _react2 = require("@emotion/react");
11
+ var _reactIntlNext = require("react-intl-next");
12
+ var _hooks = require("@atlaskit/editor-common/hooks");
13
+ var _messages = require("@atlaskit/editor-common/messages");
14
+ var _styles = require("@atlaskit/editor-common/styles");
15
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
+ var _editorPalette = require("@atlaskit/editor-palette");
17
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
18
+ var _primitives = require("@atlaskit/primitives");
19
+ var _EditorHighlightIcon = require("./shared/EditorHighlightIcon");
20
+ var _PaletteDropdown = require("./shared/PaletteDropdown");
21
+ var _useDropdownEvents2 = require("./shared/useDropdownEvents");
22
+ /** @jsx jsx */
23
+
24
+ var FloatingToolbarHighlightColor = function FloatingToolbarHighlightColor(_ref) {
25
+ var popupsMountPoint = _ref.popupsMountPoint,
26
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
27
+ popupsScrollableElement = _ref.popupsScrollableElement,
28
+ isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
29
+ disabled = _ref.disabled,
30
+ pluginInjectionApi = _ref.pluginInjectionApi,
31
+ formatMessage = _ref.intl.formatMessage;
32
+ var toolbarItemRef = (0, _react.useRef)(null);
33
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['highlight']),
34
+ highlightState = _useSharedPluginState.highlightState;
35
+ var _useState = (0, _react.useState)(false),
36
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
+ isDropdownOpen = _useState2[0],
38
+ setIsDropdownOpen = _useState2[1];
39
+ var _useDropdownEvents = (0, _useDropdownEvents2.useDropdownEvents)({
40
+ toolbarItemRef: toolbarItemRef,
41
+ setIsDropdownOpen: setIsDropdownOpen,
42
+ isDropdownOpen: isDropdownOpen,
43
+ pluginInjectionApi: pluginInjectionApi
44
+ }),
45
+ handleClick = _useDropdownEvents.handleClick,
46
+ handleKeyDown = _useDropdownEvents.handleKeyDown,
47
+ handleClickOutside = _useDropdownEvents.handleClickOutside,
48
+ handleEscapeKeydown = _useDropdownEvents.handleEscapeKeydown,
49
+ handleColorChange = _useDropdownEvents.handleColorChange,
50
+ isOpenedByKeyboard = _useDropdownEvents.isOpenedByKeyboard;
51
+
52
+ // Don't render the toolbar option while the plugin is initialising
53
+ if (!highlightState) {
54
+ return null;
55
+ }
56
+ var toolbarButtonLabel = formatMessage(_messages.highlightMessages.highlight);
57
+
58
+ // Get the design token for the active color (if it exists) to modify the toolbar
59
+ // icon, but show the nice rainbow if none is selected
60
+ var activeColorToken = highlightState.activeColor === null ? null : (0, _editorPalette.hexToEditorTextBackgroundPaletteColor)(highlightState.activeColor);
61
+ return (0, _react2.jsx)(_primitives.Flex, {
62
+ alignItems: "center"
63
+ }, (0, _react2.jsx)(_PaletteDropdown.PaletteDropdown, {
64
+ popupsMountPoint: popupsMountPoint,
65
+ popupsBoundariesElement: popupsBoundariesElement,
66
+ popupsScrollableElement: popupsScrollableElement,
67
+ isOpen: isDropdownOpen && !highlightState.disabled,
68
+ activeColor: highlightState.activeColor,
69
+ trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
70
+ buttonId: _uiMenu.TOOLBAR_BUTTON.BACKGROUND_COLOR,
71
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
72
+ disabled: disabled || highlightState.disabled,
73
+ selected: isDropdownOpen,
74
+ "aria-label": toolbarButtonLabel,
75
+ "aria-expanded": isDropdownOpen,
76
+ "aria-haspopup": true,
77
+ title: toolbarButtonLabel,
78
+ onClick: handleClick,
79
+ onKeyDown: handleKeyDown,
80
+ ref: toolbarItemRef,
81
+ iconBefore: (0, _react2.jsx)(_primitives.Flex, null, (0, _react2.jsx)(_EditorHighlightIcon.EditorHighlightIcon, {
82
+ selectedColor: activeColorToken,
83
+ disabled: highlightState.disabled
84
+ }), (0, _react2.jsx)("span", {
85
+ css: _styles.expandIconWrapperStyle
86
+ }, (0, _react2.jsx)(_chevronDown.default, {
87
+ label: ""
88
+ })))
89
+ }),
90
+ onColorChange: function onColorChange(color) {
91
+ return handleColorChange(color);
92
+ },
93
+ isOpenedByKeyboard: isOpenedByKeyboard,
94
+ handleClickOutside: handleClickOutside,
95
+ handleEscapeKeydown: handleEscapeKeydown
96
+ }));
97
+ };
98
+ var FloatingToolbarHighlightColorWithIntl = exports.FloatingToolbarHighlightColorWithIntl = (0, _reactIntlNext.injectIntl)(FloatingToolbarHighlightColor);
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PrimaryToolbarHighlightColorWithIntl = void 0;
8
+ var _react = require("react");
9
+ var _react2 = require("@emotion/react");
10
+ var _reactIntlNext = require("react-intl-next");
11
+ var _hooks = require("@atlaskit/editor-common/hooks");
12
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
13
+ var _messages = require("@atlaskit/editor-common/messages");
14
+ var _styles = require("@atlaskit/editor-common/styles");
15
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
+ var _editorPalette = require("@atlaskit/editor-palette");
17
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
18
+ var _primitives = require("@atlaskit/primitives");
19
+ var _commands = require("../commands");
20
+ var _EditorHighlightIcon = require("./shared/EditorHighlightIcon");
21
+ var _PaletteDropdown = require("./shared/PaletteDropdown");
22
+ var _useDropdownEvents2 = require("./shared/useDropdownEvents");
23
+ /** @jsx jsx */
24
+
25
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
+
27
+ var PrimaryToolbarHighlightColor = function PrimaryToolbarHighlightColor(_ref) {
28
+ var popupsMountPoint = _ref.popupsMountPoint,
29
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
30
+ popupsScrollableElement = _ref.popupsScrollableElement,
31
+ isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
32
+ disabled = _ref.disabled,
33
+ pluginInjectionApi = _ref.pluginInjectionApi,
34
+ formatMessage = _ref.intl.formatMessage,
35
+ editorView = _ref.editorView;
36
+ var toolbarItemRef = (0, _react.useRef)(null);
37
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['highlight']),
38
+ highlightState = _useSharedPluginState.highlightState;
39
+ var setDropdownOpen = function setDropdownOpen(isOpen) {
40
+ if (!(highlightState !== null && highlightState !== void 0 && highlightState.disabled)) {
41
+ var state = editorView.state,
42
+ dispatch = editorView.dispatch;
43
+ (0, _commands.setPalette)(pluginInjectionApi, isOpen)(state, dispatch);
44
+ }
45
+ };
46
+ var isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
47
+ var _useDropdownEvents = (0, _useDropdownEvents2.useDropdownEvents)({
48
+ toolbarItemRef: toolbarItemRef,
49
+ setIsDropdownOpen: setDropdownOpen,
50
+ isDropdownOpen: isDropdownOpen,
51
+ pluginInjectionApi: pluginInjectionApi
52
+ }),
53
+ handleClick = _useDropdownEvents.handleClick,
54
+ handleKeyDown = _useDropdownEvents.handleKeyDown,
55
+ handleClickOutside = _useDropdownEvents.handleClickOutside,
56
+ handleEscapeKeydown = _useDropdownEvents.handleEscapeKeydown,
57
+ handleColorChange = _useDropdownEvents.handleColorChange,
58
+ isOpenedByKeyboard = _useDropdownEvents.isOpenedByKeyboard;
59
+
60
+ // Don't render the toolbar option while the plugin is initialising
61
+ if (!highlightState) {
62
+ return null;
63
+ }
64
+ var toolbarButtonLabel = formatMessage(_messages.highlightMessages.highlight);
65
+
66
+ // Get the design token for the active color (if it exists) to modify the toolbar
67
+ // icon, but show the nice rainbow if none is selected
68
+ var activeColorToken = highlightState.activeColor === null ? null : (0, _editorPalette.hexToEditorTextBackgroundPaletteColor)(highlightState.activeColor);
69
+ return (0, _react2.jsx)(_primitives.Flex, {
70
+ alignItems: "center"
71
+ }, (0, _react2.jsx)(_PaletteDropdown.PaletteDropdown, {
72
+ popupsMountPoint: popupsMountPoint,
73
+ popupsBoundariesElement: popupsBoundariesElement,
74
+ popupsScrollableElement: popupsScrollableElement,
75
+ isOpen: isDropdownOpen && !highlightState.disabled,
76
+ activeColor: highlightState.activeColor,
77
+ trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
78
+ buttonId: _uiMenu.TOOLBAR_BUTTON.BACKGROUND_COLOR,
79
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
80
+ disabled: disabled || highlightState.disabled,
81
+ selected: isDropdownOpen,
82
+ "aria-label": (0, _keymaps.tooltip)(_keymaps.toggleHighlightPalette, toolbarButtonLabel),
83
+ "aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleHighlightPalette),
84
+ "aria-expanded": isDropdownOpen,
85
+ "aria-haspopup": true,
86
+ title: (0, _keymaps.tooltip)(_keymaps.toggleHighlightPalette, toolbarButtonLabel),
87
+ onClick: handleClick,
88
+ onKeyDown: handleKeyDown,
89
+ ref: toolbarItemRef,
90
+ iconBefore: (0, _react2.jsx)(_primitives.Flex, null, (0, _react2.jsx)(_EditorHighlightIcon.EditorHighlightIcon, {
91
+ selectedColor: activeColorToken,
92
+ disabled: highlightState.disabled
93
+ }), (0, _react2.jsx)("span", {
94
+ css: _styles.expandIconWrapperStyle
95
+ }, (0, _react2.jsx)(_chevronDown.default, {
96
+ label: ""
97
+ })))
98
+ }),
99
+ onColorChange: function onColorChange(color) {
100
+ return handleColorChange(color);
101
+ },
102
+ isOpenedByKeyboard: isOpenedByKeyboard,
103
+ handleClickOutside: handleClickOutside,
104
+ handleEscapeKeydown: handleEscapeKeydown
105
+ }));
106
+ };
107
+ var PrimaryToolbarHighlightColorWithIntl = exports.PrimaryToolbarHighlightColorWithIntl = (0, _reactIntlNext.injectIntl)(PrimaryToolbarHighlightColor);
@@ -22,11 +22,13 @@ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-
22
22
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
23
23
  var _primitives = require("@atlaskit/primitives");
24
24
  var _commands = require("../commands");
25
- var _EditorHighlightIcon = require("./EditorHighlightIcon");
25
+ var _EditorHighlightIcon = require("./shared/EditorHighlightIcon");
26
26
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
27
27
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
28
28
  /** @jsx jsx */
29
29
 
30
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
31
+
30
32
  var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
31
33
  var popupsMountPoint = _ref.popupsMountPoint,
32
34
  popupsBoundariesElement = _ref.popupsBoundariesElement,
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PaletteDropdown = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _uiColor = require("@atlaskit/editor-common/ui-color");
10
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
11
+ var _editorPalette = require("@atlaskit/editor-palette");
12
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
13
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
14
+ var PaletteDropdown = exports.PaletteDropdown = function PaletteDropdown(props) {
15
+ var popupsMountPoint = props.popupsMountPoint,
16
+ popupsBoundariesElement = props.popupsBoundariesElement,
17
+ popupsScrollableElement = props.popupsScrollableElement,
18
+ isOpen = props.isOpen,
19
+ activeColor = props.activeColor,
20
+ trigger = props.trigger,
21
+ onColorChange = props.onColorChange,
22
+ isOpenedByKeyboard = props.isOpenedByKeyboard,
23
+ handleClickOutside = props.handleClickOutside,
24
+ handleEscapeKeydown = props.handleEscapeKeydown;
25
+
26
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
27
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
28
+ var fitWidth = 242;
29
+ var palette = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.dynamic-palette-borders') ? _uiColor.highlightColorPaletteWithTokenBorders : _uiColor.highlightColorPalette;
30
+ var _getSelectedRowAndCol = (0, _uiColor.getSelectedRowAndColumnFromPalette)(palette, activeColor),
31
+ selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
32
+ selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
33
+ return /*#__PURE__*/_react.default.createElement(_uiMenu.DropdownContainer, {
34
+ mountTo: popupsMountPoint,
35
+ boundariesElement: popupsBoundariesElement,
36
+ scrollableElement: popupsScrollableElement,
37
+ isOpen: isOpen,
38
+ handleClickOutside: handleClickOutside,
39
+ handleEscapeKeydown: handleEscapeKeydown,
40
+ zIndex: _editorSharedStyles.akEditorMenuZIndex,
41
+ fitWidth: fitWidth,
42
+ closeOnTab: true,
43
+ arrowKeyNavigationProviderOptions: {
44
+ type: _uiMenu.ArrowKeyNavigationType.COLOR,
45
+ selectedRowIndex: selectedRowIndex,
46
+ selectedColumnIndex: selectedColumnIndex,
47
+ isOpenedByKeyboard: isOpenedByKeyboard,
48
+ isPopupPositioned: true
49
+ },
50
+ trigger: trigger
51
+ }, /*#__PURE__*/_react.default.createElement("div", {
52
+ "data-testid": "highlight-color-palette"
53
+ }, /*#__PURE__*/_react.default.createElement(_uiColor.ColorPalette, {
54
+ onClick: onColorChange,
55
+ selectedColor: activeColor,
56
+ paletteOptions: {
57
+ palette: palette,
58
+ hexToPaletteColor: _editorPalette.hexToEditorTextBackgroundPaletteColor
59
+ }
60
+ })));
61
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useDropdownEvents = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _react = require("react");
10
+ var _commands = require("../../commands");
11
+ var useDropdownEvents = exports.useDropdownEvents = function useDropdownEvents(args) {
12
+ var toolbarItemRef = args.toolbarItemRef,
13
+ setIsDropdownOpen = args.setIsDropdownOpen,
14
+ isDropdownOpen = args.isDropdownOpen,
15
+ pluginInjectionApi = args.pluginInjectionApi;
16
+ var _useState = (0, _react.useState)(false),
17
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
18
+ isOpenedByKeyboard = _useState2[0],
19
+ setIsOpenedByKeyboard = _useState2[1];
20
+ return {
21
+ handleClick: function handleClick() {
22
+ setIsOpenedByKeyboard(false);
23
+ setIsDropdownOpen(!isDropdownOpen);
24
+ },
25
+ handleKeyDown: function handleKeyDown(event) {
26
+ if (event.key === 'Enter' || event.key === ' ') {
27
+ event.preventDefault();
28
+ setIsOpenedByKeyboard(true);
29
+ setIsDropdownOpen(!isDropdownOpen);
30
+ }
31
+ },
32
+ handleClickOutside: function handleClickOutside() {
33
+ if (isDropdownOpen) {
34
+ setIsDropdownOpen(false);
35
+ setIsOpenedByKeyboard(false);
36
+ }
37
+ },
38
+ handleEscapeKeydown: function handleEscapeKeydown() {
39
+ if (isDropdownOpen) {
40
+ var _toolbarItemRef$curre;
41
+ setIsDropdownOpen(false);
42
+ setIsOpenedByKeyboard(false);
43
+ toolbarItemRef === null || toolbarItemRef === void 0 || (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 || _toolbarItemRef$curre.focus();
44
+ }
45
+ },
46
+ handleColorChange: function handleColorChange(color) {
47
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
48
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.core) === null || _pluginInjectionApi$c === void 0 || _pluginInjectionApi$c.actions.execute((0, _commands.changeColor)(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)({
49
+ color: color
50
+ }));
51
+ setIsDropdownOpen(false);
52
+ },
53
+ isOpenedByKeyboard: isOpenedByKeyboard
54
+ };
55
+ };
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
2
3
  import { changeColor } from './commands';
3
4
  import { keymapPlugin } from './pm-plugins/keymap';
4
5
  import { createPlugin, highlightPluginKey } from './pm-plugins/main';
6
+ import { PrimaryToolbarHighlightColorWithIntl as PrimaryToolbarHighlightColor } from './ui/PrimaryToolbarHighlightColor';
5
7
  import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
6
8
  export const highlightPlugin = ({
7
9
  api
@@ -14,15 +16,21 @@ export const highlightPlugin = ({
14
16
  popupsScrollableElement,
15
17
  disabled,
16
18
  isToolbarReducedSpacing,
17
- dispatchAnalyticsEvent,
18
19
  editorView
19
- }) => /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
20
+ }) => getBooleanFF('platform.editor.refactor-highlight-toolbar_mo0pj') ? /*#__PURE__*/React.createElement(PrimaryToolbarHighlightColor, {
21
+ popupsMountPoint: popupsMountPoint,
22
+ popupsBoundariesElement: popupsBoundariesElement,
23
+ popupsScrollableElement: popupsScrollableElement,
24
+ disabled: disabled,
25
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
26
+ pluginInjectionApi: api,
27
+ editorView: editorView
28
+ }) : /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
20
29
  popupsMountPoint: popupsMountPoint,
21
30
  popupsBoundariesElement: popupsBoundariesElement,
22
31
  popupsScrollableElement: popupsScrollableElement,
23
32
  disabled: disabled,
24
33
  isToolbarReducedSpacing: isToolbarReducedSpacing,
25
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
26
34
  pluginInjectionApi: api,
27
35
  editorView: editorView
28
36
  });
@@ -0,0 +1,89 @@
1
+ /** @jsx jsx */
2
+ import { useRef, useState } from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
+ import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
7
+ import { expandIconWrapperStyle } from '@atlaskit/editor-common/styles';
8
+ import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
9
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
10
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
11
+ import { Flex } from '@atlaskit/primitives';
12
+ import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
13
+ import { PaletteDropdown } from './shared/PaletteDropdown';
14
+ import { useDropdownEvents } from './shared/useDropdownEvents';
15
+ const FloatingToolbarHighlightColor = ({
16
+ popupsMountPoint,
17
+ popupsBoundariesElement,
18
+ popupsScrollableElement,
19
+ isToolbarReducedSpacing,
20
+ disabled,
21
+ pluginInjectionApi,
22
+ intl: {
23
+ formatMessage
24
+ }
25
+ }) => {
26
+ const toolbarItemRef = useRef(null);
27
+ const {
28
+ highlightState
29
+ } = useSharedPluginState(pluginInjectionApi, ['highlight']);
30
+ const [isDropdownOpen, setIsDropdownOpen] = useState(false);
31
+ const {
32
+ handleClick,
33
+ handleKeyDown,
34
+ handleClickOutside,
35
+ handleEscapeKeydown,
36
+ handleColorChange,
37
+ isOpenedByKeyboard
38
+ } = useDropdownEvents({
39
+ toolbarItemRef,
40
+ setIsDropdownOpen,
41
+ isDropdownOpen,
42
+ pluginInjectionApi
43
+ });
44
+
45
+ // Don't render the toolbar option while the plugin is initialising
46
+ if (!highlightState) {
47
+ return null;
48
+ }
49
+ const toolbarButtonLabel = formatMessage(messages.highlight);
50
+
51
+ // Get the design token for the active color (if it exists) to modify the toolbar
52
+ // icon, but show the nice rainbow if none is selected
53
+ const activeColorToken = highlightState.activeColor === null ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
54
+ return jsx(Flex, {
55
+ alignItems: "center"
56
+ }, jsx(PaletteDropdown, {
57
+ popupsMountPoint: popupsMountPoint,
58
+ popupsBoundariesElement: popupsBoundariesElement,
59
+ popupsScrollableElement: popupsScrollableElement,
60
+ isOpen: isDropdownOpen && !highlightState.disabled,
61
+ activeColor: highlightState.activeColor,
62
+ trigger: jsx(ToolbarButton, {
63
+ buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
64
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
65
+ disabled: disabled || highlightState.disabled,
66
+ selected: isDropdownOpen,
67
+ "aria-label": toolbarButtonLabel,
68
+ "aria-expanded": isDropdownOpen,
69
+ "aria-haspopup": true,
70
+ title: toolbarButtonLabel,
71
+ onClick: handleClick,
72
+ onKeyDown: handleKeyDown,
73
+ ref: toolbarItemRef,
74
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
75
+ selectedColor: activeColorToken,
76
+ disabled: highlightState.disabled
77
+ }), jsx("span", {
78
+ css: expandIconWrapperStyle
79
+ }, jsx(ExpandIcon, {
80
+ label: ""
81
+ })))
82
+ }),
83
+ onColorChange: color => handleColorChange(color),
84
+ isOpenedByKeyboard: isOpenedByKeyboard,
85
+ handleClickOutside: handleClickOutside,
86
+ handleEscapeKeydown: handleEscapeKeydown
87
+ }));
88
+ };
89
+ export const FloatingToolbarHighlightColorWithIntl = injectIntl(FloatingToolbarHighlightColor);
@@ -0,0 +1,104 @@
1
+ /** @jsx jsx */
2
+ import { useRef } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
5
+ import { jsx } from '@emotion/react';
6
+ import { injectIntl } from 'react-intl-next';
7
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
+ import { getAriaKeyshortcuts, toggleHighlightPalette, tooltip } from '@atlaskit/editor-common/keymaps';
9
+ import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
10
+ import { expandIconWrapperStyle } from '@atlaskit/editor-common/styles';
11
+ import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
12
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
13
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
+ import { Flex } from '@atlaskit/primitives';
15
+ import { setPalette } from '../commands';
16
+ import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
17
+ import { PaletteDropdown } from './shared/PaletteDropdown';
18
+ import { useDropdownEvents } from './shared/useDropdownEvents';
19
+ const PrimaryToolbarHighlightColor = ({
20
+ popupsMountPoint,
21
+ popupsBoundariesElement,
22
+ popupsScrollableElement,
23
+ isToolbarReducedSpacing,
24
+ disabled,
25
+ pluginInjectionApi,
26
+ intl: {
27
+ formatMessage
28
+ },
29
+ editorView
30
+ }) => {
31
+ const toolbarItemRef = useRef(null);
32
+ const {
33
+ highlightState
34
+ } = useSharedPluginState(pluginInjectionApi, ['highlight']);
35
+ const setDropdownOpen = isOpen => {
36
+ if (!(highlightState !== null && highlightState !== void 0 && highlightState.disabled)) {
37
+ const {
38
+ state,
39
+ dispatch
40
+ } = editorView;
41
+ setPalette(pluginInjectionApi, isOpen)(state, dispatch);
42
+ }
43
+ };
44
+ const isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
45
+ const {
46
+ handleClick,
47
+ handleKeyDown,
48
+ handleClickOutside,
49
+ handleEscapeKeydown,
50
+ handleColorChange,
51
+ isOpenedByKeyboard
52
+ } = useDropdownEvents({
53
+ toolbarItemRef,
54
+ setIsDropdownOpen: setDropdownOpen,
55
+ isDropdownOpen,
56
+ pluginInjectionApi
57
+ });
58
+
59
+ // Don't render the toolbar option while the plugin is initialising
60
+ if (!highlightState) {
61
+ return null;
62
+ }
63
+ const toolbarButtonLabel = formatMessage(messages.highlight);
64
+
65
+ // Get the design token for the active color (if it exists) to modify the toolbar
66
+ // icon, but show the nice rainbow if none is selected
67
+ const activeColorToken = highlightState.activeColor === null ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
68
+ return jsx(Flex, {
69
+ alignItems: "center"
70
+ }, jsx(PaletteDropdown, {
71
+ popupsMountPoint: popupsMountPoint,
72
+ popupsBoundariesElement: popupsBoundariesElement,
73
+ popupsScrollableElement: popupsScrollableElement,
74
+ isOpen: isDropdownOpen && !highlightState.disabled,
75
+ activeColor: highlightState.activeColor,
76
+ trigger: jsx(ToolbarButton, {
77
+ buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
78
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
79
+ disabled: disabled || highlightState.disabled,
80
+ selected: isDropdownOpen,
81
+ "aria-label": tooltip(toggleHighlightPalette, toolbarButtonLabel),
82
+ "aria-keyshortcuts": getAriaKeyshortcuts(toggleHighlightPalette),
83
+ "aria-expanded": isDropdownOpen,
84
+ "aria-haspopup": true,
85
+ title: tooltip(toggleHighlightPalette, toolbarButtonLabel),
86
+ onClick: handleClick,
87
+ onKeyDown: handleKeyDown,
88
+ ref: toolbarItemRef,
89
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
90
+ selectedColor: activeColorToken,
91
+ disabled: highlightState.disabled
92
+ }), jsx("span", {
93
+ css: expandIconWrapperStyle
94
+ }, jsx(ExpandIcon, {
95
+ label: ""
96
+ })))
97
+ }),
98
+ onColorChange: color => handleColorChange(color),
99
+ isOpenedByKeyboard: isOpenedByKeyboard,
100
+ handleClickOutside: handleClickOutside,
101
+ handleEscapeKeydown: handleEscapeKeydown
102
+ }));
103
+ };
104
+ export const PrimaryToolbarHighlightColorWithIntl = injectIntl(PrimaryToolbarHighlightColor);
@@ -1,5 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import React, { useRef, useState } from 'react';
3
+
4
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
3
5
  import { jsx } from '@emotion/react';
4
6
  import { injectIntl } from 'react-intl-next';
5
7
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
@@ -14,7 +16,7 @@ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
16
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
17
  import { Flex } from '@atlaskit/primitives';
16
18
  import { changeColor, setPalette } from '../commands';
17
- import { EditorHighlightIcon } from './EditorHighlightIcon';
19
+ import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
18
20
  const ToolbarHighlightColor = ({
19
21
  popupsMountPoint,
20
22
  popupsBoundariesElement,