@atlaskit/editor-plugin-highlight 1.8.1 → 1.10.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 (35) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/plugin.js +36 -4
  3. package/dist/cjs/ui/FloatingToolbarHighlightColor.js +92 -0
  4. package/dist/cjs/ui/PrimaryToolbarHighlightColor.js +107 -0
  5. package/dist/cjs/ui/ToolbarHighlightColor.js +1 -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 +34 -4
  9. package/dist/es2019/ui/FloatingToolbarHighlightColor.js +83 -0
  10. package/dist/es2019/ui/PrimaryToolbarHighlightColor.js +104 -0
  11. package/dist/es2019/ui/ToolbarHighlightColor.js +1 -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 +36 -4
  15. package/dist/esm/ui/FloatingToolbarHighlightColor.js +84 -0
  16. package/dist/esm/ui/PrimaryToolbarHighlightColor.js +99 -0
  17. package/dist/esm/ui/ToolbarHighlightColor.js +1 -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/plugin.d.ts +4 -0
  21. package/dist/types/ui/FloatingToolbarHighlightColor.d.ts +14 -0
  22. package/dist/types/ui/PrimaryToolbarHighlightColor.d.ts +24 -0
  23. package/dist/types/ui/shared/PaletteDropdown.d.ts +14 -0
  24. package/dist/types/ui/shared/useDropdownEvents.d.ts +19 -0
  25. package/dist/types-ts4.5/plugin.d.ts +4 -0
  26. package/dist/types-ts4.5/ui/FloatingToolbarHighlightColor.d.ts +14 -0
  27. package/dist/types-ts4.5/ui/PrimaryToolbarHighlightColor.d.ts +24 -0
  28. package/dist/types-ts4.5/ui/shared/PaletteDropdown.d.ts +14 -0
  29. package/dist/types-ts4.5/ui/shared/useDropdownEvents.d.ts +19 -0
  30. package/package.json +13 -7
  31. /package/dist/cjs/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  32. /package/dist/es2019/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  33. /package/dist/esm/ui/{EditorHighlightIcon.js → shared/EditorHighlightIcon.js} +0 -0
  34. /package/dist/types/ui/{EditorHighlightIcon.d.ts → shared/EditorHighlightIcon.d.ts} +0 -0
  35. /package/dist/types-ts4.5/ui/{EditorHighlightIcon.d.ts → shared/EditorHighlightIcon.d.ts} +0 -0
@@ -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);
@@ -16,7 +16,7 @@ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
16
16
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
17
  import { Flex } from '@atlaskit/primitives';
18
18
  import { changeColor, setPalette } from '../commands';
