@atlaskit/editor-plugin-highlight 1.0.5 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/editor-plugin-highlight
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 1.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#98130](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98130)
14
+ [`6a3c0d9d6382`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6a3c0d9d6382) -
15
+ [ED-23154] Add highlight option to main toolbar in editor
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+
3
21
  ## 1.0.5
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.changeColor = void 0;
7
+ var _pmPlugin = require("../pm-plugin");
8
+ // import {
9
+ // ACTION,
10
+ // ACTION_SUBJECT,
11
+ // ACTION_SUBJECT_ID,
12
+ // EVENT_TYPE,
13
+ // } from '@atlaskit/editor-common/analytics';
14
+
15
+ var changeColor = exports.changeColor = function changeColor(_editorAnalyticsAPI) {
16
+ return function (_ref) {
17
+ var color = _ref.color;
18
+ return function (_ref2) {
19
+ var tr = _ref2.tr;
20
+ tr.setMeta(_pmPlugin.highlightPluginKey, {
21
+ type: _pmPlugin.HighlightPluginAction.CHANGE_COLOR,
22
+ color: color
23
+ });
24
+
25
+ // editorAnalyticsAPI?.attachAnalyticsEvent({
26
+ // action: ACTION.FORMATTED,
27
+ // actionSubject: ACTION_SUBJECT.TEXT,
28
+ // actionSubjectId: ACTION_SUBJECT_ID.HIGHLIGHT,
29
+ // eventType: EVENT_TYPE.TRACK,
30
+ // })(tr);
31
+
32
+ return tr;
33
+ };
34
+ };
35
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "changeColor", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _changeColor.changeColor;
10
+ }
11
+ });
12
+ var _changeColor = require("./change-color");
@@ -1,15 +1,24 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.highlightPlugin = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
7
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
+ var _commands = require("./commands");
8
11
  var _pmPlugin = require("./pm-plugin");
12
+ var _ToolbarHighlightColor = require("./ui/ToolbarHighlightColor");
9
13
  var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
14
+ var _api$analytics;
10
15
  var api = _ref.api;
16
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
11
17
  return {
12
18
  name: 'highlight',
19
+ commands: {
20
+ changeColor: (0, _commands.changeColor)(editorAnalyticsAPI)
21
+ },
13
22
  marks: function marks() {
14
23
  return [{
15
24
  name: 'backgroundColor',
@@ -31,9 +40,24 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
31
40
  return;
32
41
  }
33
42
  return _pmPlugin.highlightPluginKey.getState(editorState);
34
- } // Add highlight toolbar button to primary toolbar
35
- // primaryToolbarComponent({ disabled }) {
36
- // TODO: Implement primary toolbar UI
37
- // },
43
+ },
44
+ primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
45
+ var editorView = _ref2.editorView,
46
+ popupsMountPoint = _ref2.popupsMountPoint,
47
+ popupsBoundariesElement = _ref2.popupsBoundariesElement,
48
+ popupsScrollableElement = _ref2.popupsScrollableElement,
49
+ disabled = _ref2.disabled,
50
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
51
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
52
+ return /*#__PURE__*/_react.default.createElement(_ToolbarHighlightColor.ToolbarHighlightColorWithIntl, {
53
+ popupsMountPoint: popupsMountPoint,
54
+ popupsBoundariesElement: popupsBoundariesElement,
55
+ popupsScrollableElement: popupsScrollableElement,
56
+ disabled: disabled,
57
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
58
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
59
+ pluginInjectionApi: api
60
+ });
61
+ }
38
62
  };
39
63
  };
@@ -1,15 +1,47 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.highlightPluginKey = exports.createPlugin = void 0;
7
+ exports.highlightPluginKey = exports.createPlugin = exports.HighlightPluginAction = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
+ var _uiColor = require("@atlaskit/editor-common/ui-color");
8
11
  var _state = require("@atlaskit/editor-prosemirror/state");
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
14
  var highlightPluginKey = exports.highlightPluginKey = new _state.PluginKey('highlight');
15
+ var initialState = {
16
+ activeColor: _uiColor.REMOVE_HIGHLIGHT_COLOR,
17
+ disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
18
+ };
19
+ var HighlightPluginAction = exports.HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
20
+ HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
21
+ return HighlightPluginAction;
22
+ }({});
10
23
  var createPlugin = exports.createPlugin = function createPlugin(_ref) {
11
24
  var api = _ref.api;
12
25
  return new _safePlugin.SafePlugin({
13
- key: highlightPluginKey
26
+ key: highlightPluginKey,
27
+ state: {
28
+ init: function init() {
29
+ return initialState;
30
+ },
31
+ apply: function apply(tr, pluginState) {
32
+ var _tr$getMeta;
33
+ var action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
34
+ switch (action) {
35
+ case HighlightPluginAction.CHANGE_COLOR:
36
+ var _tr$getMeta2 = tr.getMeta(highlightPluginKey),
37
+ color = _tr$getMeta2.color;
38
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
39
+ activeColor: color
40
+ });
41
+ default:
42
+ return pluginState;
43
+ }
44
+ }
45
+ }
14
46
  });
15
47
  };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.EditorHighlightIcon = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _icons = require("@atlaskit/editor-common/icons");
