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