19
- import { EditorHighlightIcon } from './EditorHighlightIcon';
19
+ import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
20
20
  const ToolbarHighlightColor = ({
21
21
  popupsMountPoint,
22
22
  popupsBoundariesElement,
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette, highlightColorPaletteWithTokenBorders } from '@atlaskit/editor-common/ui-color';
3
+ import { ArrowKeyNavigationType, DropdownContainer as Dropdown } from '@atlaskit/editor-common/ui-menu';
4
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
5
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ export const PaletteDropdown = props => {
8
+ const {
9
+ popupsMountPoint,
10
+ popupsBoundariesElement,
11
+ popupsScrollableElement,
12
+ isOpen,
13
+ activeColor,
14
+ trigger,
15
+ onColorChange,
16
+ isOpenedByKeyboard,
17
+ handleClickOutside,
18
+ handleEscapeKeydown
19
+ } = props;
20
+
21
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
22
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
23
+ const fitWidth = 242;
24
+ const palette = getBooleanFF('platform.editor.dynamic-palette-borders') ? highlightColorPaletteWithTokenBorders : highlightColorPalette;
25
+ const {
26
+ selectedRowIndex,
27
+ selectedColumnIndex
28
+ } = getSelectedRowAndColumnFromPalette(palette, activeColor);
29
+ return /*#__PURE__*/React.createElement(Dropdown, {
30
+ mountTo: popupsMountPoint,
31
+ boundariesElement: popupsBoundariesElement,
32
+ scrollableElement: popupsScrollableElement,
33
+ isOpen: isOpen,
34
+ handleClickOutside: handleClickOutside,
35
+ handleEscapeKeydown: handleEscapeKeydown,
36
+ zIndex: akEditorMenuZIndex,
37
+ fitWidth: fitWidth,
38
+ closeOnTab: true,
39
+ arrowKeyNavigationProviderOptions: {
40
+ type: ArrowKeyNavigationType.COLOR,
41
+ selectedRowIndex,
42
+ selectedColumnIndex,
43
+ isOpenedByKeyboard,
44
+ isPopupPositioned: true
45
+ },
46
+ trigger: trigger
47
+ }, /*#__PURE__*/React.createElement("div", {
48
+ "data-testid": "highlight-color-palette"
49
+ }, /*#__PURE__*/React.createElement(ColorPalette, {
50
+ onClick: onColorChange,
51
+ selectedColor: activeColor,
52
+ paletteOptions: {
53
+ palette,
54
+ hexToPaletteColor: hexToEditorTextBackgroundPaletteColor
55
+ }
56
+ })));
57
+ };
@@ -0,0 +1,46 @@
1
+ import { useState } from 'react';
2
+ import { changeColor } from '../../commands';
3
+ export const useDropdownEvents = args => {
4
+ const {
5
+ toolbarItemRef,
6
+ setIsDropdownOpen,
7
+ isDropdownOpen,
8
+ pluginInjectionApi
9
+ } = args;
10
+ const [isOpenedByKeyboard, setIsOpenedByKeyboard] = useState(false);
11
+ return {
12
+ handleClick: () => {
13
+ setIsOpenedByKeyboard(false);
14
+ setIsDropdownOpen(!isDropdownOpen);
15
+ },
16
+ handleKeyDown: event => {
17
+ if (event.key === 'Enter' || event.key === ' ') {
18
+ event.preventDefault();
19
+ setIsOpenedByKeyboard(true);
20
+ setIsDropdownOpen(!isDropdownOpen);
21
+ }
22
+ },
23
+ handleClickOutside: () => {
24
+ if (isDropdownOpen) {
25
+ setIsDropdownOpen(false);
26
+ setIsOpenedByKeyboard(false);
27
+ }
28
+ },
29
+ handleEscapeKeydown: () => {
30
+ if (isDropdownOpen) {
31
+ var _toolbarItemRef$curre;
32
+ setIsDropdownOpen(false);
33
+ setIsOpenedByKeyboard(false);
34
+ toolbarItemRef === null || toolbarItemRef === void 0 ? void 0 : (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 ? void 0 : _toolbarItemRef$curre.focus();
35
+ }
36
+ },
37
+ handleColorChange: color => {
38
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
39
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c = pluginInjectionApi.core) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions.execute(changeColor(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)({
40
+ color
41
+ }));
42
+ setIsDropdownOpen(false);
43
+ },
44
+ isOpenedByKeyboard
45
+ };
46
+ };
@@ -1,11 +1,15 @@
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 { FloatingToolbarHighlightColorWithIntl as FloatingToolbarHighlightColor } from './ui/FloatingToolbarHighlightColor';
7
+ import { PrimaryToolbarHighlightColorWithIntl as PrimaryToolbarHighlightColor } from './ui/PrimaryToolbarHighlightColor';
5
8
  import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
6
9
  export var highlightPlugin = function highlightPlugin(_ref) {
7
10
  var _api$analytics;
8
- var api = _ref.api;
11
+ var api = _ref.api,
12
+ options = _ref.config;
9
13
  var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
10
14
  var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
11
15
  var popupsMountPoint = _ref2.popupsMountPoint,
@@ -13,15 +17,21 @@ export var highlightPlugin = function highlightPlugin(_ref) {
13
17
  popupsScrollableElement = _ref2.popupsScrollableElement,
14
18
  disabled = _ref2.disabled,
15
19
  isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
16
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
17
20
  editorView = _ref2.editorView;
18
- return /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
21
+ return getBooleanFF('platform.editor.refactor-highlight-toolbar_mo0pj') ? /*#__PURE__*/React.createElement(PrimaryToolbarHighlightColor, {
22
+ popupsMountPoint: popupsMountPoint,
23
+ popupsBoundariesElement: popupsBoundariesElement,
24
+ popupsScrollableElement: popupsScrollableElement,
25
+ disabled: disabled,
26
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
27
+ pluginInjectionApi: api,
28
+ editorView: editorView
29
+ }) : /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
19
30
  popupsMountPoint: popupsMountPoint,
20
31
  popupsBoundariesElement: popupsBoundariesElement,
21
32
  popupsScrollableElement: popupsScrollableElement,
22
33
  disabled: disabled,
23
34
  isToolbarReducedSpacing: isToolbarReducedSpacing,
24
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
25
35
  pluginInjectionApi: api,
26
36
  editorView: editorView
27
37
  });
@@ -61,6 +71,28 @@ export var highlightPlugin = function highlightPlugin(_ref) {
61
71
  component: primaryToolbarComponent
62
72
  }));