10
+ var _editFilled = _interopRequireDefault(require("@atlaskit/icon/glyph/edit-filled"));
11
+ var _primitives = require("@atlaskit/primitives");
12
+ var EditorHighlightIcon = exports.EditorHighlightIcon = function EditorHighlightIcon(_ref) {
13
+ var disabled = _ref.disabled,
14
+ selectedColor = _ref.selectedColor;
15
+ return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
16
+ paddingInline: "space.050"
17
+ }, /*#__PURE__*/_react.default.createElement(_icons.SteppedRainbowIconDecoration, {
18
+ selectedColor: selectedColor,
19
+ disabled: disabled,
20
+ icon: /*#__PURE__*/_react.default.createElement(_editFilled.default, {
21
+ size: "small",
22
+ label: ""
23
+ })
24
+ }));
25
+ };
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ToolbarHighlightColorWithIntl = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _react2 = require("@emotion/react");
12
+ var _reactIntlNext = require("react-intl-next");
13
+ var _analytics = require("@atlaskit/editor-common/analytics");
14
+ var _hooks = require("@atlaskit/editor-common/hooks");
15
+ var _messages = require("@atlaskit/editor-common/messages");
16
+ var _styles = require("@atlaskit/editor-common/styles");
17
+ var _uiColor = require("@atlaskit/editor-common/ui-color");
18
+ var _uiMenu = require("@atlaskit/editor-common/ui-menu");
19
+ var _editorPalette = require("@atlaskit/editor-palette");
20
+ var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
21
+ var _chevronDown = _interopRequireDefault(require("@atlaskit/icon/glyph/chevron-down"));
22
+ var _primitives = require("@atlaskit/primitives");
23
+ var _commands = require("../commands");
24
+ var _EditorHighlightIcon = require("./EditorHighlightIcon");
25
+ 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); }
26
+ 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; }
27
+ /** @jsx jsx */
28
+
29
+ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
30
+ var popupsMountPoint = _ref.popupsMountPoint,
31
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
32
+ popupsScrollableElement = _ref.popupsScrollableElement,
33
+ isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
34
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
35
+ disabled = _ref.disabled,
36
+ pluginInjectionApi = _ref.pluginInjectionApi,
37
+ formatMessage = _ref.intl.formatMessage;
38
+ var toolbarItemRef = (0, _react.useRef)(null);
39
+ var _useState = (0, _react.useState)(false),
40
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
41
+ isDropdownOpen = _useState2[0],
42
+ setIsDropdownOpen = _useState2[1];
43
+ var _useState3 = (0, _react.useState)(false),
44
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
45
+ isOpenedByKeyboard = _useState4[0],
46
+ setIsOpenedByKeyboard = _useState4[1];
47
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['highlight']),
48
+ highlightState = _useSharedPluginState.highlightState;
49
+ var setDropdownOpen = function setDropdownOpen(isOpen) {
50
+ dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
51
+ action: isOpen ? _analytics.ACTION.OPENED : _analytics.ACTION.CLOSED,
52
+ actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR,
53
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.HIGHLIGHT,
54
+ eventType: _analytics.EVENT_TYPE.TRACK
55
+ });
56
+ setIsDropdownOpen(isOpen);
57
+ };
58
+ var toggleDropdown = function toggleDropdown() {
59
+ return setDropdownOpen(!isDropdownOpen);
60
+ };
61
+ var handleClick = function handleClick() {
62
+ setIsOpenedByKeyboard(false);
63
+ toggleDropdown();
64
+ };
65
+ var handleKeyDown = function handleKeyDown(event) {
66
+ if (event.key === 'Enter' || event.key === ' ') {
67
+ event.preventDefault();
68
+ setIsOpenedByKeyboard(true);
69
+ toggleDropdown();
70
+ }
71
+ };
72
+ var handleClickOutside = function handleClickOutside() {
73
+ if (isDropdownOpen) {
74
+ setDropdownOpen(false);
75
+ setIsOpenedByKeyboard(false);
76
+ }
77
+ };
78
+ var handleEscapeKeydown = function handleEscapeKeydown() {
79
+ if (isDropdownOpen) {
80
+ var _toolbarItemRef$curre;
81
+ setDropdownOpen(false);
82
+ setIsOpenedByKeyboard(false);
83
+ toolbarItemRef === null || toolbarItemRef === void 0 || (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 || _toolbarItemRef$curre.focus();
84
+ }
85
+ };
86
+ var handleColorChange = function handleColorChange(color) {
87
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
88
+ 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)({
89
+ color: color
90
+ }));
91
+ setDropdownOpen(false);
92
+ };
93
+
94
+ // Don't render the toolbar option while the plugin is initialising
95
+ if (!highlightState) {
96
+ return null;
97
+ }
98
+ var toolbarButtonLabel = formatMessage(_messages.highlightMessages.highlight);
99
+
100
+ // Get the design token for the active color (if it exists) to modify the toolbar
101
+ // icon, but show the nice rainbow if none is selected
102
+ var activeColorToken = highlightState.activeColor === _uiColor.REMOVE_HIGHLIGHT_COLOR ? null : (0, _editorPalette.hexToEditorTextBackgroundPaletteColor)(highlightState.activeColor);
103
+
104
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
105
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
106
+ var fitWidth = 242;
107
+ var _getSelectedRowAndCol = (0, _uiColor.getSelectedRowAndColumnFromPalette)(_uiColor.highlightColorPalette, highlightState.activeColor),
108
+ selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
109
+ selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
110
+ return (0, _react2.jsx)(_primitives.Flex, {
111
+ alignItems: "center"
112
+ }, (0, _react2.jsx)(_uiMenu.DropdownContainer, {
113
+ mountTo: popupsMountPoint,
114
+ boundariesElement: popupsBoundariesElement,
115
+ scrollableElement: popupsScrollableElement,
116
+ isOpen: isDropdownOpen && !highlightState.disabled,
117
+ handleClickOutside: handleClickOutside,
118
+ handleEscapeKeydown: handleEscapeKeydown,
119
+ zIndex: _editorSharedStyles.akEditorMenuZIndex,
120
+ fitWidth: fitWidth,
121
+ closeOnTab: true,
122
+ arrowKeyNavigationProviderOptions: {
123
+ type: _uiMenu.ArrowKeyNavigationType.COLOR,
124
+ selectedRowIndex: selectedRowIndex,
125
+ selectedColumnIndex: selectedColumnIndex,
126
+ isOpenedByKeyboard: isOpenedByKeyboard,
127
+ isPopupPositioned: true
128
+ },
129
+ trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
130
+ buttonId: _uiMenu.TOOLBAR_BUTTON.HIGHLIGHT,
131
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
132
+ disabled: disabled || highlightState.disabled,
133
+ selected: isDropdownOpen,
134
+ "aria-label": toolbarButtonLabel,
135
+ "aria-expanded": isDropdownOpen,
136
+ "aria-haspopup": true,
137
+ title: toolbarButtonLabel,
138
+ onClick: handleClick,
139
+ onKeyDown: handleKeyDown,
140
+ ref: toolbarItemRef,
141
+ iconBefore: (0, _react2.jsx)(_primitives.Flex, null, (0, _react2.jsx)(_EditorHighlightIcon.EditorHighlightIcon, {
142
+ selectedColor: activeColorToken,
143
+ disabled: highlightState.disabled
144
+ }), (0, _react2.jsx)("span", {
145
+ css: _styles.expandIconWrapperStyle
146
+ }, (0, _react2.jsx)(_chevronDown.default, {
147
+ label: ""
148
+ })))
149
+ })
150
+ }, (0, _react2.jsx)("div", {
151
+ "data-testid": "highlight-color-palette"
152
+ }, (0, _react2.jsx)(_uiColor.ColorPalette, {
153
+ onClick: function onClick(color) {
154
+ return handleColorChange(color);
155
+ },
156
+ selectedColor: highlightState.activeColor,
157
+ paletteOptions: {
158
+ palette: _uiColor.highlightColorPalette,
159
+ hexToPaletteColor: _editorPalette.hexToEditorTextBackgroundPaletteColor
160
+ }
161
+ }))), (0, _react2.jsx)("span", {
162
+ css: _styles.separatorStyles
163
+ }));
164
+ };
165
+ var ToolbarHighlightColorWithIntl = exports.ToolbarHighlightColorWithIntl = (0, _reactIntlNext.injectIntl)(ToolbarHighlightColor);
@@ -0,0 +1,27 @@
1
+ // import {
2
+ // ACTION,
3
+ // ACTION_SUBJECT,
4
+ // ACTION_SUBJECT_ID,
5
+ // EVENT_TYPE,
6
+ // } from '@atlaskit/editor-common/analytics';
7
+
8
+ import { HighlightPluginAction, highlightPluginKey } from '../pm-plugin';
9
+ export const changeColor = _editorAnalyticsAPI => ({
10
+ color
11
+ }) => ({
12
+ tr
13
+ }) => {
14
+ tr.setMeta(highlightPluginKey, {
15
+ type: HighlightPluginAction.CHANGE_COLOR,
16
+ color
17
+ });
18
+
19
+ // editorAnalyticsAPI?.attachAnalyticsEvent({
20
+ // action: ACTION.FORMATTED,
21
+ // actionSubject: ACTION_SUBJECT.TEXT,
22
+ // actionSubjectId: ACTION_SUBJECT_ID.HIGHLIGHT,
23
+ // eventType: EVENT_TYPE.TRACK,
24
+ // })(tr);
25
+
26
+ return tr;
27
+ };
@@ -0,0 +1 @@
1
+ export { changeColor } from './change-color';
@@ -1,30 +1,52 @@
1
+ import React from 'react';
1
2
  import { backgroundColor } from '@atlaskit/adf-schema';
