@atlaskit/editor-plugin-text-color 6.1.2 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @atlaskit/editor-plugin-text-color
2
2
 
3
+ ## 6.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`872bd8d576773`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/872bd8d576773) -
8
+ [ux] ED-29272 Add missing tooltip and shortcut for TextColorDropdownMenu
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 6.1.2
4
15
 
5
16
  ### Patch Changes
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.togglePalette = exports.setPalette = void 0;
7
+ var _main = require("../pm-plugins/main");
8
+ var togglePalette = exports.togglePalette = function togglePalette(api) {
9
+ return function (_ref) {
10
+ var tr = _ref.tr;
11
+ var pluginState = api === null || api === void 0 ? void 0 : api.textColor.sharedState.currentState();
12
+ var isPaletteOpen = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPaletteOpen;
13
+ tr.setMeta(_main.pluginKey, {
14
+ action: _main.ACTIONS.SET_PALETTE,
15
+ isPaletteOpen: !isPaletteOpen
16
+ });
17
+ return tr;
18
+ };
19
+ };
20
+ var setPalette = exports.setPalette = function setPalette(isPaletteOpen) {
21
+ return function (_ref2) {
22
+ var tr = _ref2.tr;
23
+ tr.setMeta(_main.pluginKey, {
24
+ action: _main.ACTIONS.SET_PALETTE,
25
+ isPaletteOpen: isPaletteOpen
26
+ });
27
+ return tr;
28
+ };
29
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.keymapPlugin = keymapPlugin;
7
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
8
+ var _palette = require("../editor-commands/palette");
9
+ function keymapPlugin(_ref) {
10
+ var api = _ref.api;
11
+ var list = {};
12
+ if (_keymaps.toggleHighlightPalette.common) {
13
+ (0, _keymaps.bindKeymapWithEditorCommand)(_keymaps.toggleHighlightPalette.common, (0, _palette.togglePalette)(api), list);
14
+ }
15
+ return (0, _keymaps.keymap)(list);
16
+ }
@@ -28,7 +28,8 @@ function createInitialPluginState(editorState, pluginConfig) {
28
28
  color: (0, _color.getActiveColor)(editorState),
29
29
  disabled: (0, _disabled.getDisabledState)(editorState),
30
30
  palette: palette,
31
- defaultColor: defaultColor.color
31
+ defaultColor: defaultColor.color,
32
+ isPaletteOpen: false
32
33
  };
33
34
  return state;
34
35
  }
@@ -36,6 +37,7 @@ var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
36
37
  ACTIONS[ACTIONS["RESET_COLOR"] = 0] = "RESET_COLOR";
37
38
  ACTIONS[ACTIONS["SET_COLOR"] = 1] = "SET_COLOR";
38
39
  ACTIONS[ACTIONS["DISABLE"] = 2] = "DISABLE";
40
+ ACTIONS[ACTIONS["SET_PALETTE"] = 3] = "SET_PALETTE";
39
41
  return ACTIONS;
40
42
  }({});
41
43
  var pluginKey = exports.pluginKey = new _state.PluginKey('textColorPlugin');
@@ -58,7 +60,8 @@ function createPlugin(dispatch, pluginConfig) {
58
60
  case ACTIONS.SET_COLOR:
59
61
  nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
60
62
  color: meta.color,
61
- disabled: false
63
+ disabled: false,
64
+ isPaletteOpen: false
62
65
  });
63
66
  break;
64
67
  case ACTIONS.DISABLE:
@@ -66,13 +69,18 @@ function createPlugin(dispatch, pluginConfig) {
66
69
  disabled: true
67
70
  });
68
71
  break;
72
+ case ACTIONS.SET_PALETTE:
73
+ nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
74
+ isPaletteOpen: meta.isPaletteOpen
75
+ });
76
+ break;
69
77
  default:
70
78
  nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
71
79
  color: (0, _color.getActiveColor)(newState),
72
80
  disabled: (0, _disabled.getDisabledState)(newState)
73
81
  });
74
82
  }
75
- if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled) {
83
+ if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled || pluginState && pluginState.isPaletteOpen !== nextState.isPaletteOpen) {
76
84
  dispatch(pluginKey, nextState);
77
85
  return nextState;
78
86
  }