63
73
  },
74
+ pluginsOptions: {
75
+ selectionToolbar: function selectionToolbar() {
76
+ if (!(options !== null && options !== void 0 && options.textHighlightingFloatingToolbarExperiment) || !getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd')) {
77
+ return;
78
+ }
79
+ var toolbarCustom = {
80
+ type: 'custom',
81
+ render: function render(_view, _idx, dispatchAnalyticsEvent) {
82
+ return /*#__PURE__*/React.createElement(FloatingToolbarHighlightColor, {
83
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
84
+ pluginInjectionApi: api
85
+ });
86
+ },
87
+ fallback: []
88
+ };
89
+ return {
90
+ rank: -9,
91
+ isToolbarAbove: true,
92
+ items: [toolbarCustom]
93
+ };
94
+ }
95
+ },
64
96
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
65
97
  };
66
98
  };
@@ -0,0 +1,84 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /** @jsx jsx */
3
+ import { useRef, useState } from 'react';
4
+
5
+ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
6
+ import { jsx } from '@emotion/react';
7
+ import { injectIntl } from 'react-intl-next';
8
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
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 { EditorHighlightIcon } from './shared/EditorHighlightIcon';
16
+ import { PaletteDropdown } from './shared/PaletteDropdown';
17
+ import { useDropdownEvents } from './shared/useDropdownEvents';
18
+ var FloatingToolbarHighlightColor = function FloatingToolbarHighlightColor(_ref) {
19
+ var pluginInjectionApi = _ref.pluginInjectionApi,
20
+ formatMessage = _ref.intl.formatMessage;
21
+ var toolbarItemRef = useRef(null);
22
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['highlight']),
23
+ highlightState = _useSharedPluginState.highlightState;
24
+ var _useState = useState(false),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ isDropdownOpen = _useState2[0],
27
+ setIsDropdownOpen = _useState2[1];
28
+ var _useDropdownEvents = useDropdownEvents({
29
+ toolbarItemRef: toolbarItemRef,
30
+ setIsDropdownOpen: setIsDropdownOpen,
31
+ isDropdownOpen: isDropdownOpen,
32
+ pluginInjectionApi: pluginInjectionApi
33
+ }),
34
+ handleClick = _useDropdownEvents.handleClick,
35
+ handleKeyDown = _useDropdownEvents.handleKeyDown,
36
+ handleClickOutside = _useDropdownEvents.handleClickOutside,
37
+ handleEscapeKeydown = _useDropdownEvents.handleEscapeKeydown,
38
+ handleColorChange = _useDropdownEvents.handleColorChange,
39
+ isOpenedByKeyboard = _useDropdownEvents.isOpenedByKeyboard;
40
+
41
+ // Don't render the toolbar option while the plugin is initialising
42
+ if (!highlightState) {
43
+ return null;
44
+ }
45
+ var toolbarButtonLabel = formatMessage(messages.highlight);
46
+
47
+ // Get the design token for the active color (if it exists) to modify the toolbar
48
+ // icon, but show the nice rainbow if none is selected
49
+ var activeColorToken = highlightState.activeColor === null ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
50
+ return jsx(Flex, {
51
+ alignItems: "center"
52
+ }, jsx(PaletteDropdown, {
53
+ isOpen: isDropdownOpen && !highlightState.disabled,
54
+ activeColor: highlightState.activeColor,
55
+ trigger: jsx(ToolbarButton, {
56
+ buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
57
+ spacing: 'default',
58
+ disabled: highlightState.disabled,
59
+ selected: isDropdownOpen,
60
+ "aria-label": toolbarButtonLabel,
61
+ "aria-expanded": isDropdownOpen,
62
+ "aria-haspopup": true,
63
+ title: toolbarButtonLabel,
64
+ onClick: handleClick,
65
+ onKeyDown: handleKeyDown,
66
+ ref: toolbarItemRef,
67
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
68
+ selectedColor: activeColorToken,
69
+ disabled: highlightState.disabled
70
+ }), jsx("span", {
71
+ css: expandIconWrapperStyle
72
+ }, jsx(ExpandIcon, {
73
+ label: ""
74
+ })))
75
+ }, formatMessage(messages.highlightFloatingToolbar)),
76
+ onColorChange: function onColorChange(color) {
77
+ return handleColorChange(color);
78
+ },
79
+ isOpenedByKeyboard: isOpenedByKeyboard,
80
+ handleClickOutside: handleClickOutside,
81
+ handleEscapeKeydown: handleEscapeKeydown
82
+ }));
83
+ };
84
+ export var FloatingToolbarHighlightColorWithIntl = injectIntl(FloatingToolbarHighlightColor);
@@ -0,0 +1,99 @@
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
+ var PrimaryToolbarHighlightColor = function PrimaryToolbarHighlightColor(_ref) {
20
+ var popupsMountPoint = _ref.popupsMountPoint,
21
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
22
+ popupsScrollableElement = _ref.popupsScrollableElement,
23
+ isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
24
+ disabled = _ref.disabled,
25
+ pluginInjectionApi = _ref.pluginInjectionApi,
26
+ formatMessage = _ref.intl.formatMessage,
27
+ editorView = _ref.editorView;
28
+ var toolbarItemRef = useRef(null);
29
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['highlight']),
30
+ highlightState = _useSharedPluginState.highlightState;
31
+ var setDropdownOpen = function setDropdownOpen(isOpen) {
32
+ if (!(highlightState !== null && highlightState !== void 0 && highlightState.disabled)) {
33
+ var state = editorView.state,
34
+ dispatch = editorView.dispatch;
35
+ setPalette(pluginInjectionApi, isOpen)(state, dispatch);
36
+ }
37
+ };
38
+ var isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
39
+ var _useDropdownEvents = useDropdownEvents({
40
+ toolbarItemRef: toolbarItemRef,
41
+ setIsDropdownOpen: setDropdownOpen,
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.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 : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
61
+ return jsx(Flex, {
62
+ alignItems: "center"
63
+ }, jsx(PaletteDropdown, {
64
+ popupsMountPoint: popupsMountPoint,
65
+ popupsBoundariesElement: popupsBoundariesElement,
66
+ popupsScrollableElement: popupsScrollableElement,
67
+ isOpen: isDropdownOpen && !highlightState.disabled,
68
+ activeColor: highlightState.activeColor,
69
+ trigger: jsx(ToolbarButton, {
70
+ buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
71
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
72
+ disabled: disabled || highlightState.disabled,
73
+ selected: isDropdownOpen,
74
+ "aria-label": tooltip(toggleHighlightPalette, toolbarButtonLabel),
75
+ "aria-keyshortcuts": getAriaKeyshortcuts(toggleHighlightPalette),
76
+ "aria-expanded": isDropdownOpen,
77
+ "aria-haspopup": true,
78
+ title: tooltip(toggleHighlightPalette, toolbarButtonLabel),
79
+ onClick: handleClick,
80
+ onKeyDown: handleKeyDown,
81
+ ref: toolbarItemRef,
82
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
83
+ selectedColor: activeColorToken,
84
+ disabled: highlightState.disabled
85
+ }), jsx("span", {
86
+ css: expandIconWrapperStyle
87
+ }, jsx(ExpandIcon, {
88
+ label: ""
89
+ })))
90
+ }),
91
+ onColorChange: function onColorChange(color) {
92
+ return handleColorChange(color);
93
+ },
94
+ isOpenedByKeyboard: isOpenedByKeyboard,
95
+ handleClickOutside: handleClickOutside,
96
+ handleEscapeKeydown: handleEscapeKeydown
97
+ }));
98
+ };
99
+ export var PrimaryToolbarHighlightColorWithIntl = injectIntl(PrimaryToolbarHighlightColor);
@@ -17,7 +17,7 @@ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
17
17
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
18
18
  import { Flex } from '@atlaskit/primitives';