3
+ import { changeColor } from './commands';
2
4
  import { createPlugin, highlightPluginKey } from './pm-plugin';
5
+ import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
3
6
  export const highlightPlugin = ({
4
7
  api
5
- }) => ({
6
- name: 'highlight',
7
- marks() {
8
- return [{
9
- name: 'backgroundColor',
10
- mark: backgroundColor
11
- }];
12
- },
13
- pmPlugins: () => [{
8
+ }) => {
9
+ var _api$analytics;
10
+ const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
11
+ return {
14
12
  name: 'highlight',
15
- plugin: () => createPlugin({
16
- api
13
+ commands: {
14
+ changeColor: changeColor(editorAnalyticsAPI)
15
+ },
16
+ marks() {
17
+ return [{
18
+ name: 'backgroundColor',
19
+ mark: backgroundColor
20
+ }];
21
+ },
22
+ pmPlugins: () => [{
23
+ name: 'highlight',
24
+ plugin: () => createPlugin({
25
+ api
26
+ })
27
+ }],
28
+ getSharedState(editorState) {
29
+ if (!editorState) {
30
+ return;
31
+ }
32
+ return highlightPluginKey.getState(editorState);
33
+ },
34
+ primaryToolbarComponent: ({
35
+ editorView,
36
+ popupsMountPoint,
37
+ popupsBoundariesElement,
38
+ popupsScrollableElement,
39
+ disabled,
40
+ isToolbarReducedSpacing,
41
+ dispatchAnalyticsEvent
42
+ }) => /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
43
+ popupsMountPoint: popupsMountPoint,
44
+ popupsBoundariesElement: popupsBoundariesElement,
45
+ popupsScrollableElement: popupsScrollableElement,
46
+ disabled: disabled,
47
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
48
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
49
+ pluginInjectionApi: api
17
50
  })
18
- }],
19
- getSharedState(editorState) {
20
- if (!editorState) {
21
- return;
22
- }
23
- return highlightPluginKey.getState(editorState);
24
- }
25
-
26
- // Add highlight toolbar button to primary toolbar
27
- // primaryToolbarComponent({ disabled }) {
28
- // TODO: Implement primary toolbar UI
29
- // },
30
- });
51
+ };
52
+ };
@@ -1,10 +1,38 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
2
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
4
  export const highlightPluginKey = new PluginKey('highlight');
