@atlaskit/editor-plugin-highlight 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/dist/cjs/plugin.js +36 -4
- package/dist/cjs/ui/FloatingToolbarHighlightColor.js +92 -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 +34 -4
- package/dist/es2019/ui/FloatingToolbarHighlightColor.js +83 -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 +36 -4
- package/dist/esm/ui/FloatingToolbarHighlightColor.js +84 -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/plugin.d.ts +4 -0
- package/dist/types/ui/FloatingToolbarHighlightColor.d.ts +14 -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/plugin.d.ts +4 -0
- package/dist/types-ts4.5/ui/FloatingToolbarHighlightColor.d.ts +14 -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 +13 -7
- /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,27 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-highlight
|
|
2
2
|
|
|
3
|
+
## 1.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#114903](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/114903)
|
|
8
|
+
[`8f2977cd60ba0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8f2977cd60ba0) -
|
|
9
|
+
[ux] [ED-23063] Adds optional floating toolbar button for text highlighting to the selection
|
|
10
|
+
toolbar (disabled by default)
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
16
|
+
## 1.9.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- [#112947](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/112947)
|
|
21
|
+
[`ec865ff1780db`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ec865ff1780db) -
|
|
22
|
+
[ux] [ED-23760] Refactor Editor Highlight toolbar button to facilitate reuse and add a (currently
|
|
23
|
+
unused) Floating toolbar button
|
|
24
|
+
|
|
3
25
|
## 1.8.1
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -6,13 +6,17 @@ 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 _FloatingToolbarHighlightColor = require("./ui/FloatingToolbarHighlightColor");
|
|
14
|
+
var _PrimaryToolbarHighlightColor = require("./ui/PrimaryToolbarHighlightColor");
|
|
12
15
|
var _ToolbarHighlightColor = require("./ui/ToolbarHighlightColor");
|
|
13
16
|
var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
14
17
|
var _api$analytics;
|
|
15
|
-
var api = _ref.api
|
|
18
|
+
var api = _ref.api,
|
|
19
|
+
options = _ref.config;
|
|
16
20
|
var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
17
21
|
var primaryToolbarComponent = function primaryToolbarComponent(_ref2) {
|
|
18
22
|
var popupsMountPoint = _ref2.popupsMountPoint,
|
|
@@ -20,15 +24,21 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
20
24
|
popupsScrollableElement = _ref2.popupsScrollableElement,
|
|
21
25
|
disabled = _ref2.disabled,
|
|
22
26
|
isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
|
|
23
|
-
dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
|
|
24
27
|
editorView = _ref2.editorView;
|
|
25
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
28
|
+
return (0, _platformFeatureFlags.getBooleanFF)('platform.editor.refactor-highlight-toolbar_mo0pj') ? /*#__PURE__*/_react.default.createElement(_PrimaryToolbarHighlightColor.PrimaryToolbarHighlightColorWithIntl, {
|
|
29
|
+
popupsMountPoint: popupsMountPoint,
|
|
30
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
31
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
32
|
+
disabled: disabled,
|
|
33
|
+
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
34
|
+
pluginInjectionApi: api,
|
|
35
|
+
editorView: editorView
|
|
36
|
+
}) : /*#__PURE__*/_react.default.createElement(_ToolbarHighlightColor.ToolbarHighlightColorWithIntl, {
|
|
26
37
|
popupsMountPoint: popupsMountPoint,
|
|
27
38
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
28
39
|
popupsScrollableElement: popupsScrollableElement,
|
|
29
40
|
disabled: disabled,
|
|
30
41
|
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
31
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
32
42
|
pluginInjectionApi: api,
|
|
33
43
|
editorView: editorView
|
|
34
44
|
});
|
|
@@ -68,6 +78,28 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
68
78
|
component: primaryToolbarComponent
|
|
69
79
|
}));
|
|
70
80
|
},
|
|
81
|
+
pluginsOptions: {
|
|
82
|
+
selectionToolbar: function selectionToolbar() {
|
|
83
|
+
if (!(options !== null && options !== void 0 && options.textHighlightingFloatingToolbarExperiment) || !(0, _platformFeatureFlags.getBooleanFF)('platform.editor.enable-selection-toolbar_ucdwd')) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var toolbarCustom = {
|
|
87
|
+
type: 'custom',
|
|
88
|
+
render: function render(_view, _idx, dispatchAnalyticsEvent) {
|
|
89
|
+
return /*#__PURE__*/_react.default.createElement(_FloatingToolbarHighlightColor.FloatingToolbarHighlightColorWithIntl, {
|
|
90
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
91
|
+
pluginInjectionApi: api
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
fallback: []
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
rank: -9,
|
|
98
|
+
isToolbarAbove: true,
|
|
99
|
+
items: [toolbarCustom]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
},
|
|
71
103
|
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
|
|
72
104
|
};
|
|
73
105
|
};
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
25
|
+
|
|
26
|
+
var FloatingToolbarHighlightColor = function FloatingToolbarHighlightColor(_ref) {
|
|
27
|
+
var pluginInjectionApi = _ref.pluginInjectionApi,
|
|
28
|
+
formatMessage = _ref.intl.formatMessage;
|
|
29
|
+
var toolbarItemRef = (0, _react.useRef)(null);
|
|
30
|
+
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['highlight']),
|
|
31
|
+
highlightState = _useSharedPluginState.highlightState;
|
|
32
|
+
var _useState = (0, _react.useState)(false),
|
|
33
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
34
|
+
isDropdownOpen = _useState2[0],
|
|
35
|
+
setIsDropdownOpen = _useState2[1];
|
|
36
|
+
var _useDropdownEvents = (0, _useDropdownEvents2.useDropdownEvents)({
|
|
37
|
+
toolbarItemRef: toolbarItemRef,
|
|
38
|
+
setIsDropdownOpen: setIsDropdownOpen,
|
|
39
|
+
isDropdownOpen: isDropdownOpen,
|
|
40
|
+
pluginInjectionApi: pluginInjectionApi
|
|
41
|
+
}),
|
|
42
|
+
handleClick = _useDropdownEvents.handleClick,
|
|
43
|
+
handleKeyDown = _useDropdownEvents.handleKeyDown,
|
|
44
|
+
handleClickOutside = _useDropdownEvents.handleClickOutside,
|
|
45
|
+
handleEscapeKeydown = _useDropdownEvents.handleEscapeKeydown,
|
|
46
|
+
handleColorChange = _useDropdownEvents.handleColorChange,
|
|
47
|
+
isOpenedByKeyboard = _useDropdownEvents.isOpenedByKeyboard;
|
|
48
|
+
|
|
49
|
+
// Don't render the toolbar option while the plugin is initialising
|
|
50
|
+
if (!highlightState) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
var toolbarButtonLabel = formatMessage(_messages.highlightMessages.highlight);
|
|
54
|
+
|
|
55
|
+
// Get the design token for the active color (if it exists) to modify the toolbar
|
|
56
|
+
// icon, but show the nice rainbow if none is selected
|
|
57
|
+
var activeColorToken = highlightState.activeColor === null ? null : (0, _editorPalette.hexToEditorTextBackgroundPaletteColor)(highlightState.activeColor);
|
|
58
|
+
return (0, _react2.jsx)(_primitives.Flex, {
|
|
59
|
+
alignItems: "center"
|
|
60
|
+
}, (0, _react2.jsx)(_PaletteDropdown.PaletteDropdown, {
|
|
61
|
+
isOpen: isDropdownOpen && !highlightState.disabled,
|
|
62
|
+
activeColor: highlightState.activeColor,
|
|
63
|
+
trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
64
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.BACKGROUND_COLOR,
|
|
65
|
+
spacing: 'default',
|
|
66
|
+
disabled: highlightState.disabled,
|
|
67
|
+
selected: isDropdownOpen,
|
|
68
|
+
"aria-label": toolbarButtonLabel,
|
|
69
|
+
"aria-expanded": isDropdownOpen,
|
|
70
|
+
"aria-haspopup": true,
|
|
71
|
+
title: toolbarButtonLabel,
|
|
72
|
+
onClick: handleClick,
|
|
73
|
+
onKeyDown: handleKeyDown,
|
|
74
|
+
ref: toolbarItemRef,
|
|
75
|
+
iconBefore: (0, _react2.jsx)(_primitives.Flex, null, (0, _react2.jsx)(_EditorHighlightIcon.EditorHighlightIcon, {
|
|
76
|
+
selectedColor: activeColorToken,
|
|
77
|
+
disabled: highlightState.disabled
|
|
78
|
+
}), (0, _react2.jsx)("span", {
|
|
79
|
+
css: _styles.expandIconWrapperStyle
|
|
80
|
+
}, (0, _react2.jsx)(_chevronDown.default, {
|
|
81
|
+
label: ""
|
|
82
|
+
})))
|
|
83
|
+
}, formatMessage(_messages.highlightMessages.highlightFloatingToolbar)),
|
|
84
|
+
onColorChange: function onColorChange(color) {
|
|
85
|
+
return handleColorChange(color);
|
|
86
|
+
},
|
|
87
|
+
isOpenedByKeyboard: isOpenedByKeyboard,
|
|
88
|
+
handleClickOutside: handleClickOutside,
|
|
89
|
+
handleEscapeKeydown: handleEscapeKeydown
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
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,10 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
2
3
|
import { changeColor } from './commands';
|
|
3
4
|
import { keymapPlugin } from './pm-plugins/keymap';
|
|
4
5
|
import { createPlugin, highlightPluginKey } from './pm-plugins/main';
|
|
6
|
+
import { FloatingToolbarHighlightColorWithIntl as FloatingToolbarHighlightColor } from './ui/FloatingToolbarHighlightColor';
|
|
7
|
+
import { PrimaryToolbarHighlightColorWithIntl as PrimaryToolbarHighlightColor } from './ui/PrimaryToolbarHighlightColor';
|
|
5
8
|
import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
|
|
6
9
|
export const highlightPlugin = ({
|
|
7
|
-
api
|
|
10
|
+
api,
|
|
11
|
+
config: options
|
|
8
12
|
}) => {
|
|
9
13
|
var _api$analytics;
|
|
10
14
|
const editorAnalyticsAPI = api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions;
|
|
@@ -14,15 +18,21 @@ export const highlightPlugin = ({
|
|
|
14
18
|
popupsScrollableElement,
|
|
15
19
|
disabled,
|
|
16
20
|
isToolbarReducedSpacing,
|
|
17
|
-
dispatchAnalyticsEvent,
|
|
18
21
|
editorView
|
|
19
|
-
}) => /*#__PURE__*/React.createElement(
|
|
22
|
+
}) => getBooleanFF('platform.editor.refactor-highlight-toolbar_mo0pj') ? /*#__PURE__*/React.createElement(PrimaryToolbarHighlightColor, {
|
|
23
|
+
popupsMountPoint: popupsMountPoint,
|
|
24
|
+
popupsBoundariesElement: popupsBoundariesElement,
|
|
25
|
+
popupsScrollableElement: popupsScrollableElement,
|
|
26
|
+
disabled: disabled,
|
|
27
|
+
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
28
|
+
pluginInjectionApi: api,
|
|
29
|
+
editorView: editorView
|
|
30
|
+
}) : /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
|
|
20
31
|
popupsMountPoint: popupsMountPoint,
|
|
21
32
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
22
33
|
popupsScrollableElement: popupsScrollableElement,
|
|
23
34
|
disabled: disabled,
|
|
24
35
|
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
25
|
-
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
26
36
|
pluginInjectionApi: api,
|
|
27
37
|
editorView: editorView
|
|
28
38
|
});
|
|
@@ -55,6 +65,26 @@ export const highlightPlugin = ({
|
|
|
55
65
|
component: primaryToolbarComponent
|
|
56
66
|
}));
|
|
57
67
|
},
|
|
68
|
+
pluginsOptions: {
|
|
69
|
+
selectionToolbar() {
|
|
70
|
+
if (!(options !== null && options !== void 0 && options.textHighlightingFloatingToolbarExperiment) || !getBooleanFF('platform.editor.enable-selection-toolbar_ucdwd')) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const toolbarCustom = {
|
|
74
|
+
type: 'custom',
|
|
75
|
+
render: (_view, _idx, dispatchAnalyticsEvent) => /*#__PURE__*/React.createElement(FloatingToolbarHighlightColor, {
|
|
76
|
+
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
77
|
+
pluginInjectionApi: api
|
|
78
|
+
}),
|
|
79
|
+
fallback: []
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
rank: -9,
|
|
83
|
+
isToolbarAbove: true,
|
|
84
|
+
items: [toolbarCustom]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
},
|
|
58
88
|
primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) ? primaryToolbarComponent : undefined
|
|
59
89
|
};
|
|
60
90
|
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { useRef, useState } 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 { highlightMessages as messages } from '@atlaskit/editor-common/messages';
|
|
9
|
+
import { expandIconWrapperStyle } from '@atlaskit/editor-common/styles';
|
|
10
|
+
import { TOOLBAR_BUTTON, ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
11
|
+
import { hexToEditorTextBackgroundPaletteColor } from '@atlaskit/editor-palette';
|
|
12
|
+
import ExpandIcon from '@atlaskit/icon/glyph/chevron-down';
|
|
13
|
+
import { Flex } from '@atlaskit/primitives';
|
|
14
|
+
import { EditorHighlightIcon } from './shared/EditorHighlightIcon';
|
|
15
|
+
import { PaletteDropdown } from './shared/PaletteDropdown';
|
|
16
|
+
import { useDropdownEvents } from './shared/useDropdownEvents';
|
|
17
|
+
const FloatingToolbarHighlightColor = ({
|
|
18
|
+
pluginInjectionApi,
|
|
19
|
+
intl: {
|
|
20
|
+
formatMessage
|
|
21
|
+
}
|
|
22
|
+
}) => {
|
|
23
|
+
const toolbarItemRef = useRef(null);
|
|
24
|
+
const {
|
|
25
|
+
highlightState
|
|
26
|
+
} = useSharedPluginState(pluginInjectionApi, ['highlight']);
|
|
27
|
+
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
|
|
28
|
+
const {
|
|
29
|
+
handleClick,
|
|
30
|
+
handleKeyDown,
|
|
31
|
+
handleClickOutside,
|
|
32
|
+
handleEscapeKeydown,
|
|
33
|
+
handleColorChange,
|
|
34
|
+
isOpenedByKeyboard
|
|
35
|
+
} = useDropdownEvents({
|
|
36
|
+
toolbarItemRef,
|
|
37
|
+
setIsDropdownOpen,
|
|
38
|
+
isDropdownOpen,
|
|
39
|
+
pluginInjectionApi
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Don't render the toolbar option while the plugin is initialising
|
|
43
|
+
if (!highlightState) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const toolbarButtonLabel = formatMessage(messages.highlight);
|
|
47
|
+
|
|
48
|
+
// Get the design token for the active color (if it exists) to modify the toolbar
|
|
49
|
+
// icon, but show the nice rainbow if none is selected
|
|
50
|
+
const activeColorToken = highlightState.activeColor === null ? null : hexToEditorTextBackgroundPaletteColor(highlightState.activeColor);
|
|
51
|
+
return jsx(Flex, {
|
|
52
|
+
alignItems: "center"
|
|
53
|
+
}, jsx(PaletteDropdown, {
|
|
54
|
+
isOpen: isDropdownOpen && !highlightState.disabled,
|
|
55
|
+
activeColor: highlightState.activeColor,
|
|
56
|
+
trigger: jsx(ToolbarButton, {
|
|
57
|
+
buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
|
|
58
|
+
spacing: 'default',
|
|
59
|
+
disabled: highlightState.disabled,
|
|
60
|
+
selected: isDropdownOpen,
|
|
61
|
+
"aria-label": toolbarButtonLabel,
|
|
62
|
+
"aria-expanded": isDropdownOpen,
|
|
63
|
+
"aria-haspopup": true,
|
|
64
|
+
title: toolbarButtonLabel,
|
|
65
|
+
onClick: handleClick,
|
|
66
|
+
onKeyDown: handleKeyDown,
|
|
67
|
+
ref: toolbarItemRef,
|
|
68
|
+
iconBefore: jsx(Flex, null, jsx(EditorHighlightIcon, {
|
|
69
|
+
selectedColor: activeColorToken,
|
|
70
|
+
disabled: highlightState.disabled
|
|
71
|
+
}), jsx("span", {
|
|
72
|
+
css: expandIconWrapperStyle
|
|
73
|
+
}, jsx(ExpandIcon, {
|
|
74
|
+
label: ""
|
|
75
|
+
})))
|
|
76
|
+
}, formatMessage(messages.highlightFloatingToolbar)),
|
|
77
|
+
onColorChange: color => handleColorChange(color),
|
|
78
|
+
isOpenedByKeyboard: isOpenedByKeyboard,
|
|
79
|
+
handleClickOutside: handleClickOutside,
|
|
80
|
+
handleEscapeKeydown: handleEscapeKeydown
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
83
|
+
export const FloatingToolbarHighlightColorWithIntl = injectIntl(FloatingToolbarHighlightColor);
|