19
19
  import { changeColor, setPalette } from '../commands';
20
- import { EditorHighlightIcon } from './EditorHighlightIcon';
20
+ import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
21
21
  var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
22
22
  var popupsMountPoint = _ref.popupsMountPoint,
23
23
  popupsBoundariesElement = _ref.popupsBoundariesElement,
@@ -0,0 +1,54 @@
1
+ import React from 'react';
2
+ import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette, highlightColorPaletteWithTokenBorders } from '@atlaskit/editor-common/ui-color';
3
+ import { ArrowKeyNavigationType, DropdownContainer as Dropdown } from '@atlaskit/editor-common/ui-menu';
4
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
5
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
6
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
7
+ export var PaletteDropdown = function PaletteDropdown(props) {
8
+ var popupsMountPoint = props.popupsMountPoint,
9
+ popupsBoundariesElement = props.popupsBoundariesElement,
10
+ popupsScrollableElement = props.popupsScrollableElement,
11
+ isOpen = props.isOpen,
12
+ activeColor = props.activeColor,
13
+ trigger = props.trigger,
14
+ onColorChange = props.onColorChange,
15
+ isOpenedByKeyboard = props.isOpenedByKeyboard,
16
+ handleClickOutside = props.handleClickOutside,
17
+ handleEscapeKeydown = props.handleEscapeKeydown;
18
+
19
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
20
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
21
+ var fitWidth = 242;
22
+ var palette = getBooleanFF('platform.editor.dynamic-palette-borders') ? highlightColorPaletteWithTokenBorders : highlightColorPalette;
23
+ var _getSelectedRowAndCol = getSelectedRowAndColumnFromPalette(palette, activeColor),
24
+ selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
25
+ selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
26
+ return /*#__PURE__*/React.createElement(Dropdown, {
27
+ mountTo: popupsMountPoint,
28
+ boundariesElement: popupsBoundariesElement,
29
+ scrollableElement: popupsScrollableElement,
30
+ isOpen: isOpen,
31
+ handleClickOutside: handleClickOutside,
32
+ handleEscapeKeydown: handleEscapeKeydown,
33
+ zIndex: akEditorMenuZIndex,
34
+ fitWidth: fitWidth,
35
+ closeOnTab: true,
36
+ arrowKeyNavigationProviderOptions: {
37
+ type: ArrowKeyNavigationType.COLOR,
38
+ selectedRowIndex: selectedRowIndex,
39
+ selectedColumnIndex: selectedColumnIndex,
40
+ isOpenedByKeyboard: isOpenedByKeyboard,
41
+ isPopupPositioned: true
42
+ },
43
+ trigger: trigger
44
+ }, /*#__PURE__*/React.createElement("div", {
45
+ "data-testid": "highlight-color-palette"
46
+ }, /*#__PURE__*/React.createElement(ColorPalette, {
47
+ onClick: onColorChange,
48
+ selectedColor: activeColor,
49
+ paletteOptions: {
50
+ palette: palette,
51
+ hexToPaletteColor: hexToEditorTextBackgroundPaletteColor
52
+ }
53
+ })));
54
+ };
@@ -0,0 +1,48 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useState } from 'react';
3
+ import { changeColor } from '../../commands';
4
+ export var useDropdownEvents = function useDropdownEvents(args) {
5
+ var toolbarItemRef = args.toolbarItemRef,
6
+ setIsDropdownOpen = args.setIsDropdownOpen,
7
+ isDropdownOpen = args.isDropdownOpen,
8
+ pluginInjectionApi = args.pluginInjectionApi;
9
+ var _useState = useState(false),
10
+ _useState2 = _slicedToArray(_useState, 2),
11
+ isOpenedByKeyboard = _useState2[0],
12
+ setIsOpenedByKeyboard = _useState2[1];
13
+ return {
14
+ handleClick: function handleClick() {
15
+ setIsOpenedByKeyboard(false);
16
+ setIsDropdownOpen(!isDropdownOpen);
17
+ },
18
+ handleKeyDown: function handleKeyDown(event) {
19
+ if (event.key === 'Enter' || event.key === ' ') {
20
+ event.preventDefault();
21
+ setIsOpenedByKeyboard(true);
22
+ setIsDropdownOpen(!isDropdownOpen);
23
+ }
24
+ },
25
+ handleClickOutside: function handleClickOutside() {
26
+ if (isDropdownOpen) {
27
+ setIsDropdownOpen(false);
28
+ setIsOpenedByKeyboard(false);
29
+ }
30
+ },
31
+ handleEscapeKeydown: function handleEscapeKeydown() {
32
+ if (isDropdownOpen) {
33
+ var _toolbarItemRef$curre;
34
+ setIsDropdownOpen(false);
35
+ setIsOpenedByKeyboard(false);
36
+ toolbarItemRef === null || toolbarItemRef === void 0 || (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 || _toolbarItemRef$curre.focus();
37
+ }
38
+ },
39
+ handleColorChange: function handleColorChange(color) {
40
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
41
+ pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.core) === null || _pluginInjectionApi$c === void 0 || _pluginInjectionApi$c.actions.execute(changeColor(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)({
42
+ color: color
43
+ }));
44
+ setIsDropdownOpen(false);
45
+ },
46
+ isOpenedByKeyboard: isOpenedByKeyboard
47
+ };
48
+ };
@@ -4,7 +4,11 @@ import type { BackgroundColorPlugin } from '@atlaskit/editor-plugin-background-c
4
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
5
  import type { TextFormattingPlugin } from '@atlaskit/editor-plugin-text-formatting';