5
+ const initialState = {
6
+ activeColor: REMOVE_HIGHLIGHT_COLOR,
7
+ disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
8
+ };
9
+ export let HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
10
+ HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
11
+ return HighlightPluginAction;
12
+ }({});
4
13
  export const createPlugin = ({
5
14
  api
6
15
  }) => {
7
16
  return new SafePlugin({
8
- key: highlightPluginKey
17
+ key: highlightPluginKey,
18
+ state: {
19
+ init: () => initialState,
20
+ apply: (tr, pluginState) => {
21
+ var _tr$getMeta;
22
+ const action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
23
+ switch (action) {
24
+ case HighlightPluginAction.CHANGE_COLOR:
25
+ const {
26
+ color
27
+ } = tr.getMeta(highlightPluginKey);
28
+ return {
29
+ ...pluginState,
30
+ activeColor: color
31
+ };
32
+ default:
33
+ return pluginState;
34
+ }
35
+ }
36
+ }
9
37
  });
10
38
  };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { SteppedRainbowIconDecoration } from '@atlaskit/editor-common/icons';
3
+ import EditFilledIcon from '@atlaskit/icon/glyph/edit-filled';
4
+ import { Box } from '@atlaskit/primitives';
5
+ export const EditorHighlightIcon = ({
6
+ disabled,
7
+ selectedColor
8
+ }) => /*#__PURE__*/React.createElement(Box, {
9
+ paddingInline: "space.050"
10
+ }, /*#__PURE__*/React.createElement(SteppedRainbowIconDecoration, {
11
+ selectedColor: selectedColor,
12
+ disabled: disabled,
13
+ icon: /*#__PURE__*/React.createElement(EditFilledIcon, {
14
+ size: "small",
15
+ label: ""
16
+ })
17
+ }));
@@ -0,0 +1,148 @@
1
+ /** @jsx jsx */
2
+ import React, { useRef, useState } from 'react';
3
+ import { jsx } from '@emotion/react';
4
+ import { injectIntl } from 'react-intl-next';
5
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
6
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
+ import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
8
+ import { expandIconWrapperStyle, separatorStyles } from '@atlaskit/editor-common/styles';
9
+ import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
10
+ import { ArrowKeyNavigationType, DropdownContainer as Dropdown, TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
11
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
12
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
13
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
14
+ import { Flex } from '@atlaskit/primitives';
15
+ import { changeColor } from '../commands';
16
+ import { EditorHighlightIcon } from './EditorHighlightIcon';
17
+ const ToolbarHighlightColor = ({
18
+ popupsMountPoint,
19
+ popupsBoundariesElement,
20
+ popupsScrollableElement,
21
+ isToolbarReducedSpacing,
22
+ dispatchAnalyticsEvent,
23
+ disabled,
24
+ pluginInjectionApi,
25
+ intl: {
26
+ formatMessage
27
+ }
28
+ }) => {
29
+ const toolbarItemRef = useRef(null);
30
+ const [isDropdownOpen, setIsDropdownOpen] = useState(false);
31
+ const [isOpenedByKeyboard, setIsOpenedByKeyboard] = useState(false);
32
+ const {
33
+ highlightState
34
+ } = useSharedPluginState(pluginInjectionApi, ['highlight']);
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.HIGHLIGHT,
40
+ eventType: EVENT_TYPE.TRACK
41
+ });
42
+ setIsDropdownOpen(isOpen);
43
+ };
44
+ const toggleDropdown = () => setDropdownOpen(!isDropdownOpen);
45
+ const handleClick = () => {
46
+ setIsOpenedByKeyboard(false);
47
+ toggleDropdown();
48
+ };
49
+ const handleKeyDown = event => {
50
+ if (event.key === 'Enter' || event.key === ' ') {
51
+ event.preventDefault();
52
+ setIsOpenedByKeyboard(true);
53
+ toggleDropdown();
54
+ }
55
+ };
56
+ const handleClickOutside = () => {
57
+ if (isDropdownOpen) {
58
+ setDropdownOpen(false);
59
+ setIsOpenedByKeyboard(false);
60
+ }
61
+ };
62
+ const handleEscapeKeydown = () => {
63
+ if (isDropdownOpen) {
64
+ var _toolbarItemRef$curre;
65
+ setDropdownOpen(false);
66
+ setIsOpenedByKeyboard(false);
67
+ toolbarItemRef === null || toolbarItemRef === void 0 ? void 0 : (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 ? void 0 : _toolbarItemRef$curre.focus();
68
+ }
69
+ };
70
+ const handleColorChange = color => {
71
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
72
+ 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)({
73
+ color
74
+ }));
75
+ setDropdownOpen(false);
76
+ };
77
+
78
+ // Don't render the toolbar option while the plugin is initialising
79
+ if (!highlightState) {
80
+ return null;
81
+ }
82
+ const toolbarButtonLabel = formatMessage(messages.highlight);
83
+
84
+ // Get the design token for the active color (if it exists) to modify the toolbar
85
+ // icon, but show the nice rainbow if none is selected
86
+ const activeColorToken = highlightState.activeColor === REMOVE_HIGHLIGHT_COLOR ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
87
+
88
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
89
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
90
+ const fitWidth = 242;
91
+ const {
92
+ selectedRowIndex,
93
+ selectedColumnIndex
94
+ } = getSelectedRowAndColumnFromPalette(highlightColorPalette, highlightState.activeColor);
95
+ return jsx(Flex, {
96
+ alignItems: "center"
97
+ }, jsx(Dropdown, {
98
+ mountTo: popupsMountPoint,
99
+ boundariesElement: popupsBoundariesElement,
100
+ scrollableElement: popupsScrollableElement,
101
+ isOpen: isDropdownOpen && !highlightState.disabled,
102
+ handleClickOutside: handleClickOutside,
103
+ handleEscapeKeydown: handleEscapeKeydown,
104
+ zIndex: akEditorMenuZIndex,
105
+ fitWidth: fitWidth,
106
+ closeOnTab: true,
107
+ arrowKeyNavigationProviderOptions: {
108
+ type: ArrowKeyNavigationType.COLOR,
109
+ selectedRowIndex,
110
+ selectedColumnIndex,
111
+ isOpenedByKeyboard,
112
+ isPopupPositioned: true
113
+ },
114
+ trigger: jsx(ToolbarButton, {
115
+ buttonId: TOOLBAR_BUTTON.HIGHLIGHT,
116
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
117
+ disabled: disabled || highlightState.disabled,
118
+ selected: isDropdownOpen,
119
+ "aria-label": toolbarButtonLabel,
120
+ "aria-expanded": isDropdownOpen,
121
+ "aria-haspopup": true,
122
+ title: toolbarButtonLabel,
123
+ onClick: handleClick,
124
+ onKeyDown: handleKeyDown,
125
+ ref: toolbarItemRef,
126
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
127
+ selectedColor: activeColorToken,
128
+ disabled: highlightState.disabled
129
+ }), jsx("span", {
130
+ css: expandIconWrapperStyle
131
+ }, jsx(ExpandIcon, {
132
+ label: ""
133
+ })))
134
+ })
135
+ }, jsx("div", {
136
+ "data-testid": "highlight-color-palette"
137
+ }, jsx(ColorPalette, {
138
+ onClick: color => handleColorChange(color),
139
+ selectedColor: highlightState.activeColor,
140
+ paletteOptions: {
141
+ palette: highlightColorPalette,
142
+ hexToPaletteColor: hexToEditorTextBackgroundPaletteColor
143
+ }
144
+ }))), jsx("span", {
145
+ css: separatorStyles
146
+ }));
147
+ };
148
+ export const ToolbarHighlightColorWithIntl = injectIntl(ToolbarHighlightColor);
@@ -0,0 +1,29 @@
1
+ // import {
2
+ // ACTION,
3
+ // ACTION_SUBJECT,
4
+ // ACTION_SUBJECT_ID,
5
+ // EVENT_TYPE,
6
+ // } from '@atlaskit/editor-common/analytics';
7
+
8
+ import { HighlightPluginAction, highlightPluginKey } from '../pm-plugin';
9
+ export var changeColor = function changeColor(_editorAnalyticsAPI) {
10
+ return function (_ref) {
11
+ var color = _ref.color;
12
+ return function (_ref2) {
13
+ var tr = _ref2.tr;
14
+ tr.setMeta(highlightPluginKey, {
15
+ type: HighlightPluginAction.CHANGE_COLOR,
16
+ color: color
17
+ });
18
+
19
+ // editorAnalyticsAPI?.attachAnalyticsEvent({
20
+ // action: ACTION.FORMATTED,
21
+ // actionSubject: ACTION_SUBJECT.TEXT,
22
+ // actionSubjectId: ACTION_SUBJECT_ID.HIGHLIGHT,
23
+ // eventType: EVENT_TYPE.TRACK,
24
+ // })(tr);
25
+
26
+ return tr;
27
+ };
28
+ };
29
+ };
@@ -0,0 +1 @@
1
+ export { changeColor } from './change-color';
@@ -1,9 +1,17 @@
1
+ import React from 'react';
1
2
  import { backgroundColor } from '@atlaskit/adf-schema';
