@atlaskit/editor-plugin-highlight 1.7.4 → 1.7.5

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 (45) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/commands/change-color.js +5 -4
  3. package/dist/cjs/commands/index.js +15 -1
  4. package/dist/cjs/commands/set-palette.js +39 -0
  5. package/dist/cjs/commands/toggle-palette.js +40 -0
  6. package/dist/cjs/plugin.js +15 -5
  7. package/dist/cjs/pm-plugins/keymap.js +14 -0
  8. package/dist/cjs/{pm-plugin.js → pm-plugins/main.js} +11 -3
  9. package/dist/cjs/ui/ToolbarHighlightColor.js +14 -18
  10. package/dist/cjs/utils/color.js +22 -21
  11. package/dist/es2019/commands/change-color.js +3 -2
  12. package/dist/es2019/commands/index.js +3 -1
  13. package/dist/es2019/commands/set-palette.js +31 -0
  14. package/dist/es2019/commands/toggle-palette.js +32 -0
  15. package/dist/es2019/plugin.js +11 -3
  16. package/dist/es2019/pm-plugins/keymap.js +9 -0
  17. package/dist/es2019/{pm-plugin.js → pm-plugins/main.js} +13 -3
  18. package/dist/es2019/ui/ToolbarHighlightColor.js +15 -14
  19. package/dist/es2019/utils/color.js +22 -21
  20. package/dist/esm/commands/change-color.js +3 -2
  21. package/dist/esm/commands/index.js +3 -1
  22. package/dist/esm/commands/set-palette.js +33 -0
  23. package/dist/esm/commands/toggle-palette.js +34 -0
  24. package/dist/esm/plugin.js +13 -3
  25. package/dist/esm/pm-plugins/keymap.js +8 -0
  26. package/dist/esm/{pm-plugin.js → pm-plugins/main.js} +11 -3
  27. package/dist/esm/ui/ToolbarHighlightColor.js +15 -19
  28. package/dist/esm/utils/color.js +22 -21
  29. package/dist/types/commands/index.d.ts +2 -0
  30. package/dist/types/commands/set-palette.d.ts +3 -0
  31. package/dist/types/commands/toggle-palette.d.ts +3 -0
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/plugin.d.ts +1 -1
  34. package/dist/types/pm-plugins/keymap.d.ts +6 -0
  35. package/dist/{types-ts4.5/pm-plugin.d.ts → types/pm-plugins/main.d.ts} +4 -2
  36. package/dist/types/ui/ToolbarHighlightColor.d.ts +3 -0
  37. package/dist/types-ts4.5/commands/index.d.ts +2 -0
  38. package/dist/types-ts4.5/commands/set-palette.d.ts +3 -0
  39. package/dist/types-ts4.5/commands/toggle-palette.d.ts +3 -0
  40. package/dist/types-ts4.5/index.d.ts +1 -1
  41. package/dist/types-ts4.5/plugin.d.ts +1 -1
  42. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +6 -0
  43. package/dist/{types/pm-plugin.d.ts → types-ts4.5/pm-plugins/main.d.ts} +4 -2
  44. package/dist/types-ts4.5/ui/ToolbarHighlightColor.d.ts +3 -0
  45. package/package.json +2 -2
@@ -2,8 +2,8 @@
2
2
  import React, { useRef, useState } from 'react';
3
3
  import { jsx } from '@emotion/react';
4
4
  import { injectIntl } from 'react-intl-next';
5
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
6
5
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
+ import { getAriaKeyshortcuts, toggleHighlightPalette, tooltip } from '@atlaskit/editor-common/keymaps';
7
7
  import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
8
8
  import { expandIconWrapperStyle } from '@atlaskit/editor-common/styles';
9
9
  import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette } from '@atlaskit/editor-common/ui-color';
@@ -12,34 +12,34 @@ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette'
12
12
  import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
13
13
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
14
  import { Flex } from '@atlaskit/primitives';
15
- import { changeColor } from '../commands';
15
+ import { changeColor, setPalette } from '../commands';
16
16
  import { EditorHighlightIcon } from './EditorHighlightIcon';