6
6
  import type { HighlightPluginState } from './pm-plugins/main';
7
+ export type HighlightPluginOptions = {
8
+ textHighlightingFloatingToolbarExperiment?: boolean;
9
+ };
7
10
  export type HighlightPlugin = NextEditorPlugin<'highlight', {
11
+ pluginConfiguration?: HighlightPluginOptions;
8
12
  dependencies: [
9
13
  BackgroundColorPlugin,
10
14
  OptionalPlugin<AnalyticsPlugin>,
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
4
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
+ import type { HighlightPlugin } from '../plugin';
6
+ export declare const FloatingToolbarHighlightColorWithIntl: import("react").FC<import("react-intl-next").WithIntlProps<{
7
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
8
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
9
+ } & WrappedComponentProps>> & {
10
+ WrappedComponent: import("react").ComponentType<{
11
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
12
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
13
+ } & WrappedComponentProps>;
14
+ };
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
5
+ import type { HighlightPlugin } from '../plugin';
6
+ export declare const PrimaryToolbarHighlightColorWithIntl: import("react").FC<import("react-intl-next").WithIntlProps<{
7
+ popupsMountPoint?: HTMLElement | undefined;
8
+ popupsBoundariesElement?: HTMLElement | undefined;
9
+ popupsScrollableElement?: HTMLElement | undefined;
10
+ disabled: boolean;
11
+ isToolbarReducedSpacing: boolean;
12
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
13
+ editorView: EditorView;
14
+ } & WrappedComponentProps>> & {
15
+ WrappedComponent: import("react").ComponentType<{
16
+ popupsMountPoint?: HTMLElement | undefined;
17
+ popupsBoundariesElement?: HTMLElement | undefined;
18
+ popupsScrollableElement?: HTMLElement | undefined;
19
+ disabled: boolean;
20
+ isToolbarReducedSpacing: boolean;
21
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
22
+ editorView: EditorView;
23
+ } & WrappedComponentProps>;
24
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { type WithOutsideClickProps } from '@atlaskit/editor-common/ui';
3
+ type PaletteDropdownProps = {
4
+ popupsMountPoint?: HTMLElement;
5
+ popupsBoundariesElement?: HTMLElement;
6
+ popupsScrollableElement?: HTMLElement;
7
+ isOpen: boolean;
8
+ activeColor: string | null;
9
+ trigger: React.ReactElement;
10
+ onColorChange: (color: string) => void;
11
+ isOpenedByKeyboard: boolean;
12
+ } & WithOutsideClickProps;
13
+ export declare const PaletteDropdown: (props: PaletteDropdownProps) => JSX.Element;
14
+ export {};