3
+ import { changeColor } from './commands';
2
4
  import { createPlugin, highlightPluginKey } from './pm-plugin';
5
+ import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
3
6
  export var highlightPlugin = function highlightPlugin(_ref) {
7
+ var _api$analytics;
4
8
  var api = _ref.api;
9
+ var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
5
10
  return {
6
11
  name: 'highlight',
12
+ commands: {
13
+ changeColor: changeColor(editorAnalyticsAPI)
14
+ },
7
15
  marks: function marks() {
8
16
  return [{
9
17
  name: 'backgroundColor',
@@ -25,9 +33,24 @@ export var highlightPlugin = function highlightPlugin(_ref) {
25
33
  return;
26
34
  }
27
35
  return highlightPluginKey.getState(editorState);
28
- } // Add highlight toolbar button to primary toolbar
29
- // primaryToolbarComponent({ disabled }) {
30
- // TODO: Implement primary toolbar UI
31
- // },
36
+ },
37
+ primaryToolbarComponent: function primaryToolbarComponent(_ref2) {
38
+ var editorView = _ref2.editorView,
39
+ popupsMountPoint = _ref2.popupsMountPoint,
40
+ popupsBoundariesElement = _ref2.popupsBoundariesElement,
41
+ popupsScrollableElement = _ref2.popupsScrollableElement,
42
+ disabled = _ref2.disabled,
43
+ isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
44
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
45
+ return /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
46
+ popupsMountPoint: popupsMountPoint,
47
+ popupsBoundariesElement: popupsBoundariesElement,
48
+ popupsScrollableElement: popupsScrollableElement,
49
+ disabled: disabled,
50
+ isToolbarReducedSpacing: isToolbarReducedSpacing,
51
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
52
+ pluginInjectionApi: api
53
+ });
54
+ }
32
55
  };