@@ -8,9 +8,12 @@ exports.textColorPlugin = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _adfSchema = require("@atlaskit/adf-schema");
10
10
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
11
12
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
12
13
  var _changeColor2 = require("./editor-commands/change-color");
14
+ var _palette = require("./editor-commands/palette");
13
15
  var _changeColor3 = require("./pm-plugins/commands/change-color");
16
+ var _keymap = require("./pm-plugins/keymap");
14
17
  var _main = require("./pm-plugins/main");
15
18
  var _FloatingToolbarComponent = require("./ui/FloatingToolbarComponent");
16
19
  var _PrimaryToolbarComponent = require("./ui/PrimaryToolbarComponent");
@@ -70,12 +73,25 @@ var textColorPlugin = exports.textColorPlugin = function textColorPlugin(_ref) {
70
73
  }];
71
74
  },
72
75
  pmPlugins: function pmPlugins() {
73
- return [{
76
+ return (0, _experiments.editorExperiment)('platform_editor_toolbar_aifc', true) && (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? [{
74
77
  name: 'textColor',
75
78
  plugin: function plugin(_ref3) {
76
79
  var dispatch = _ref3.dispatch;
77
80
  return (0, _main.createPlugin)(dispatch, pluginConfig(textColorConfig));
78
81
  }
82
+ }, {
83
+ name: 'textColorKeymap',
84
+ plugin: function plugin() {
85
+ return (0, _keymap.keymapPlugin)({
86
+ api: api
87
+ });
88
+ }
89
+ }] : [{
90
+ name: 'textColor',
91
+ plugin: function plugin(_ref4) {
92
+ var dispatch = _ref4.dispatch;
93
+ return (0, _main.createPlugin)(dispatch, pluginConfig(textColorConfig));
94
+ }
79
95
  }];
80
96
  },
81
97
  getSharedState: function getSharedState(editorState) {
@@ -93,6 +109,9 @@ var textColorPlugin = exports.textColorPlugin = function textColorPlugin(_ref) {
93
109
  commands: {
94
110
  changeColor: function changeColor(color, inputMethod) {
95
111
  return (0, _changeColor2.changeColor)(color, api, inputMethod);
112
+ },
113
+ setPalette: function setPalette(isPaletteOpen) {
114
+ return (0, _palette.setPalette)(isPaletteOpen);
96
115
  }
97
116
  },
98
117
  pluginsOptions: !isToolbarAIFCEnabled ? {
@@ -1,21 +1,23 @@
1
1
  /* TextColorHighlightMenu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  "use strict";
3
3
 
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.TextColorHighlightMenu = void 0;
9
9
  require("./TextColorHighlightMenu.compiled.css");
10
10
  var _runtime = require("@compiled/react/runtime");
11
- var _react = _interopRequireDefault(require("react"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
12
  var _reactIntlNext = require("react-intl-next");
13
+ var _keymaps = require("@atlaskit/editor-common/keymaps");
13
14
  var _messages = require("@atlaskit/editor-common/messages");
14
15
  var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
15
16
  var _editorPalette = require("@atlaskit/editor-palette");
16
17
  var _editorToolbar = require("@atlaskit/editor-toolbar");
17
18
  var _compiled = require("@atlaskit/primitives/compiled");
18
19
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
20
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
19
21
  var styles = {
20
22
  menu: "_1rjcv77o _18zru2gc"
21
23
  };
@@ -26,6 +28,7 @@ var getIconColor = function getIconColor(textColor, defaultColor, highlightColor
26
28
  return (0, _editorPalette.hexToEditorTextPaletteColor)(textColor) || "var(--ds-text, #172B4D)";
27
29
  };
28
30
  var TextColorHighlightMenu = exports.TextColorHighlightMenu = function TextColorHighlightMenu(_ref) {
31
+ var _api$textColor2;
29
32
  var children = _ref.children,
30
33
  api = _ref.api;
31
34
  var isHighlightPluginExisted = !!(api !== null && api !== void 0 && api.highlight);
@@ -38,11 +41,30 @@ var TextColorHighlightMenu = exports.TextColorHighlightMenu = function TextColor
38
41
  var _useIntl = (0, _reactIntlNext.useIntl)(),
39
42
  formatMessage = _useIntl.formatMessage;
40
43
  var defaultColor = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textColor.defaultColor');
44
+ var isPaletteOpen = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'textColor.isPaletteOpen');
45
+ var setIsPaletteOpen = (0, _react.useCallback)(function (isOpen) {
46
+ var _api$textColor;
47
+ if (api !== null && api !== void 0 && (_api$textColor = api.textColor) !== null && _api$textColor !== void 0 && (_api$textColor = _api$textColor.commands) !== null && _api$textColor !== void 0 && _api$textColor.setPalette) {
48
+ api.core.actions.execute(function (_ref2) {
49
+ var tr = _ref2.tr;
50
+ api.textColor.commands.setPalette(isOpen)({
51
+ tr: tr
52
+ });
53
+ return tr;
54
+ });
55
+ }
56
+ }, [api === null || api === void 0 || (_api$textColor2 = api.textColor) === null || _api$textColor2 === void 0 ? void 0 : _api$textColor2.commands, api === null || api === void 0 ? void 0 : api.core.actions]);
41
57
  var iconColor = getIconColor(textColor, defaultColor, highlightColor);
42
58
  var highlightColorIcon = highlightColor ? highlightColor : (0, _editorToolbar.getContrastingBackgroundColor)(iconColor);
43
59
  return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarTooltip, {
44
- content: formatMessage(isHighlightPluginExisted ? _messages.textColorMessages.textColorHighlightTooltip : _messages.textColorMessages.textColorTooltip)
45
- }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenuProvider, null, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenu, {
60
+ content: /*#__PURE__*/_react.default.createElement(_keymaps.ToolTipContent, {
61
+ description: formatMessage(isHighlightPluginExisted ? _messages.textColorMessages.textColorHighlightTooltip : _messages.textColorMessages.textColorTooltip),
62
+ keymap: _keymaps.toggleHighlightPalette
63
+ })
64
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenuProvider, {
65
+ isOpen: (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? isPaletteOpen : undefined,
66
+ setIsOpen: (0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? setIsPaletteOpen : undefined
67
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownMenu, {
46
68
  iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarColorSwatch, {
47
69
  highlightColor: highlightColorIcon
48
70
  }, /*#__PURE__*/_react.default.createElement(_editorToolbar.TextColorIcon, {
@@ -0,0 +1,21 @@
1
+ import { pluginKey, ACTIONS } from '../pm-plugins/main';
2
+ export const togglePalette = api => ({
3
+ tr
4
+ }) => {
5
+ const pluginState = api === null || api === void 0 ? void 0 : api.textColor.sharedState.currentState();
6
+ const isPaletteOpen = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPaletteOpen;
7
+ tr.setMeta(pluginKey, {
8
+ action: ACTIONS.SET_PALETTE,
9
+ isPaletteOpen: !isPaletteOpen
10
+ });
11
+ return tr;
12
+ };
13
+ export const setPalette = isPaletteOpen => ({
14
+ tr
15
+ }) => {
16
+ tr.setMeta(pluginKey, {
17
+ action: ACTIONS.SET_PALETTE,
18
+ isPaletteOpen
19
+ });
20
+ return tr;
21
+ };
@@ -0,0 +1,11 @@
1
+ import { bindKeymapWithEditorCommand, keymap, toggleHighlightPalette } from '@atlaskit/editor-common/keymaps';
2
+ import { togglePalette } from '../editor-commands/palette';
3
+ export function keymapPlugin({
4
+ api
5
+ }) {
6
+ const list = {};
7
+ if (toggleHighlightPalette.common) {
8
+ bindKeymapWithEditorCommand(toggleHighlightPalette.common, togglePalette(api), list);
9
+ }
10
+ return keymap(list);
11
+ }
@@ -15,7 +15,8 @@ function createInitialPluginState(editorState, pluginConfig) {
15
15
  color: getActiveColor(editorState),
16
16
  disabled: getDisabledState(editorState),
17
17
  palette,
18
- defaultColor: defaultColor.color
18
+ defaultColor: defaultColor.color,
19
+ isPaletteOpen: false
19
20
  };
20
21
  return state;
21
22
  }
@@ -23,6 +24,7 @@ export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
23
24
  ACTIONS[ACTIONS["RESET_COLOR"] = 0] = "RESET_COLOR";
24
25
  ACTIONS[ACTIONS["SET_COLOR"] = 1] = "SET_COLOR";
25
26
  ACTIONS[ACTIONS["DISABLE"] = 2] = "DISABLE";
27
+ ACTIONS[ACTIONS["SET_PALETTE"] = 3] = "SET_PALETTE";
26
28
  return ACTIONS;
27
29
  }({});
28
30
  export const pluginKey = new PluginKey('textColorPlugin');
@@ -47,7 +49,8 @@ export function createPlugin(dispatch, pluginConfig) {
47
49
  nextState = {
48
50
  ...pluginState,
49
51
  color: meta.color,
50
- disabled: false
52
+ disabled: false,
53
+ isPaletteOpen: false
51
54
  };
52
55
  break;
53
56
  case ACTIONS.DISABLE:
@@ -56,6 +59,12 @@ export function createPlugin(dispatch, pluginConfig) {
56
59
  disabled: true
57
60
  };
58
61
  break;
62
+ case ACTIONS.SET_PALETTE:
63
+ nextState = {
64
+ ...pluginState,
65
+ isPaletteOpen: meta.isPaletteOpen
66
+ };
67
+ break;
59
68
  default:
60
69
  nextState = {
61
70
  ...pluginState,
@@ -63,7 +72,7 @@ export function createPlugin(dispatch, pluginConfig) {
63
72
  disabled: getDisabledState(newState)
64
73
  };
65
74
  }
66
- if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled) {
75
+ if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled || pluginState && pluginState.isPaletteOpen !== nextState.isPaletteOpen) {
67
76
  dispatch(pluginKey, nextState);
68
77
  return nextState;
69
78
  }
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
2
  import { textColor } from '@atlaskit/adf-schema';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
6
  import { changeColor as changeColorCommand } from './editor-commands/change-color';
7
+ import { setPalette } from './editor-commands/palette';
6
8
  import { changeColor } from './pm-plugins/commands/change-color';
9
+ import { keymapPlugin } from './pm-plugins/keymap';
7
10
  import { createPlugin, pluginKey as textColorPluginKey } from './pm-plugins/main';
8
11
  import { FloatingToolbarComponent } from './ui/FloatingToolbarComponent';
9
12
  import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
@@ -65,7 +68,17 @@ export const textColorPlugin = ({
65
68
  }];
66
69
  },
67
70
  pmPlugins() {
68
- return [{
71
+ return editorExperiment('platform_editor_toolbar_aifc', true) && expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? [{
72
+ name: 'textColor',
73
+ plugin: ({
74
+ dispatch
75
+ }) => createPlugin(dispatch, pluginConfig(textColorConfig))
76
+ }, {
77
+ name: 'textColorKeymap',
78
+ plugin: () => keymapPlugin({
79
+ api
80
+ })
81
+ }] : [{
69
82
  name: 'textColor',
70
83
  plugin: ({
71
84
  dispatch
@@ -87,6 +100,9 @@ export const textColorPlugin = ({
87
100
  commands: {
88
101
  changeColor: (color, inputMethod) => {
89
102
  return changeColorCommand(color, api, inputMethod);
103
+ },
104
+ setPalette: isPaletteOpen => {
105
+ return setPalette(isPaletteOpen);
90
106
  }
91
107
  },
92
108
  pluginsOptions: !isToolbarAIFCEnabled ? {
@@ -1,8 +1,9 @@
1
1
  /* TextColorHighlightMenu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  import "./TextColorHighlightMenu.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React from 'react';
4
+ import React, { useCallback } from 'react';
5
5
  import { useIntl } from 'react-intl-next';
6
+ import { toggleHighlightPalette, ToolTipContent } from '@atlaskit/editor-common/keymaps';
6
7
  import { textColorMessages as messages } from '@atlaskit/editor-common/messages';
7
8
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
9
  import { hexToEditorTextPaletteColor } from '@atlaskit/editor-palette';
@@ -22,6 +23,7 @@ export const TextColorHighlightMenu = ({
22
23
  children,
23
24
  api
24
25
  }) => {
26
+ var _api$textColor2;
25
27
  const isHighlightPluginExisted = !!(api !== null && api !== void 0 && api.highlight);
26
28
  const isTextColorDisabled = useSharedPluginStateSelector(api, 'textColor.disabled');
27
29
  const {
@@ -34,11 +36,31 @@ export const TextColorHighlightMenu = ({
34
36
  formatMessage
35
37
  } = useIntl();
36
38
  const defaultColor = useSharedPluginStateSelector(api, 'textColor.defaultColor');
39
+ const isPaletteOpen = useSharedPluginStateSelector(api, 'textColor.isPaletteOpen');
40
+ const setIsPaletteOpen = useCallback(isOpen => {
41
+ var _api$textColor, _api$textColor$comman;
42
+ if (api !== null && api !== void 0 && (_api$textColor = api.textColor) !== null && _api$textColor !== void 0 && (_api$textColor$comman = _api$textColor.commands) !== null && _api$textColor$comman !== void 0 && _api$textColor$comman.setPalette) {
43
+ api.core.actions.execute(({
44
+ tr
45
+ }) => {
46
+ api.textColor.commands.setPalette(isOpen)({
47
+ tr
48
+ });
49
+ return tr;
50
+ });
51
+ }
52
+ }, [api === null || api === void 0 ? void 0 : (_api$textColor2 = api.textColor) === null || _api$textColor2 === void 0 ? void 0 : _api$textColor2.commands, api === null || api === void 0 ? void 0 : api.core.actions]);
37
53
  const iconColor = getIconColor(textColor, defaultColor, highlightColor);
38
54
  const highlightColorIcon = highlightColor ? highlightColor : getContrastingBackgroundColor(iconColor);
39
55
  return /*#__PURE__*/React.createElement(ToolbarTooltip, {
40
- content: formatMessage(isHighlightPluginExisted ? messages.textColorHighlightTooltip : messages.textColorTooltip)
41
- }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, null, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
56
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
57
+ description: formatMessage(isHighlightPluginExisted ? messages.textColorHighlightTooltip : messages.textColorTooltip),
58
+ keymap: toggleHighlightPalette
59
+ })
60
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
61
+ isOpen: expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? isPaletteOpen : undefined,
62
+ setIsOpen: expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? setIsPaletteOpen : undefined
63
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
42
64
  iconBefore: /*#__PURE__*/React.createElement(ToolbarColorSwatch, {
43
65
  highlightColor: highlightColorIcon
44
66
  }, /*#__PURE__*/React.createElement(TextColorIcon, {
@@ -0,0 +1,23 @@
1
+ import { pluginKey, ACTIONS } from '../pm-plugins/main';
2
+ export var togglePalette = function togglePalette(api) {
3
+ return function (_ref) {
4
+ var tr = _ref.tr;
5
+ var pluginState = api === null || api === void 0 ? void 0 : api.textColor.sharedState.currentState();
6
+ var isPaletteOpen = pluginState === null || pluginState === void 0 ? void 0 : pluginState.isPaletteOpen;
7
+ tr.setMeta(pluginKey, {
8
+ action: ACTIONS.SET_PALETTE,
9
+ isPaletteOpen: !isPaletteOpen
10
+ });
11
+ return tr;
12
+ };
13
+ };
14
+ export var setPalette = function setPalette(isPaletteOpen) {
15
+ return function (_ref2) {
16
+ var tr = _ref2.tr;
17
+ tr.setMeta(pluginKey, {
18
+ action: ACTIONS.SET_PALETTE,
19
+ isPaletteOpen: isPaletteOpen
20
+ });
21
+ return tr;
22
+ };
23
+ };
@@ -0,0 +1,10 @@
1
+ import { bindKeymapWithEditorCommand, keymap, toggleHighlightPalette } from '@atlaskit/editor-common/keymaps';
2
+ import { togglePalette } from '../editor-commands/palette';
3
+ export function keymapPlugin(_ref) {
4
+ var api = _ref.api;
5
+ var list = {};
6
+ if (toggleHighlightPalette.common) {
7
+ bindKeymapWithEditorCommand(toggleHighlightPalette.common, togglePalette(api), list);
8
+ }
9
+ return keymap(list);
10
+ }
@@ -19,7 +19,8 @@ function createInitialPluginState(editorState, pluginConfig) {
19
19
  color: getActiveColor(editorState),
20
20
  disabled: getDisabledState(editorState),
21
21
  palette: palette,
22
- defaultColor: defaultColor.color
22
+ defaultColor: defaultColor.color,
23
+ isPaletteOpen: false
23
24
  };
24
25
  return state;
25
26
  }
@@ -27,6 +28,7 @@ export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
27
28
  ACTIONS[ACTIONS["RESET_COLOR"] = 0] = "RESET_COLOR";
28
29
  ACTIONS[ACTIONS["SET_COLOR"] = 1] = "SET_COLOR";
29
30
  ACTIONS[ACTIONS["DISABLE"] = 2] = "DISABLE";
31
+ ACTIONS[ACTIONS["SET_PALETTE"] = 3] = "SET_PALETTE";
30
32
  return ACTIONS;
31
33
  }({});
32
34
  export var pluginKey = new PluginKey('textColorPlugin');
@@ -49,7 +51,8 @@ export function createPlugin(dispatch, pluginConfig) {
49
51
  case ACTIONS.SET_COLOR:
50
52
  nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
51
53
  color: meta.color,
52
- disabled: false
54
+ disabled: false,
55
+ isPaletteOpen: false
53
56
  });
54
57
  break;
55
58
  case ACTIONS.DISABLE:
@@ -57,13 +60,18 @@ export function createPlugin(dispatch, pluginConfig) {
57
60
  disabled: true
58
61
  });
59
62
  break;
63
+ case ACTIONS.SET_PALETTE:
64
+ nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
65
+ isPaletteOpen: meta.isPaletteOpen
66
+ });
67
+ break;
60
68
  default:
61
69
  nextState = _objectSpread(_objectSpread({}, pluginState), {}, {
62
70
  color: getActiveColor(newState),
63
71
  disabled: getDisabledState(newState)
64
72
  });
65
73
  }
66
- if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled) {
74
+ if (pluginState && pluginState.color !== nextState.color || pluginState && pluginState.disabled !== nextState.disabled || pluginState && pluginState.isPaletteOpen !== nextState.isPaletteOpen) {
67
75
  dispatch(pluginKey, nextState);
68
76
  return nextState;
69
77
  }
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
2
  import { textColor } from '@atlaskit/adf-schema';
3
3
  import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
6
  import { changeColor as changeColorCommand } from './editor-commands/change-color';
7
+ import { setPalette as _setPalette } from './editor-commands/palette';
6
8
  import { changeColor as _changeColor } from './pm-plugins/commands/change-color';
9
+ import { keymapPlugin } from './pm-plugins/keymap';
7
10
  import { createPlugin, pluginKey as textColorPluginKey } from './pm-plugins/main';
8
11
  import { FloatingToolbarComponent } from './ui/FloatingToolbarComponent';
9
12
  import { PrimaryToolbarComponent } from './ui/PrimaryToolbarComponent';
@@ -63,12 +66,25 @@ export var textColorPlugin = function textColorPlugin(_ref) {
63
66
  }];
64
67
  },
65
68
  pmPlugins: function pmPlugins() {
66
- return [{
69
+ return editorExperiment('platform_editor_toolbar_aifc', true) && expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? [{
67
70
  name: 'textColor',
68
71
  plugin: function plugin(_ref3) {
69
72
  var dispatch = _ref3.dispatch;
70
73
  return createPlugin(dispatch, pluginConfig(textColorConfig));
71
74
  }
75
+ }, {
76
+ name: 'textColorKeymap',
77
+ plugin: function plugin() {
78
+ return keymapPlugin({
79
+ api: api
80
+ });
81
+ }
82
+ }] : [{
83
+ name: 'textColor',
84
+ plugin: function plugin(_ref4) {
85
+ var dispatch = _ref4.dispatch;
86
+ return createPlugin(dispatch, pluginConfig(textColorConfig));
87
+ }
72
88
  }];
73
89
  },
74
90
  getSharedState: function getSharedState(editorState) {
@@ -86,6 +102,9 @@ export var textColorPlugin = function textColorPlugin(_ref) {
86
102
  commands: {
87
103
  changeColor: function changeColor(color, inputMethod) {
88
104
  return changeColorCommand(color, api, inputMethod);
105
+ },
106
+ setPalette: function setPalette(isPaletteOpen) {
107
+ return _setPalette(isPaletteOpen);
89
108
  }
90
109
  },
91
110
  pluginsOptions: !isToolbarAIFCEnabled ? {
@@ -1,8 +1,9 @@
1
1
  /* TextColorHighlightMenu.tsx generated by @compiled/babel-plugin v0.38.1 */
2
2
  import "./TextColorHighlightMenu.compiled.css";
3
3
  import { ax, ix } from "@compiled/react/runtime";
4
- import React from 'react';
4
+ import React, { useCallback } from 'react';
5
5
  import { useIntl } from 'react-intl-next';
6
+ import { toggleHighlightPalette, ToolTipContent } from '@atlaskit/editor-common/keymaps';
6
7
  import { textColorMessages as messages } from '@atlaskit/editor-common/messages';
7
8
  import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
9
  import { hexToEditorTextPaletteColor } from '@atlaskit/editor-palette';
@@ -19,6 +20,7 @@ var getIconColor = function getIconColor(textColor, defaultColor, highlightColor
19
20
  return hexToEditorTextPaletteColor(textColor) || "var(--ds-text, #172B4D)";
20
21
  };
21
22
  export var TextColorHighlightMenu = function TextColorHighlightMenu(_ref) {
23
+ var _api$textColor2;
22
24
  var children = _ref.children,
23
25
  api = _ref.api;
24
26
  var isHighlightPluginExisted = !!(api !== null && api !== void 0 && api.highlight);
@@ -31,11 +33,30 @@ export var TextColorHighlightMenu = function TextColorHighlightMenu(_ref) {
31
33
  var _useIntl = useIntl(),
32
34
  formatMessage = _useIntl.formatMessage;
33
35
  var defaultColor = useSharedPluginStateSelector(api, 'textColor.defaultColor');
36
+ var isPaletteOpen = useSharedPluginStateSelector(api, 'textColor.isPaletteOpen');
37
+ var setIsPaletteOpen = useCallback(function (isOpen) {
38
+ var _api$textColor;
39
+ if (api !== null && api !== void 0 && (_api$textColor = api.textColor) !== null && _api$textColor !== void 0 && (_api$textColor = _api$textColor.commands) !== null && _api$textColor !== void 0 && _api$textColor.setPalette) {
40
+ api.core.actions.execute(function (_ref2) {
41
+ var tr = _ref2.tr;
42
+ api.textColor.commands.setPalette(isOpen)({
43
+ tr: tr
44
+ });
45
+ return tr;
46
+ });
47
+ }
48
+ }, [api === null || api === void 0 || (_api$textColor2 = api.textColor) === null || _api$textColor2 === void 0 ? void 0 : _api$textColor2.commands, api === null || api === void 0 ? void 0 : api.core.actions]);
34
49
  var iconColor = getIconColor(textColor, defaultColor, highlightColor);
35
50
  var highlightColorIcon = highlightColor ? highlightColor : getContrastingBackgroundColor(iconColor);
36
51
  return /*#__PURE__*/React.createElement(ToolbarTooltip, {
37
- content: formatMessage(isHighlightPluginExisted ? messages.textColorHighlightTooltip : messages.textColorTooltip)
38
- }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, null, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
52
+ content: /*#__PURE__*/React.createElement(ToolTipContent, {
53
+ description: formatMessage(isHighlightPluginExisted ? messages.textColorHighlightTooltip : messages.textColorTooltip),
54
+ keymap: toggleHighlightPalette
55
+ })
56
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenuProvider, {
57
+ isOpen: expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? isPaletteOpen : undefined,
58
+ setIsOpen: expValEquals('platform_editor_toolbar_aifc_patch_6', 'isEnabled', true) ? setIsPaletteOpen : undefined
59
+ }, /*#__PURE__*/React.createElement(ToolbarDropdownMenu, {
39
60
  iconBefore: /*#__PURE__*/React.createElement(ToolbarColorSwatch, {
40
61
  highlightColor: highlightColorIcon
41
62
  }, /*#__PURE__*/React.createElement(TextColorIcon, {
@@ -0,0 +1,4 @@
1
+ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { TextColorPlugin } from '../textColorPluginType';
3
+ export declare const togglePalette: (api: ExtractInjectionAPI<TextColorPlugin> | undefined) => EditorCommand;
4
+ export declare const setPalette: (isPaletteOpen: boolean) => EditorCommand;
@@ -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 { TextColorPlugin } from '../textColorPluginType';
4
+ export declare function keymapPlugin({ api }: {
5
+ api: ExtractInjectionAPI<TextColorPlugin> | undefined;
6
+ }): SafePlugin;
@@ -6,6 +6,7 @@ export type TextColorPluginState = {
6
6
  color: string | null;
7
7
  defaultColor: string;
8
8
  disabled?: boolean;
9
+ isPaletteOpen?: boolean;
9
10
  palette: Array<PaletteColor>;
10
11
  };
11
12
  type TextColorDefaultColor = {
@@ -18,7 +19,8 @@ export interface TextColorPluginConfig {
18
19
  export declare enum ACTIONS {
19
20
  RESET_COLOR = 0,
20
21
  SET_COLOR = 1,
21
- DISABLE = 2
22
+ DISABLE = 2,
23
+ SET_PALETTE = 3
22
24
  }
23
25
  export declare const pluginKey: PluginKey<TextColorPluginState>;
24
26
  export declare function createPlugin(dispatch: Dispatch, pluginConfig?: TextColorPluginConfig): SafePlugin;
@@ -22,6 +22,7 @@ export type TextColorPlugin = NextEditorPlugin<'textColor', {
22
22
  };
23
23
  commands: {
24
24
  changeColor: (color: string, inputMethod?: TextColorInputMethod) => EditorCommand;
25
+ setPalette: (isPaletteOpen: boolean) => EditorCommand;
25
26
  };
26
27
  dependencies: Dependencies;
27
28
  pluginConfiguration: TextColorPluginOptions | undefined;
@@ -0,0 +1,4 @@
1
+ import type { EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { TextColorPlugin } from '../textColorPluginType';
3
+ export declare const togglePalette: (api: ExtractInjectionAPI<TextColorPlugin> | undefined) => EditorCommand;
4
+ export declare const setPalette: (isPaletteOpen: boolean) => EditorCommand;
@@ -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 { TextColorPlugin } from '../textColorPluginType';
4
+ export declare function keymapPlugin({ api }: {
5
+ api: ExtractInjectionAPI<TextColorPlugin> | undefined;
6
+ }): SafePlugin;
@@ -6,6 +6,7 @@ export type TextColorPluginState = {
6
6
  color: string | null;
7
7
  defaultColor: string;
8
8
  disabled?: boolean;
9
+ isPaletteOpen?: boolean;
9
10
  palette: Array<PaletteColor>;
10
11
  };
11
12
  type TextColorDefaultColor = {
@@ -18,7 +19,8 @@ export interface TextColorPluginConfig {
18
19
  export declare enum ACTIONS {
19
20
  RESET_COLOR = 0,
20
21
  SET_COLOR = 1,
21
- DISABLE = 2
22
+ DISABLE = 2,
23
+ SET_PALETTE = 3
22
24
  }
23
25
  export declare const pluginKey: PluginKey<TextColorPluginState>;
24
26
  export declare function createPlugin(dispatch: Dispatch, pluginConfig?: TextColorPluginConfig): SafePlugin;
@@ -22,6 +22,7 @@ export type TextColorPlugin = NextEditorPlugin<'textColor', {
22
22
  };
23
23
  commands: {
24
24
  changeColor: (color: string, inputMethod?: TextColorInputMethod) => EditorCommand;
25
+ setPalette: (isPaletteOpen: boolean) => EditorCommand;
25
26
  };
26
27
  dependencies: Dependencies;
27
28
  pluginConfiguration: TextColorPluginOptions | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-text-color",
3
- "version": "6.1.2",
3
+ "version": "6.2.0",
4
4
  "description": "Text color plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,14 +34,14 @@
34
34
  "@atlaskit/css": "^0.14.0",
35
35
  "@atlaskit/editor-palette": "^2.1.0",
36
36
  "@atlaskit/editor-plugin-analytics": "^6.1.0",
37
- "@atlaskit/editor-plugin-highlight": "^6.1.0",
37
+ "@atlaskit/editor-plugin-highlight": "^6.2.0",
38
38
  "@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
39
39
  "@atlaskit/editor-plugin-selection-toolbar": "^7.0.0",
40
40
  "@atlaskit/editor-plugin-toolbar": "^3.1.0",
41
41
  "@atlaskit/editor-prosemirror": "7.0.0",
42
42
  "@atlaskit/editor-shared-styles": "^3.6.0",
43
43
  "@atlaskit/editor-tables": "^2.9.0",
44
- "@atlaskit/editor-toolbar": "^0.13.0",
44
+ "@atlaskit/editor-toolbar": "^0.14.0",
45
45
  "@atlaskit/editor-toolbar-model": "^0.2.0",
46
46
  "@atlaskit/heading": "^5.2.0",
47
47
  "@atlaskit/icon": "^28.4.0",