17
17
  const ToolbarHighlightColor = ({
18
18
  popupsMountPoint,
19
19
  popupsBoundariesElement,
20
20
  popupsScrollableElement,
21
21
  isToolbarReducedSpacing,
22
- dispatchAnalyticsEvent,
23
22
  disabled,
24
23
  pluginInjectionApi,
25
24
  intl: {
26
25
  formatMessage
27
- }
26
+ },
27
+ editorView
28
28
  }) => {
29
29
  const toolbarItemRef = useRef(null);
30
- const [isDropdownOpen, setIsDropdownOpen] = useState(false);
31
30
  const [isOpenedByKeyboard, setIsOpenedByKeyboard] = useState(false);
32
31
  const {
33
32
  highlightState
34
33
  } = useSharedPluginState(pluginInjectionApi, ['highlight']);
34
+ const isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
35
35
  const setDropdownOpen = isOpen => {
36
- dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 ? void 0 : dispatchAnalyticsEvent({
37
- action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
38
- actionSubject: ACTION_SUBJECT.TOOLBAR,
39
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
40
- eventType: EVENT_TYPE.TRACK
41
- });
42
- setIsDropdownOpen(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
43
  };
44
44
  const toggleDropdown = () => setDropdownOpen(!isDropdownOpen);
45
45
  const handleClick = () => {
@@ -116,10 +116,11 @@ const ToolbarHighlightColor = ({
116
116
  spacing: isToolbarReducedSpacing ? 'none' : 'default',
117
117
  disabled: disabled || highlightState.disabled,
118
118
  selected: isDropdownOpen,
119
- "aria-label": toolbarButtonLabel,
119
+ "aria-label": tooltip(toggleHighlightPalette, toolbarButtonLabel),
120
+ "aria-keyshortcuts": getAriaKeyshortcuts(toggleHighlightPalette),
120
121
  "aria-expanded": isDropdownOpen,
121
122
  "aria-haspopup": true,
122
- title: toolbarButtonLabel,
123
+ title: tooltip(toggleHighlightPalette, toolbarButtonLabel),
123
124
  onClick: handleClick,
124
125
  onKeyDown: handleKeyDown,
125
126
  ref: toolbarItemRef,
@@ -1,5 +1,4 @@
1
1
  import { entireSelectionContainsMark } from '@atlaskit/editor-common/mark';
2
- import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
3
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
3
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
5
4
  const getAllUniqueBackgroundColorMarksInRange = (from, to, tr) => {
@@ -45,23 +44,24 @@ const getAllUniqueBackgroundColorMarksInCellSelection = (selection, tr) => {
45
44
  const getColorFromCellSelection = (selection, tr) => {
46
45
  const marks = getAllUniqueBackgroundColorMarksInCellSelection(selection, tr);
47
46
  if (marks.length > 1) {
48
- return null;
47
+ return 'multiple';
49
48
  }
50
49
  const firstColorMark = marks.at(0);
51
- let foundNonColoredNode = false;
52
- if (firstColorMark) {
53
- selection.forEachCell((cell, cellPos) => {
54
- if (foundNonColoredNode) {
55
- return;
56
- }
57
- const from = cellPos;
58
- const to = cellPos + cell.nodeSize;
59
- if (!entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
60
- foundNonColoredNode = true;
61
- }
62
- });
50
+ if (!firstColorMark) {
51
+ return null;
63
52
  }
64
- return foundNonColoredNode ? REMOVE_HIGHLIGHT_COLOR : firstColorMark === null || firstColorMark === void 0 ? void 0 : firstColorMark.attrs.color;
53
+ let foundUncolouredNode = false;
54
+ selection.forEachCell((cell, cellPos) => {
55
+ if (foundUncolouredNode) {
56
+ return;
57
+ }
58
+ const from = cellPos;
59
+ const to = cellPos + cell.nodeSize;
60
+ if (!entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
61
+ foundUncolouredNode = true;
62
+ }
63
+ });
64
+ return foundUncolouredNode ? null : firstColorMark.attrs.color;
65
65
  };
66
66
 
67
67
  // All other selections - find the first instance of a backgroundColor mark
@@ -70,28 +70,29 @@ const getColorFromCellSelection = (selection, tr) => {
70
70
  const getColorFromRange = (from, to, tr) => {
71
71
  const marks = getAllUniqueBackgroundColorMarksInRange(from, to, tr);
72
72
  if (marks.length > 1) {
73
- return null;
73
+ return 'multiple';
74
74
  }
75
75
  const firstColorMark = marks.at(0);
76
76
  if (firstColorMark && entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
77
77
  return firstColorMark.attrs.color;
78
78
  }
79
- return REMOVE_HIGHLIGHT_COLOR;
79
+ return null;
80
80
  };
81
81
 
82
82
  // For Cursor selections - set color if it is found in the storedMarks or $cursor.marks
83
83
  const getColorFromCursor = (selection, tr) => {
84
+ var _mark$attrs$color;
84
85
  if (!selection.$cursor) {
85
- return REMOVE_HIGHLIGHT_COLOR;
86
+ return null;
86
87
  }
87
88
  const mark = tr.doc.type.schema.marks.backgroundColor.isInSet([...(tr.storedMarks ? tr.storedMarks : []), ...selection.$cursor.marks()]);
88
- return (mark === null || mark === void 0 ? void 0 : mark.attrs.color) || REMOVE_HIGHLIGHT_COLOR;
89
+ return (_mark$attrs$color = mark === null || mark === void 0 ? void 0 : mark.attrs.color) !== null && _mark$attrs$color !== void 0 ? _mark$attrs$color : null;
89
90
  };
90
91
  export const getActiveColor = tr => {
91
92
  const {
92
93
  selection
93
94
  } = tr;
94
- let color;
95
+ let color = null;
95
96
  if (selection instanceof CellSelection) {
96
97
  color = getColorFromCellSelection(selection, tr);
97
98
  } else if (selection instanceof TextSelection && selection.$cursor) {
@@ -99,5 +100,5 @@ export const getActiveColor = tr => {
99
100
  } else {
100
101
  color = getColorFromRange(selection.from, selection.to, tr);
101
102
  }
102
- return color === undefined ? REMOVE_HIGHLIGHT_COLOR : color;
103
+ return color;
103
104
  };
@@ -1,7 +1,7 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
2
  import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
3
3
  import { highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
4
- import { HighlightPluginAction, highlightPluginKey } from '../pm-plugin';
4
+ import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
5
5
  import { getActiveColor } from '../utils/color';
6
6
  export var changeColor = function changeColor(editorAnalyticsAPI) {
7
7
  return function (_ref) {
@@ -34,7 +34,8 @@ export var changeColor = function changeColor(editorAnalyticsAPI) {
34
34
  };
35
35
  };
36
36
  var createAnalyticsEvent = function createAnalyticsEvent(color, tr) {
37
- var previousColor = getActiveColor(tr);
37
+ var _getActiveColor;
38
+ var previousColor = (_getActiveColor = getActiveColor(tr)) !== null && _getActiveColor !== void 0 ? _getActiveColor : REMOVE_HIGHLIGHT_COLOR;
38
39
  // get color names from palette
39
40
  var newColorFromPalette = highlightColorPalette.find(function (_ref3) {
40
41
  var value = _ref3.value;
@@ -1 +1,3 @@
1
- export { changeColor } from './change-color';
1
+ export { changeColor } from './change-color';
2
+ export { togglePalette } from './toggle-palette';
3
+ export { setPalette } from './set-palette';
@@ -0,0 +1,33 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
3
+ export var setPalette = function setPalette(api, isPaletteOpen) {
4
+ return function (state, dispatch) {
5
+ var _highlightPluginKey$g;
6
+ var isDisabled = (_highlightPluginKey$g = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
7
+ if (!isDisabled) {
8
+ var _api$analytics;
9
+ var tr = state.tr;
10
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(isPaletteOpen))(tr);
11
+ tr.setMeta(highlightPluginKey, {
12
+ type: HighlightPluginAction.TOGGLE_PALETTE,
13
+ isPaletteOpen: isPaletteOpen
14
+ });
15
+ if (dispatch) {
16
+ dispatch(tr);
17
+ }
18
+ return true;
19
+ }
20
+ return false;
21
+ };
22
+ };
23
+ var createAnalyticsEvent = function createAnalyticsEvent(isOpen) {
24
+ return {
25
+ action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
26
+ actionSubject: ACTION_SUBJECT.TOOLBAR,
27
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
28
+ eventType: EVENT_TYPE.TRACK,
29
+ attributes: {
30
+ inputMethod: INPUT_METHOD.TOOLBAR
31
+ }
32
+ };
33
+ };
@@ -0,0 +1,34 @@
1
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
+ import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
3
+ export var togglePalette = function togglePalette(api) {
4
+ return function (state, dispatch) {
5
+ var _highlightPluginKey$g, _highlightPluginKey$g2;
6
+ var isDisabled = (_highlightPluginKey$g = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
7
+ var isPaletteOpen = (_highlightPluginKey$g2 = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g2 === void 0 ? void 0 : _highlightPluginKey$g2.isPaletteOpen;
8
+ var tr = state.tr;
9
+ if (!isDisabled) {
10
+ var _api$analytics;
11
+ (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(!isPaletteOpen))(tr);
12
+ tr.setMeta(highlightPluginKey, {
13
+ type: HighlightPluginAction.TOGGLE_PALETTE,
14
+ isPaletteOpen: !isPaletteOpen
15
+ });
16
+ if (dispatch) {
17
+ dispatch(tr);
18
+ }
19
+ return true;
20
+ }
21
+ return false;
22
+ };
23
+ };
24
+ var createAnalyticsEvent = function createAnalyticsEvent(isOpen) {
25
+ return {
26
+ action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
27
+ actionSubject: ACTION_SUBJECT.TOOLBAR,
28
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
29
+ eventType: EVENT_TYPE.TRACK,
30
+ attributes: {
31
+ inputMethod: INPUT_METHOD.SHORTCUT
32
+ }
33
+ };
34
+ };
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { changeColor } from './commands';
3
- import { createPlugin, highlightPluginKey } from './pm-plugin';
3
+ import { keymapPlugin } from './pm-plugins/keymap';
4
+ import { createPlugin, highlightPluginKey } from './pm-plugins/main';
4
5
  import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
5
6
  export var highlightPlugin = function highlightPlugin(_ref) {
6
7
  var _api$analytics;
@@ -12,7 +13,8 @@ export var highlightPlugin = function highlightPlugin(_ref) {
12
13
  popupsScrollableElement = _ref2.popupsScrollableElement,
13
14
  disabled = _ref2.disabled,
14
15
  isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
15
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
16
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
17
+ editorView = _ref2.editorView;
16
18
  return /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
17
19
  popupsMountPoint: popupsMountPoint,
18
20
  popupsBoundariesElement: popupsBoundariesElement,
@@ -20,7 +22,8 @@ export var highlightPlugin = function highlightPlugin(_ref) {
20
22
  disabled: disabled,
21
23
  isToolbarReducedSpacing: isToolbarReducedSpacing,
22
24
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
23
- pluginInjectionApi: api
25
+ pluginInjectionApi: api,
26
+ editorView: editorView
24
27
  });
25
28
  };
26
29
  return {
@@ -36,6 +39,13 @@ export var highlightPlugin = function highlightPlugin(_ref) {
36
39
  api: api
37
40
  });
38
41
  }
42
+ }, {
43
+ name: 'highlightKeymap',
44
+ plugin: function plugin() {
45
+ return keymapPlugin({
46
+ api: api
47
+ });
48
+ }
39
49
  }];
40
50
  },
41
51
  getSharedState: function getSharedState(editorState) {
@@ -0,0 +1,8 @@
1
+ import { bindKeymapWithCommand, keymap, toggleHighlightPalette } from '@atlaskit/editor-common/keymaps';
2
+ import { togglePalette } from '../commands';
3
+ export function keymapPlugin(_ref) {
4
+ var api = _ref.api;
5
+ var list = {};
6
+ bindKeymapWithCommand(toggleHighlightPalette.common, togglePalette(api), list);
7
+ return keymap(list);
8
+ }
@@ -3,11 +3,12 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
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 { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
- import { getActiveColor } from './utils/color';
7
- import { getDisabledState } from './utils/disabled';
6
+ import { getActiveColor } from '../utils/color';
7
+ import { getDisabledState } from '../utils/disabled';
8
8
  export var highlightPluginKey = new PluginKey('highlight');
9
9
  export var HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
10
10
  HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
11
+ HighlightPluginAction[HighlightPluginAction["TOGGLE_PALETTE"] = 1] = "TOGGLE_PALETTE";
11
12
  return HighlightPluginAction;
12
13
  }({});
13
14
  export var createPlugin = function createPlugin(_ref) {
@@ -18,7 +19,8 @@ export var createPlugin = function createPlugin(_ref) {
18
19
  init: function init(_, editorState) {
19
20
  return {
20
21
  activeColor: null,
21
- disabled: getDisabledState(editorState)
22
+ disabled: getDisabledState(editorState),
23
+ isPaletteOpen: false
22
24
  };
23
25
  },
24
26
  apply: function apply(tr, pluginState, _oldState, newState) {
@@ -31,6 +33,12 @@ export var createPlugin = function createPlugin(_ref) {
31
33
  return _objectSpread(_objectSpread({}, pluginState), {}, {
32
34
  activeColor: color
33
35
  });
36
+ case HighlightPluginAction.TOGGLE_PALETTE:
37
+ var _tr$getMeta3 = tr.getMeta(highlightPluginKey),
38
+ isPaletteOpen = _tr$getMeta3.isPaletteOpen;
39
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
40
+ isPaletteOpen: isPaletteOpen
41
+ });
34
42
  default:
35
43
  return _objectSpread(_objectSpread({}, pluginState), {}, {
36
44
  activeColor: getActiveColor(tr),
@@ -3,8 +3,8 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  import React, { useRef, useState } from 'react';
4
4
  import { jsx } from '@emotion/react';
5
5
  import { injectIntl } from 'react-intl-next';
6
- import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
7
6
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
+ import { getAriaKeyshortcuts, toggleHighlightPalette, tooltip } from '@atlaskit/editor-common/keymaps';
8
8
  import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
9
9
  import { expandIconWrapperStyle } from '@atlaskit/editor-common/styles';
10
10
  import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette } from '@atlaskit/editor-common/ui-color';
@@ -13,36 +13,31 @@ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette'
13
13
  import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
14
14
  import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
15
15
  import { Flex } from '@atlaskit/primitives';
16
- import { changeColor } from '../commands';
16
+ import { changeColor, setPalette } from '../commands';
17
17
  import { EditorHighlightIcon } from './EditorHighlightIcon';
18
18
  var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
19
19
  var popupsMountPoint = _ref.popupsMountPoint,
20
20
  popupsBoundariesElement = _ref.popupsBoundariesElement,
21
21
  popupsScrollableElement = _ref.popupsScrollableElement,
22
22
  isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
23
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
24
23
  disabled = _ref.disabled,
25
24
  pluginInjectionApi = _ref.pluginInjectionApi,
26
- formatMessage = _ref.intl.formatMessage;
25
+ formatMessage = _ref.intl.formatMessage,
26
+ editorView = _ref.editorView;
27
27
  var toolbarItemRef = useRef(null);
28
28
  var _useState = useState(false),
29
29
  _useState2 = _slicedToArray(_useState, 2),
30
- isDropdownOpen = _useState2[0],
31
- setIsDropdownOpen = _useState2[1];
32
- var _useState3 = useState(false),
33
- _useState4 = _slicedToArray(_useState3, 2),
34
- isOpenedByKeyboard = _useState4[0],
35
- setIsOpenedByKeyboard = _useState4[1];
30
+ isOpenedByKeyboard = _useState2[0],
31
+ setIsOpenedByKeyboard = _useState2[1];
36
32
  var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['highlight']),
37
33
  highlightState = _useSharedPluginState.highlightState;
34
+ var isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
38
35
  var setDropdownOpen = function setDropdownOpen(isOpen) {
39
- dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
40
- action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
41
- actionSubject: ACTION_SUBJECT.TOOLBAR,
42
- actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
43
- eventType: EVENT_TYPE.TRACK
44
- });
45
- setIsDropdownOpen(isOpen);
36
+ if (!(highlightState !== null && highlightState !== void 0 && highlightState.disabled)) {
37
+ var state = editorView.state,
38
+ dispatch = editorView.dispatch;
39
+ setPalette(pluginInjectionApi, isOpen)(state, dispatch);
40
+ }
46
41
  };
47
42
  var toggleDropdown = function toggleDropdown() {
48
43
  return setDropdownOpen(!isDropdownOpen);
@@ -120,10 +115,11 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
120
115
  spacing: isToolbarReducedSpacing ? 'none' : 'default',
121
116
  disabled: disabled || highlightState.disabled,
122
117
  selected: isDropdownOpen,
123
- "aria-label": toolbarButtonLabel,
118
+ "aria-label": tooltip(toggleHighlightPalette, toolbarButtonLabel),
119
+ "aria-keyshortcuts": getAriaKeyshortcuts(toggleHighlightPalette),
124
120
  "aria-expanded": isDropdownOpen,
125
121
  "aria-haspopup": true,
126
- title: toolbarButtonLabel,
122
+ title: tooltip(toggleHighlightPalette, toolbarButtonLabel),
127
123
  onClick: handleClick,
128
124
  onKeyDown: handleKeyDown,
129
125
  ref: toolbarItemRef,
@@ -1,6 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { entireSelectionContainsMark } from '@atlaskit/editor-common/mark';
3
- import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
4
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
5
4
  import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
6
5
  var getAllUniqueBackgroundColorMarksInRange = function getAllUniqueBackgroundColorMarksInRange(from, to, tr) {
@@ -42,23 +41,24 @@ var getAllUniqueBackgroundColorMarksInCellSelection = function getAllUniqueBackg
42
41
  var getColorFromCellSelection = function getColorFromCellSelection(selection, tr) {
43
42
  var marks = getAllUniqueBackgroundColorMarksInCellSelection(selection, tr);
44
43
  if (marks.length > 1) {
45
- return null;
44
+ return 'multiple';
46
45
  }
47
46
  var firstColorMark = marks.at(0);
48
- var foundNonColoredNode = false;
49
- if (firstColorMark) {
50
- selection.forEachCell(function (cell, cellPos) {
51
- if (foundNonColoredNode) {
52
- return;
53
- }
54
- var from = cellPos;
55
- var to = cellPos + cell.nodeSize;
56
- if (!entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
57
- foundNonColoredNode = true;
58
- }
59
- });
47
+ if (!firstColorMark) {
48
+ return null;
60
49
  }
61
- return foundNonColoredNode ? REMOVE_HIGHLIGHT_COLOR : firstColorMark === null || firstColorMark === void 0 ? void 0 : firstColorMark.attrs.color;
50
+ var foundUncolouredNode = false;
51
+ selection.forEachCell(function (cell, cellPos) {
52
+ if (foundUncolouredNode) {
53
+ return;
54
+ }
55
+ var from = cellPos;
56
+ var to = cellPos + cell.nodeSize;
57
+ if (!entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
58
+ foundUncolouredNode = true;
59
+ }
60
+ });
61
+ return foundUncolouredNode ? null : firstColorMark.attrs.color;
62
62
  };
63
63
 
64
64
  // All other selections - find the first instance of a backgroundColor mark
@@ -67,26 +67,27 @@ var getColorFromCellSelection = function getColorFromCellSelection(selection, tr
67
67
  var getColorFromRange = function getColorFromRange(from, to, tr) {
68
68
  var marks = getAllUniqueBackgroundColorMarksInRange(from, to, tr);
69
69
  if (marks.length > 1) {
70
- return null;
70
+ return 'multiple';
71
71
  }
72
72
  var firstColorMark = marks.at(0);
73
73
  if (firstColorMark && entireSelectionContainsMark(firstColorMark, tr.doc, from, to)) {
74
74
  return firstColorMark.attrs.color;
75
75
  }
76
- return REMOVE_HIGHLIGHT_COLOR;
76
+ return null;
77
77
  };
78
78
 
79
79
  // For Cursor selections - set color if it is found in the storedMarks or $cursor.marks
80
80
  var getColorFromCursor = function getColorFromCursor(selection, tr) {
81
+ var _mark$attrs$color;
81
82
  if (!selection.$cursor) {
82
- return REMOVE_HIGHLIGHT_COLOR;
83
+ return null;
83
84
  }
84
85
  var mark = tr.doc.type.schema.marks.backgroundColor.isInSet([].concat(_toConsumableArray(tr.storedMarks ? tr.storedMarks : []), _toConsumableArray(selection.$cursor.marks())));
85
- return (mark === null || mark === void 0 ? void 0 : mark.attrs.color) || REMOVE_HIGHLIGHT_COLOR;
86
+ return (_mark$attrs$color = mark === null || mark === void 0 ? void 0 : mark.attrs.color) !== null && _mark$attrs$color !== void 0 ? _mark$attrs$color : null;
86
87
  };
87
88
  export var getActiveColor = function getActiveColor(tr) {
88
89
  var selection = tr.selection;
89
- var color;
90
+ var color = null;
90
91
  if (selection instanceof CellSelection) {
91
92
  color = getColorFromCellSelection(selection, tr);
92
93
  } else if (selection instanceof TextSelection && selection.$cursor) {
@@ -94,5 +95,5 @@ export var getActiveColor = function getActiveColor(tr) {
94
95
  } else {
95
96
  color = getColorFromRange(selection.from, selection.to, tr);
96
97
  }
97
- return color === undefined ? REMOVE_HIGHLIGHT_COLOR : color;
98
+ return color;
98
99
  };
@@ -1 +1,3 @@
1
1
  export { changeColor } from './change-color';
2
+ export { togglePalette } from './toggle-palette';
3
+ export { setPalette } from './set-palette';
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type HighlightPlugin } from '../plugin';
3
+ export declare const setPalette: (api: ExtractInjectionAPI<HighlightPlugin>, isPaletteOpen: boolean) => Command;
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type HighlightPlugin } from '../plugin';
3
+ export declare const togglePalette: (api: ExtractInjectionAPI<HighlightPlugin>) => Command;
@@ -1,3 +1,3 @@
1
1
  export { highlightPlugin } from './plugin';
2
2
  export type { HighlightPlugin } from './plugin';
3
- export type { HighlightPluginState } from './pm-plugin';
3
+ export type { HighlightPluginState } from './pm-plugins/main';
@@ -3,7 +3,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { BackgroundColorPlugin } from '@atlaskit/editor-plugin-background-color';
4
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
5
  import type { TextFormattingPlugin } from '@atlaskit/editor-plugin-text-formatting';
6
- import type { HighlightPluginState } from './pm-plugin';
6
+ import type { HighlightPluginState } from './pm-plugins/main';
7
7
  export type HighlightPlugin = NextEditorPlugin<'highlight', {
8
8
  dependencies: [
9
9
  BackgroundColorPlugin,
@@ -0,0 +1,6 @@
1
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { HighlightPlugin } from '../plugin';
4
+ export declare function keymapPlugin({ api }: {
5
+ api: ExtractInjectionAPI<HighlightPlugin> | undefined;
6
+ }): SafePlugin<any>;
@@ -1,14 +1,16 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import type { HighlightPlugin } from './plugin';
4
+ import type { HighlightPlugin } from '../plugin';
5
5
  export declare const highlightPluginKey: PluginKey<HighlightPluginState>;
6
6
  export type HighlightPluginState = {
7
7
  activeColor: string | null;
8
8
  disabled: boolean;
9
+ isPaletteOpen: boolean;
9
10
  };
10
11
  export declare enum HighlightPluginAction {
11
- CHANGE_COLOR = 0
12
+ CHANGE_COLOR = 0,
13
+ TOGGLE_PALETTE = 1
12
14
  }
13
15
  export declare const createPlugin: ({ api, }: {
14
16
  api: ExtractInjectionAPI<HighlightPlugin> | undefined;
@@ -3,6 +3,7 @@ import React from 'react';
3
3
  import type { WrappedComponentProps } from 'react-intl-next';
4
4
  import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
5
5
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
6
7
  import type { HighlightPlugin } from '../plugin';
7
8
  export declare const ToolbarHighlightColorWithIntl: React.FC<import("react-intl-next").WithIntlProps<{
8
9
  popupsMountPoint?: HTMLElement | undefined;
@@ -12,6 +13,7 @@ export declare const ToolbarHighlightColorWithIntl: React.FC<import("react-intl-
12
13
  isToolbarReducedSpacing: boolean;
13
14
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
14
15
  pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
16
+ editorView: EditorView;
15
17
  } & WrappedComponentProps>> & {
16
18
  WrappedComponent: React.ComponentType<{
17
19
  popupsMountPoint?: HTMLElement | undefined;
@@ -21,5 +23,6 @@ export declare const ToolbarHighlightColorWithIntl: React.FC<import("react-intl-
21
23
  isToolbarReducedSpacing: boolean;
22
24
  dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
23
25
  pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
26
+ editorView: EditorView;
24
27
  } & WrappedComponentProps>;
25
28
  };
@@ -1 +1,3 @@
1
1
  export { changeColor } from './change-color';
2
+ export { togglePalette } from './toggle-palette';
3
+ export { setPalette } from './set-palette';
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type HighlightPlugin } from '../plugin';
3
+ export declare const setPalette: (api: ExtractInjectionAPI<HighlightPlugin>, isPaletteOpen: boolean) => Command;
@@ -0,0 +1,3 @@
1
+ import type { Command, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import { type HighlightPlugin } from '../plugin';
3
+ export declare const togglePalette: (api: ExtractInjectionAPI<HighlightPlugin>) => Command;
@@ -1,3 +1,3 @@
1
1
  export { highlightPlugin } from './plugin';
2
2
  export type { HighlightPlugin } from './plugin';
3
- export type { HighlightPluginState } from './pm-plugin';
3
+ export type { HighlightPluginState } from './pm-plugins/main';
@@ -3,7 +3,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
3
3
  import type { BackgroundColorPlugin } from '@atlaskit/editor-plugin-background-color';
4
4
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
5
5
  import type { TextFormattingPlugin } from '@atlaskit/editor-plugin-text-formatting';
6
- import type { HighlightPluginState } from './pm-plugin';
6
+ import type { HighlightPluginState } from './pm-plugins/main';
7
7
  export type HighlightPlugin = NextEditorPlugin<'highlight', {
8
8
  dependencies: [
9
9
  BackgroundColorPlugin,
@@ -0,0 +1,6 @@
1
+ import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { HighlightPlugin } from '../plugin';
4
+ export declare function keymapPlugin({ api }: {
5
+ api: ExtractInjectionAPI<HighlightPlugin> | undefined;
6
+ }): SafePlugin<any>;
@@ -1,14 +1,16 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- import type { HighlightPlugin } from './plugin';
4
+ import type { HighlightPlugin } from '../plugin';
5
5
  export declare const highlightPluginKey: PluginKey<HighlightPluginState>;
6
6
  export type HighlightPluginState = {
7
7
  activeColor: string | null;
8
8
  disabled: boolean;
9
+ isPaletteOpen: boolean;
9
10
  };
10
11
  export declare enum HighlightPluginAction {
11
- CHANGE_COLOR = 0
12
+ CHANGE_COLOR = 0,
13
+ TOGGLE_PALETTE = 1
12
14
  }
13
15
  export declare const createPlugin: ({ api, }: {
14
16
  api: ExtractInjectionAPI<HighlightPlugin> | undefined;