33
56
  };
@@ -1,9 +1,40 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ 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; }
1
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
+ import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
2
6
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
7
  export var highlightPluginKey = new PluginKey('highlight');
8
+ var initialState = {
9
+ activeColor: REMOVE_HIGHLIGHT_COLOR,
10
+ disabled: false // TODO: Should probably be true, but we can tackle it once we tackle disabled state
11
+ };
12
+ export var HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
13
+ HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
14
+ return HighlightPluginAction;
15
+ }({});
4
16
  export var createPlugin = function createPlugin(_ref) {
5
17
  var api = _ref.api;
6
18
  return new SafePlugin({
7
- key: highlightPluginKey
19
+ key: highlightPluginKey,
20
+ state: {
21
+ init: function init() {
22
+ return initialState;
23
+ },
24
+ apply: function apply(tr, pluginState) {
25
+ var _tr$getMeta;
26
+ var action = (_tr$getMeta = tr.getMeta(highlightPluginKey)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.type;
27
+ switch (action) {
28
+ case HighlightPluginAction.CHANGE_COLOR:
29
+ var _tr$getMeta2 = tr.getMeta(highlightPluginKey),
30
+ color = _tr$getMeta2.color;
31
+ return _objectSpread(_objectSpread({}, pluginState), {}, {
32
+ activeColor: color
33
+ });
34
+ default:
35
+ return pluginState;
36
+ }
37
+ }
38
+ }
8
39
  });
9
40
  };
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { SteppedRainbowIconDecoration } from '@atlaskit/editor-common/icons';
3
+ import EditFilledIcon from '@atlaskit/icon/glyph/edit-filled';
4
+ import { Box } from '@atlaskit/primitives';
5
+ export var EditorHighlightIcon = function EditorHighlightIcon(_ref) {
6
+ var disabled = _ref.disabled,
7
+ selectedColor = _ref.selectedColor;
8
+ return /*#__PURE__*/React.createElement(Box, {
9
+ paddingInline: "space.050"
10
+ }, /*#__PURE__*/React.createElement(SteppedRainbowIconDecoration, {
11
+ selectedColor: selectedColor,
12
+ disabled: disabled,
13
+ icon: /*#__PURE__*/React.createElement(EditFilledIcon, {
14
+ size: "small",
15
+ label: ""
16
+ })
17
+ }));
18
+ };
@@ -0,0 +1,154 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ /** @jsx jsx */
3
+ import React, { useRef, useState } from 'react';
4
+ import { jsx } from '@emotion/react';
5
+ import { injectIntl } from 'react-intl-next';
6
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
7
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
8
+ import { highlightMessages as messages } from '@atlaskit/editor-common/messages';
9
+ import { expandIconWrapperStyle, separatorStyles } from '@atlaskit/editor-common/styles';
10
+ import { ColorPalette, getSelectedRowAndColumnFromPalette, highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
11
+ import { ArrowKeyNavigationType, DropdownContainer as Dropdown, TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
12
+ import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
13
+ import { akEditorMenuZIndex } from '@atlaskit/editor-shared-styles';
14
+ import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
15
+ import { Flex } from '@atlaskit/primitives';
16
+ import { changeColor } from '../commands';
17
+ import { EditorHighlightIcon } from './EditorHighlightIcon';
18
+ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
19
+ var popupsMountPoint = _ref.popupsMountPoint,
20
+ popupsBoundariesElement = _ref.popupsBoundariesElement,
21
+ popupsScrollableElement = _ref.popupsScrollableElement,
22
+ isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
23
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
24
+ disabled = _ref.disabled,
25
+ pluginInjectionApi = _ref.pluginInjectionApi,
26
+ formatMessage = _ref.intl.formatMessage;
27
+ var toolbarItemRef = useRef(null);
28
+ var _useState = useState(false),
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];
36
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['highlight']),
37
+ highlightState = _useSharedPluginState.highlightState;
38
+ 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.HIGHLIGHT,
43
+ eventType: EVENT_TYPE.TRACK
44
+ });
45
+ setIsDropdownOpen(isOpen);
46
+ };
47
+ var toggleDropdown = function toggleDropdown() {
48
+ return setDropdownOpen(!isDropdownOpen);
49
+ };
50
+ var handleClick = function handleClick() {
51
+ setIsOpenedByKeyboard(false);
52
+ toggleDropdown();
53
+ };
54
+ var handleKeyDown = function handleKeyDown(event) {
55
+ if (event.key === 'Enter' || event.key === ' ') {
56
+ event.preventDefault();
57
+ setIsOpenedByKeyboard(true);
58
+ toggleDropdown();
59
+ }
60
+ };
61
+ var handleClickOutside = function handleClickOutside() {
62
+ if (isDropdownOpen) {
63
+ setDropdownOpen(false);
64
+ setIsOpenedByKeyboard(false);
65
+ }
66
+ };
67
+ var handleEscapeKeydown = function handleEscapeKeydown() {
68
+ if (isDropdownOpen) {
69
+ var _toolbarItemRef$curre;
70
+ setDropdownOpen(false);
71
+ setIsOpenedByKeyboard(false);
72
+ toolbarItemRef === null || toolbarItemRef === void 0 || (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 || _toolbarItemRef$curre.focus();
73
+ }
74
+ };
75
+ var handleColorChange = function handleColorChange(color) {
76
+ var _pluginInjectionApi$c, _pluginInjectionApi$a;
77
+ 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)({
78
+ color: color
79
+ }));
80
+ setDropdownOpen(false);
81
+ };
82
+
83
+ // Don't render the toolbar option while the plugin is initialising
84
+ if (!highlightState) {
85
+ return null;
86
+ }
87
+ var toolbarButtonLabel = formatMessage(messages.highlight);
88
+
89
+ // Get the design token for the active color (if it exists) to modify the toolbar
90
+ // icon, but show the nice rainbow if none is selected
91
+ var activeColorToken = highlightState.activeColor === REMOVE_HIGHLIGHT_COLOR ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
92
+
93
+ // pixels, used to determine where to horizontally position the dropdown when space is limited
94
+ // this should reflect the width of the dropdown when fully populated with colors, including translations due to layering
95
+ var fitWidth = 242;
96
+ var _getSelectedRowAndCol = getSelectedRowAndColumnFromPalette(highlightColorPalette, highlightState.activeColor),
97
+ selectedRowIndex = _getSelectedRowAndCol.selectedRowIndex,
98
+ selectedColumnIndex = _getSelectedRowAndCol.selectedColumnIndex;
99
+ return jsx(Flex, {
100
+ alignItems: "center"
101
+ }, jsx(Dropdown, {
102
+ mountTo: popupsMountPoint,
103
+ boundariesElement: popupsBoundariesElement,
104
+ scrollableElement: popupsScrollableElement,
105
+ isOpen: isDropdownOpen && !highlightState.disabled,
106
+ handleClickOutside: handleClickOutside,
107
+ handleEscapeKeydown: handleEscapeKeydown,
108
+ zIndex: akEditorMenuZIndex,
109
+ fitWidth: fitWidth,
110
+ closeOnTab: true,
111
+ arrowKeyNavigationProviderOptions: {
112
+ type: ArrowKeyNavigationType.COLOR,
113
+ selectedRowIndex: selectedRowIndex,
114
+ selectedColumnIndex: selectedColumnIndex,
115
+ isOpenedByKeyboard: isOpenedByKeyboard,
116
+ isPopupPositioned: true
117
+ },
118
+ trigger: jsx(ToolbarButton, {
119
+ buttonId: TOOLBAR_BUTTON.HIGHLIGHT,
120
+ spacing: isToolbarReducedSpacing ? 'none' : 'default',
121
+ disabled: disabled || highlightState.disabled,
122
+ selected: isDropdownOpen,
123
+ "aria-label": toolbarButtonLabel,
124
+ "aria-expanded": isDropdownOpen,
125
+ "aria-haspopup": true,
126
+ title: toolbarButtonLabel,
127
+ onClick: handleClick,
128
+ onKeyDown: handleKeyDown,
129
+ ref: toolbarItemRef,
130
+ iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
131
+ selectedColor: activeColorToken,
132
+ disabled: highlightState.disabled
133
+ }), jsx("span", {
134
+ css: expandIconWrapperStyle
135
+ }, jsx(ExpandIcon, {
136
+ label: ""
137
+ })))
138
+ })
139
+ }, jsx("div", {
140
+ "data-testid": "highlight-color-palette"
141
+ }, jsx(ColorPalette, {
142
+ onClick: function onClick(color) {
143
+ return handleColorChange(color);
144
+ },
145
+ selectedColor: highlightState.activeColor,
146
+ paletteOptions: {
147
+ palette: highlightColorPalette,
148
+ hexToPaletteColor: hexToEditorTextBackgroundPaletteColor
149
+ }
150
+ }))), jsx("span", {
151
+ css: separatorStyles
152
+ }));
153
+ };
154
+ export var ToolbarHighlightColorWithIntl = injectIntl(ToolbarHighlightColor);
@@ -0,0 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
3
+ export declare const changeColor: (_editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ color }: {
4
+ color: string;
5
+ }) => EditorCommand;
@@ -0,0 +1 @@
1
+ export { changeColor } from './change-color';
@@ -1,2 +1,3 @@
1
1
  export { highlightPlugin } from './plugin';
2
2
  export type { HighlightPlugin } from './plugin';
3
+ export type { HighlightPluginState } from './pm-plugin';
@@ -2,9 +2,14 @@ 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
4
  import type { HighlightPlugin } from './plugin';
5
- export interface HighlightPluginState {
6
- }
7
5
  export declare const highlightPluginKey: PluginKey<HighlightPluginState>;
6
+ export type HighlightPluginState = {
7
+ activeColor: string;
8
+ disabled: boolean;
9
+ };
10
+ export declare enum HighlightPluginAction {
11
+ CHANGE_COLOR = 0
12
+ }
8
13
  export declare const createPlugin: ({ api, }: {
9
14
  api: ExtractInjectionAPI<HighlightPlugin> | undefined;
10
- }) => SafePlugin<any>;
15
+ }) => SafePlugin<HighlightPluginState>;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ type EditorHighlightIconProps = {
3
+ disabled: boolean;
4
+ selectedColor?: string | null;
5
+ };
6
+ export declare const EditorHighlightIcon: ({ disabled, selectedColor, }: EditorHighlightIconProps) => JSX.Element;
7
+ export {};
@@ -0,0 +1,25 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import type { WrappedComponentProps } from 'react-intl-next';
4
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
5
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
+ import type { HighlightPlugin } from '../plugin';
7
+ export declare const ToolbarHighlightColorWithIntl: React.FC<import("react-intl-next").WithIntlProps<{
8
+ popupsMountPoint?: HTMLElement | undefined;
9
+ popupsBoundariesElement?: HTMLElement | undefined;
10
+ popupsScrollableElement?: HTMLElement | undefined;
11
+ disabled: boolean;
12
+ isToolbarReducedSpacing: boolean;
13
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
14
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
15
+ } & WrappedComponentProps>> & {
16
+ WrappedComponent: React.ComponentType<{
17
+ popupsMountPoint?: HTMLElement | undefined;
18
+ popupsBoundariesElement?: HTMLElement | undefined;
19
+ popupsScrollableElement?: HTMLElement | undefined;
20
+ disabled: boolean;
21
+ isToolbarReducedSpacing: boolean;
22
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
23
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
24
+ } & WrappedComponentProps>;
25
+ };
@@ -0,0 +1,5 @@
1
+ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
3
+ export declare const changeColor: (_editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ color }: {
4
+ color: string;
5
+ }) => EditorCommand;
@@ -0,0 +1 @@
1
+ export { changeColor } from './change-color';
@@ -1,2 +1,3 @@
1
1
  export { highlightPlugin } from './plugin';
2
2
  export type { HighlightPlugin } from './plugin';
3
+ export type { HighlightPluginState } from './pm-plugin';
@@ -2,9 +2,14 @@ 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
4
  import type { HighlightPlugin } from './plugin';
5
- export interface HighlightPluginState {
6
- }
7
5
  export declare const highlightPluginKey: PluginKey<HighlightPluginState>;
6
+ export type HighlightPluginState = {
7
+ activeColor: string;
8
+ disabled: boolean;
9
+ };
10
+ export declare enum HighlightPluginAction {
11
+ CHANGE_COLOR = 0
12
+ }
8
13
  export declare const createPlugin: ({ api, }: {
9
14
  api: ExtractInjectionAPI<HighlightPlugin> | undefined;
10
- }) => SafePlugin<any>;
15
+ }) => SafePlugin<HighlightPluginState>;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ type EditorHighlightIconProps = {
3
+ disabled: boolean;
4
+ selectedColor?: string | null;
5
+ };
6
+ export declare const EditorHighlightIcon: ({ disabled, selectedColor, }: EditorHighlightIconProps) => JSX.Element;
7
+ export {};
@@ -0,0 +1,25 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import type { WrappedComponentProps } from 'react-intl-next';
4
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
5
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
+ import type { HighlightPlugin } from '../plugin';
7
+ export declare const ToolbarHighlightColorWithIntl: React.FC<import("react-intl-next").WithIntlProps<{
8
+ popupsMountPoint?: HTMLElement | undefined;
9
+ popupsBoundariesElement?: HTMLElement | undefined;
10
+ popupsScrollableElement?: HTMLElement | undefined;
11
+ disabled: boolean;
12
+ isToolbarReducedSpacing: boolean;
13
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
14
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
15
+ } & WrappedComponentProps>> & {
16
+ WrappedComponent: React.ComponentType<{
17
+ popupsMountPoint?: HTMLElement | undefined;
18
+ popupsBoundariesElement?: HTMLElement | undefined;
19
+ popupsScrollableElement?: HTMLElement | undefined;
20
+ disabled: boolean;
21
+ isToolbarReducedSpacing: boolean;
22
+ dispatchAnalyticsEvent?: DispatchAnalyticsEvent | undefined;
23
+ pluginInjectionApi: ExtractInjectionAPI<HighlightPlugin> | undefined;
24
+ } & WrappedComponentProps>;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-highlight",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Highlight plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,17 +39,23 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@atlaskit/adf-schema": "^36.1.0",
42
- "@atlaskit/editor-common": "^79.2.0",
42
+ "@atlaskit/editor-common": "^80.0.0",
43
+ "@atlaskit/editor-palette": "1.6.0",
43
44
  "@atlaskit/editor-plugin-analytics": "^1.1.0",
44
45
  "@atlaskit/editor-plugin-text-formatting": "^1.4.0",
45
46
  "@atlaskit/editor-prosemirror": "4.0.1",
46
- "@babel/runtime": "^7.0.0"
47
+ "@atlaskit/editor-shared-styles": "^2.10.0",
48
+ "@atlaskit/icon": "^22.1.0",
49
+ "@atlaskit/primitives": "^6.0.0",
50
+ "@babel/runtime": "^7.0.0",
51
+ "@emotion/react": "^11.7.1"
47
52
  },
48
53
  "peerDependencies": {
49
- "react": "^16.8.0"
54
+ "react": "^16.8.0",
55
+ "react-intl-next": "npm:react-intl@^5.18.1"
50
56
  },
51
57
  "devDependencies": {
52
- "@atlaskit/tokens": "^1.46.0",
58
+ "@atlaskit/tokens": "^1.48.0",
53
59
  "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
54
60
  "typescript": "~5.4.2"
55
61
  },