@atlaskit/editor-plugin-highlight 1.7.4 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/commands/change-color.js +5 -4
- package/dist/cjs/commands/index.js +15 -1
- package/dist/cjs/commands/set-palette.js +39 -0
- package/dist/cjs/commands/toggle-palette.js +40 -0
- package/dist/cjs/plugin.js +15 -5
- package/dist/cjs/pm-plugins/keymap.js +14 -0
- package/dist/cjs/{pm-plugin.js → pm-plugins/main.js} +11 -3
- package/dist/cjs/ui/ToolbarHighlightColor.js +14 -18
- package/dist/cjs/utils/color.js +22 -21
- package/dist/es2019/commands/change-color.js +3 -2
- package/dist/es2019/commands/index.js +3 -1
- package/dist/es2019/commands/set-palette.js +31 -0
- package/dist/es2019/commands/toggle-palette.js +32 -0
- package/dist/es2019/plugin.js +11 -3
- package/dist/es2019/pm-plugins/keymap.js +9 -0
- package/dist/es2019/{pm-plugin.js → pm-plugins/main.js} +13 -3
- package/dist/es2019/ui/ToolbarHighlightColor.js +15 -14
- package/dist/es2019/utils/color.js +22 -21
- package/dist/esm/commands/change-color.js +3 -2
- package/dist/esm/commands/index.js +3 -1
- package/dist/esm/commands/set-palette.js +33 -0
- package/dist/esm/commands/toggle-palette.js +34 -0
- package/dist/esm/plugin.js +13 -3
- package/dist/esm/pm-plugins/keymap.js +8 -0
- package/dist/esm/{pm-plugin.js → pm-plugins/main.js} +11 -3
- package/dist/esm/ui/ToolbarHighlightColor.js +15 -19
- package/dist/esm/utils/color.js +22 -21
- package/dist/types/commands/index.d.ts +2 -0
- package/dist/types/commands/set-palette.d.ts +3 -0
- package/dist/types/commands/toggle-palette.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugin.d.ts +1 -1
- package/dist/types/pm-plugins/keymap.d.ts +6 -0
- package/dist/{types-ts4.5/pm-plugin.d.ts → types/pm-plugins/main.d.ts} +4 -2
- package/dist/types/ui/ToolbarHighlightColor.d.ts +3 -0
- package/dist/types-ts4.5/commands/index.d.ts +2 -0
- package/dist/types-ts4.5/commands/set-palette.d.ts +3 -0
- package/dist/types-ts4.5/commands/toggle-palette.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/plugin.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +6 -0
- package/dist/{types/pm-plugin.d.ts → types-ts4.5/pm-plugins/main.d.ts} +4 -2
- package/dist/types-ts4.5/ui/ToolbarHighlightColor.d.ts +3 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-highlight
|
|
2
2
|
|
|
3
|
+
## 1.7.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#107302](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107302)
|
|
8
|
+
[`b1279657d678b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/b1279657d678b) -
|
|
9
|
+
[ux] [ED-23162] Add keyboard shortcut to toggle highlight color palette
|
|
10
|
+
- [#107453](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107453)
|
|
11
|
+
[`30d2c10cc823d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/30d2c10cc823d) -
|
|
12
|
+
[ED-23515] Remove selected state for "Remove highlight" option, added multiple color nuance to
|
|
13
|
+
change color analytics
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 1.7.4
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -7,7 +7,7 @@ exports.changeColor = void 0;
|
|
|
7
7
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
8
|
var _mark = require("@atlaskit/editor-common/mark");
|
|
9
9
|
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
10
|
-
var
|
|
10
|
+
var _main = require("../pm-plugins/main");
|
|
11
11
|
var _color = require("../utils/color");
|
|
12
12
|
var changeColor = exports.changeColor = function changeColor(editorAnalyticsAPI) {
|
|
13
13
|
return function (_ref) {
|
|
@@ -25,8 +25,8 @@ var changeColor = exports.changeColor = function changeColor(editorAnalyticsAPI)
|
|
|
25
25
|
tr: tr
|
|
26
26
|
});
|
|
27
27
|
} else {
|
|
28
|
-
tr.setMeta(
|
|
29
|
-
type:
|
|
28
|
+
tr.setMeta(_main.highlightPluginKey, {
|
|
29
|
+
type: _main.HighlightPluginAction.CHANGE_COLOR,
|
|
30
30
|
color: color
|
|
31
31
|
});
|
|
32
32
|
(0, _mark.toggleMark)(backgroundColor, {
|
|
@@ -40,7 +40,8 @@ var changeColor = exports.changeColor = function changeColor(editorAnalyticsAPI)
|
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
42
|
var createAnalyticsEvent = function createAnalyticsEvent(color, tr) {
|
|
43
|
-
var
|
|
43
|
+
var _getActiveColor;
|
|
44
|
+
var previousColor = (_getActiveColor = (0, _color.getActiveColor)(tr)) !== null && _getActiveColor !== void 0 ? _getActiveColor : _uiColor.REMOVE_HIGHLIGHT_COLOR;
|
|
44
45
|
// get color names from palette
|
|
45
46
|
var newColorFromPalette = _uiColor.highlightColorPalette.find(function (_ref3) {
|
|
46
47
|
var value = _ref3.value;
|
|
@@ -9,4 +9,18 @@ Object.defineProperty(exports, "changeColor", {
|
|
|
9
9
|
return _changeColor.changeColor;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
12
|
+
Object.defineProperty(exports, "setPalette", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _setPalette.setPalette;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "togglePalette", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _togglePalette.togglePalette;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _changeColor = require("./change-color");
|
|
25
|
+
var _togglePalette = require("./toggle-palette");
|
|
26
|
+
var _setPalette = require("./set-palette");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setPalette = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _main = require("../pm-plugins/main");
|
|
9
|
+
var setPalette = exports.setPalette = function setPalette(api, isPaletteOpen) {
|
|
10
|
+
return function (state, dispatch) {
|
|
11
|
+
var _highlightPluginKey$g;
|
|
12
|
+
var isDisabled = (_highlightPluginKey$g = _main.highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
|
|
13
|
+
if (!isDisabled) {
|
|
14
|
+
var _api$analytics;
|
|
15
|
+
var tr = state.tr;
|
|
16
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(isPaletteOpen))(tr);
|
|
17
|
+
tr.setMeta(_main.highlightPluginKey, {
|
|
18
|
+
type: _main.HighlightPluginAction.TOGGLE_PALETTE,
|
|
19
|
+
isPaletteOpen: isPaletteOpen
|
|
20
|
+
});
|
|
21
|
+
if (dispatch) {
|
|
22
|
+
dispatch(tr);
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var createAnalyticsEvent = function createAnalyticsEvent(isOpen) {
|
|
30
|
+
return {
|
|
31
|
+
action: isOpen ? _analytics.ACTION.OPENED : _analytics.ACTION.CLOSED,
|
|
32
|
+
actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR,
|
|
33
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
34
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
35
|
+
attributes: {
|
|
36
|
+
inputMethod: _analytics.INPUT_METHOD.TOOLBAR
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.togglePalette = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _main = require("../pm-plugins/main");
|
|
9
|
+
var togglePalette = exports.togglePalette = function togglePalette(api) {
|
|
10
|
+
return function (state, dispatch) {
|
|
11
|
+
var _highlightPluginKey$g, _highlightPluginKey$g2;
|
|
12
|
+
var isDisabled = (_highlightPluginKey$g = _main.highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
|
|
13
|
+
var isPaletteOpen = (_highlightPluginKey$g2 = _main.highlightPluginKey.getState(state)) === null || _highlightPluginKey$g2 === void 0 ? void 0 : _highlightPluginKey$g2.isPaletteOpen;
|
|
14
|
+
var tr = state.tr;
|
|
15
|
+
if (!isDisabled) {
|
|
16
|
+
var _api$analytics;
|
|
17
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(!isPaletteOpen))(tr);
|
|
18
|
+
tr.setMeta(_main.highlightPluginKey, {
|
|
19
|
+
type: _main.HighlightPluginAction.TOGGLE_PALETTE,
|
|
20
|
+
isPaletteOpen: !isPaletteOpen
|
|
21
|
+
});
|
|
22
|
+
if (dispatch) {
|
|
23
|
+
dispatch(tr);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var createAnalyticsEvent = function createAnalyticsEvent(isOpen) {
|
|
31
|
+
return {
|
|
32
|
+
action: isOpen ? _analytics.ACTION.OPENED : _analytics.ACTION.CLOSED,
|
|
33
|
+
actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR,
|
|
34
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
35
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
36
|
+
attributes: {
|
|
37
|
+
inputMethod: _analytics.INPUT_METHOD.SHORTCUT
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -7,7 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.highlightPlugin = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _commands = require("./commands");
|
|
10
|
-
var
|
|
10
|
+
var _keymap = require("./pm-plugins/keymap");
|
|
11
|
+
var _main = require("./pm-plugins/main");
|
|
11
12
|
var _ToolbarHighlightColor = require("./ui/ToolbarHighlightColor");
|
|
12
13
|
var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
13
14
|
var _api$analytics;
|
|
@@ -19,7 +20,8 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
19
20
|
popupsScrollableElement = _ref2.popupsScrollableElement,
|
|
20
21
|
disabled = _ref2.disabled,
|
|
21
22
|
isToolbarReducedSpacing = _ref2.isToolbarReducedSpacing,
|
|
22
|
-
dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent
|
|
23
|
+
dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent,
|
|
24
|
+
editorView = _ref2.editorView;
|
|
23
25
|
return /*#__PURE__*/_react.default.createElement(_ToolbarHighlightColor.ToolbarHighlightColorWithIntl, {
|
|
24
26
|
popupsMountPoint: popupsMountPoint,
|
|
25
27
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
@@ -27,7 +29,8 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
27
29
|
disabled: disabled,
|
|
28
30
|
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
29
31
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
30
|
-
pluginInjectionApi: api
|
|
32
|
+
pluginInjectionApi: api,
|
|
33
|
+
editorView: editorView
|
|
31
34
|
});
|
|
32
35
|
};
|
|
33
36
|
return {
|
|
@@ -39,7 +42,14 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
39
42
|
return [{
|
|
40
43
|
name: 'highlight',
|
|
41
44
|
plugin: function plugin() {
|
|
42
|
-
return (0,
|
|
45
|
+
return (0, _main.createPlugin)({
|
|
46
|
+
api: api
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
name: 'highlightKeymap',
|
|
51
|
+
plugin: function plugin() {
|
|
52
|
+
return (0, _keymap.keymapPlugin)({
|
|
43
53
|
api: api
|
|
44
54
|
});
|
|
45
55
|
}
|
|
@@ -49,7 +59,7 @@ var highlightPlugin = exports.highlightPlugin = function highlightPlugin(_ref) {
|
|
|
49
59
|
if (!editorState) {
|
|
50
60
|
return;
|
|
51
61
|
}
|
|
52
|
-
return
|
|
62
|
+
return _main.highlightPluginKey.getState(editorState);
|
|
53
63
|
},
|
|
54
64
|
usePluginHook: function usePluginHook() {
|
|
55
65
|
var _api$core, _api$primaryToolbar;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.keymapPlugin = keymapPlugin;
|
|
7
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
8
|
+
var _commands = require("../commands");
|
|
9
|
+
function keymapPlugin(_ref) {
|
|
10
|
+
var api = _ref.api;
|
|
11
|
+
var list = {};
|
|
12
|
+
(0, _keymaps.bindKeymapWithCommand)(_keymaps.toggleHighlightPalette.common, (0, _commands.togglePalette)(api), list);
|
|
13
|
+
return (0, _keymaps.keymap)(list);
|
|
14
|
+
}
|
|
@@ -8,13 +8,14 @@ exports.highlightPluginKey = exports.createPlugin = exports.HighlightPluginActio
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
-
var _color = require("
|
|
12
|
-
var _disabled = require("
|
|
11
|
+
var _color = require("../utils/color");
|
|
12
|
+
var _disabled = require("../utils/disabled");
|
|
13
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
14
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
15
|
var highlightPluginKey = exports.highlightPluginKey = new _state.PluginKey('highlight');
|
|
16
16
|
var HighlightPluginAction = exports.HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
|
|
17
17
|
HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
|
|
18
|
+
HighlightPluginAction[HighlightPluginAction["TOGGLE_PALETTE"] = 1] = "TOGGLE_PALETTE";
|
|
18
19
|
return HighlightPluginAction;
|
|
19
20
|
}({});
|
|
20
21
|
var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
@@ -25,7 +26,8 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
25
26
|
init: function init(_, editorState) {
|
|
26
27
|
return {
|
|
27
28
|
activeColor: null,
|
|
28
|
-
disabled: (0, _disabled.getDisabledState)(editorState)
|
|
29
|
+
disabled: (0, _disabled.getDisabledState)(editorState),
|
|
30
|
+
isPaletteOpen: false
|
|
29
31
|
};
|
|
30
32
|
},
|
|
31
33
|
apply: function apply(tr, pluginState, _oldState, newState) {
|
|
@@ -38,6 +40,12 @@ var createPlugin = exports.createPlugin = function createPlugin(_ref) {
|
|
|
38
40
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
39
41
|
activeColor: color
|
|
40
42
|
});
|
|
43
|
+
case HighlightPluginAction.TOGGLE_PALETTE:
|
|
44
|
+
var _tr$getMeta3 = tr.getMeta(highlightPluginKey),
|
|
45
|
+
isPaletteOpen = _tr$getMeta3.isPaletteOpen;
|
|
46
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
47
|
+
isPaletteOpen: isPaletteOpen
|
|
48
|
+
});
|
|
41
49
|
default:
|
|
42
50
|
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
43
51
|
activeColor: (0, _color.getActiveColor)(tr),
|
|
@@ -10,8 +10,8 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _react2 = require("@emotion/react");
|
|
12
12
|
var _reactIntlNext = require("react-intl-next");
|
|
13
|
-
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
14
13
|
var _hooks = require("@atlaskit/editor-common/hooks");
|
|
14
|
+
var _keymaps = require("@atlaskit/editor-common/keymaps");
|
|
15
15
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
16
16
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
17
17
|
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
@@ -31,29 +31,24 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
31
31
|
popupsBoundariesElement = _ref.popupsBoundariesElement,
|
|
32
32
|
popupsScrollableElement = _ref.popupsScrollableElement,
|
|
33
33
|
isToolbarReducedSpacing = _ref.isToolbarReducedSpacing,
|
|
34
|
-
dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
|
|
35
34
|
disabled = _ref.disabled,
|
|
36
35
|
pluginInjectionApi = _ref.pluginInjectionApi,
|
|
37
|
-
formatMessage = _ref.intl.formatMessage
|
|
36
|
+
formatMessage = _ref.intl.formatMessage,
|
|
37
|
+
editorView = _ref.editorView;
|
|
38
38
|
var toolbarItemRef = (0, _react.useRef)(null);
|
|
39
39
|
var _useState = (0, _react.useState)(false),
|
|
40
40
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _useState3 = (0, _react.useState)(false),
|
|
44
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
45
|
-
isOpenedByKeyboard = _useState4[0],
|
|
46
|
-
setIsOpenedByKeyboard = _useState4[1];
|
|
41
|
+
isOpenedByKeyboard = _useState2[0],
|
|
42
|
+
setIsOpenedByKeyboard = _useState2[1];
|
|
47
43
|
var _useSharedPluginState = (0, _hooks.useSharedPluginState)(pluginInjectionApi, ['highlight']),
|
|
48
44
|
highlightState = _useSharedPluginState.highlightState;
|
|
45
|
+
var isDropdownOpen = !!(highlightState !== null && highlightState !== void 0 && highlightState.isPaletteOpen);
|
|
49
46
|
var setDropdownOpen = function setDropdownOpen(isOpen) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
setIsDropdownOpen(isOpen);
|
|
47
|
+
if (!(highlightState !== null && highlightState !== void 0 && highlightState.disabled)) {
|
|
48
|
+
var state = editorView.state,
|
|
49
|
+
dispatch = editorView.dispatch;
|
|
50
|
+
(0, _commands.setPalette)(pluginInjectionApi, isOpen)(state, dispatch);
|
|
51
|
+
}
|
|
57
52
|
};
|
|
58
53
|
var toggleDropdown = function toggleDropdown() {
|
|
59
54
|
return setDropdownOpen(!isDropdownOpen);
|
|
@@ -131,10 +126,11 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
131
126
|
spacing: isToolbarReducedSpacing ? 'none' : 'default',
|
|
132
127
|
disabled: disabled || highlightState.disabled,
|
|
133
128
|
selected: isDropdownOpen,
|
|
134
|
-
"aria-label": toolbarButtonLabel,
|
|
129
|
+
"aria-label": (0, _keymaps.tooltip)(_keymaps.toggleHighlightPalette, toolbarButtonLabel),
|
|
130
|
+
"aria-keyshortcuts": (0, _keymaps.getAriaKeyshortcuts)(_keymaps.toggleHighlightPalette),
|
|
135
131
|
"aria-expanded": isDropdownOpen,
|
|
136
132
|
"aria-haspopup": true,
|
|
137
|
-
title: toolbarButtonLabel,
|
|
133
|
+
title: (0, _keymaps.tooltip)(_keymaps.toggleHighlightPalette, toolbarButtonLabel),
|
|
138
134
|
onClick: handleClick,
|
|
139
135
|
onKeyDown: handleKeyDown,
|
|
140
136
|
ref: toolbarItemRef,
|
package/dist/cjs/utils/color.js
CHANGED
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.getActiveColor = void 0;
|
|
8
8
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
9
|
var _mark = require("@atlaskit/editor-common/mark");
|
|
10
|
-
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
11
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
11
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
13
12
|
var getAllUniqueBackgroundColorMarksInRange = function getAllUniqueBackgroundColorMarksInRange(from, to, tr) {
|
|
@@ -49,23 +48,24 @@ var getAllUniqueBackgroundColorMarksInCellSelection = function getAllUniqueBackg
|
|
|
49
48
|
var getColorFromCellSelection = function getColorFromCellSelection(selection, tr) {
|
|
50
49
|
var marks = getAllUniqueBackgroundColorMarksInCellSelection(selection, tr);
|
|
51
50
|
if (marks.length > 1) {
|
|
52
|
-
return
|
|
51
|
+
return 'multiple';
|
|
53
52
|
}
|
|
54
53
|
var firstColorMark = marks.at(0);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
selection.forEachCell(function (cell, cellPos) {
|
|
58
|
-
if (foundNonColoredNode) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
var from = cellPos;
|
|
62
|
-
var to = cellPos + cell.nodeSize;
|
|
63
|
-
if (!(0, _mark.entireSelectionContainsMark)(firstColorMark, tr.doc, from, to)) {
|
|
64
|
-
foundNonColoredNode = true;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
54
|
+
if (!firstColorMark) {
|
|
55
|
+
return null;
|
|
67
56
|
}
|
|
68
|
-
|
|
57
|
+
var foundUncolouredNode = false;
|
|
58
|
+
selection.forEachCell(function (cell, cellPos) {
|
|
59
|
+
if (foundUncolouredNode) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
var from = cellPos;
|
|
63
|
+
var to = cellPos + cell.nodeSize;
|
|
64
|
+
if (!(0, _mark.entireSelectionContainsMark)(firstColorMark, tr.doc, from, to)) {
|
|
65
|
+
foundUncolouredNode = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return foundUncolouredNode ? null : firstColorMark.attrs.color;
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
// All other selections - find the first instance of a backgroundColor mark
|
|
@@ -74,26 +74,27 @@ var getColorFromCellSelection = function getColorFromCellSelection(selection, tr
|
|
|
74
74
|
var getColorFromRange = function getColorFromRange(from, to, tr) {
|
|
75
75
|
var marks = getAllUniqueBackgroundColorMarksInRange(from, to, tr);
|
|
76
76
|
if (marks.length > 1) {
|
|
77
|
-
return
|
|
77
|
+
return 'multiple';
|
|
78
78
|
}
|
|
79
79
|
var firstColorMark = marks.at(0);
|
|
80
80
|
if (firstColorMark && (0, _mark.entireSelectionContainsMark)(firstColorMark, tr.doc, from, to)) {
|
|
81
81
|
return firstColorMark.attrs.color;
|
|
82
82
|
}
|
|
83
|
-
return
|
|
83
|
+
return null;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
// For Cursor selections - set color if it is found in the storedMarks or $cursor.marks
|
|
87
87
|
var getColorFromCursor = function getColorFromCursor(selection, tr) {
|
|
88
|
+
var _mark$attrs$color;
|
|
88
89
|
if (!selection.$cursor) {
|
|
89
|
-
return
|
|
90
|
+
return null;
|
|
90
91
|
}
|
|
91
92
|
var mark = tr.doc.type.schema.marks.backgroundColor.isInSet([].concat((0, _toConsumableArray2.default)(tr.storedMarks ? tr.storedMarks : []), (0, _toConsumableArray2.default)(selection.$cursor.marks())));
|
|
92
|
-
return (mark === null || mark === void 0 ? void 0 : mark.attrs.color)
|
|
93
|
+
return (_mark$attrs$color = mark === null || mark === void 0 ? void 0 : mark.attrs.color) !== null && _mark$attrs$color !== void 0 ? _mark$attrs$color : null;
|
|
93
94
|
};
|
|
94
95
|
var getActiveColor = exports.getActiveColor = function getActiveColor(tr) {
|
|
95
96
|
var selection = tr.selection;
|
|
96
|
-
var color;
|
|
97
|
+
var color = null;
|
|
97
98
|
if (selection instanceof _cellSelection.CellSelection) {
|
|
98
99
|
color = getColorFromCellSelection(selection, tr);
|
|
99
100
|
} else if (selection instanceof _state.TextSelection && selection.$cursor) {
|
|
@@ -101,5 +102,5 @@ var getActiveColor = exports.getActiveColor = function getActiveColor(tr) {
|
|
|
101
102
|
} else {
|
|
102
103
|
color = getColorFromRange(selection.from, selection.to, tr);
|
|
103
104
|
}
|
|
104
|
-
return color
|
|
105
|
+
return color;
|
|
105
106
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
3
|
import { highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
|
|
4
|
-
import { HighlightPluginAction, highlightPluginKey } from '../pm-
|
|
4
|
+
import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
|
|
5
5
|
import { getActiveColor } from '../utils/color';
|
|
6
6
|
export const changeColor = editorAnalyticsAPI => ({
|
|
7
7
|
color
|
|
@@ -34,7 +34,8 @@ export const changeColor = editorAnalyticsAPI => ({
|
|
|
34
34
|
return tr;
|
|
35
35
|
};
|
|
36
36
|
const createAnalyticsEvent = (color, tr) => {
|
|
37
|
-
|
|
37
|
+
var _getActiveColor;
|
|
38
|
+
const previousColor = (_getActiveColor = getActiveColor(tr)) !== null && _getActiveColor !== void 0 ? _getActiveColor : REMOVE_HIGHLIGHT_COLOR;
|
|
38
39
|
// get color names from palette
|
|
39
40
|
const newColorFromPalette = highlightColorPalette.find(({
|
|
40
41
|
value
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
|
|
3
|
+
export const setPalette = (api, isPaletteOpen) => (state, dispatch) => {
|
|
4
|
+
var _highlightPluginKey$g;
|
|
5
|
+
const isDisabled = (_highlightPluginKey$g = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
|
|
6
|
+
if (!isDisabled) {
|
|
7
|
+
var _api$analytics;
|
|
8
|
+
const tr = state.tr;
|
|
9
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(isPaletteOpen))(tr);
|
|
10
|
+
tr.setMeta(highlightPluginKey, {
|
|
11
|
+
type: HighlightPluginAction.TOGGLE_PALETTE,
|
|
12
|
+
isPaletteOpen
|
|
13
|
+
});
|
|
14
|
+
if (dispatch) {
|
|
15
|
+
dispatch(tr);
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
21
|
+
const createAnalyticsEvent = isOpen => {
|
|
22
|
+
return {
|
|
23
|
+
action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
|
|
24
|
+
actionSubject: ACTION_SUBJECT.TOOLBAR,
|
|
25
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
26
|
+
eventType: EVENT_TYPE.TRACK,
|
|
27
|
+
attributes: {
|
|
28
|
+
inputMethod: INPUT_METHOD.TOOLBAR
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { HighlightPluginAction, highlightPluginKey } from '../pm-plugins/main';
|
|
3
|
+
export const togglePalette = api => (state, dispatch) => {
|
|
4
|
+
var _highlightPluginKey$g, _highlightPluginKey$g2;
|
|
5
|
+
const isDisabled = (_highlightPluginKey$g = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g === void 0 ? void 0 : _highlightPluginKey$g.disabled;
|
|
6
|
+
const isPaletteOpen = (_highlightPluginKey$g2 = highlightPluginKey.getState(state)) === null || _highlightPluginKey$g2 === void 0 ? void 0 : _highlightPluginKey$g2.isPaletteOpen;
|
|
7
|
+
const tr = state.tr;
|
|
8
|
+
if (!isDisabled) {
|
|
9
|
+
var _api$analytics;
|
|
10
|
+
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent(createAnalyticsEvent(!isPaletteOpen))(tr);
|
|
11
|
+
tr.setMeta(highlightPluginKey, {
|
|
12
|
+
type: HighlightPluginAction.TOGGLE_PALETTE,
|
|
13
|
+
isPaletteOpen: !isPaletteOpen
|
|
14
|
+
});
|
|
15
|
+
if (dispatch) {
|
|
16
|
+
dispatch(tr);
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
const createAnalyticsEvent = isOpen => {
|
|
23
|
+
return {
|
|
24
|
+
action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
|
|
25
|
+
actionSubject: ACTION_SUBJECT.TOOLBAR,
|
|
26
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
27
|
+
eventType: EVENT_TYPE.TRACK,
|
|
28
|
+
attributes: {
|
|
29
|
+
inputMethod: INPUT_METHOD.SHORTCUT
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { changeColor } from './commands';
|
|
3
|
-
import {
|
|
3
|
+
import { keymapPlugin } from './pm-plugins/keymap';
|
|
4
|
+
import { createPlugin, highlightPluginKey } from './pm-plugins/main';
|
|
4
5
|
import { ToolbarHighlightColorWithIntl as ToolbarHighlightColor } from './ui/ToolbarHighlightColor';
|
|
5
6
|
export const highlightPlugin = ({
|
|
6
7
|
api
|
|
@@ -13,7 +14,8 @@ export const highlightPlugin = ({
|
|
|
13
14
|
popupsScrollableElement,
|
|
14
15
|
disabled,
|
|
15
16
|
isToolbarReducedSpacing,
|
|
16
|
-
dispatchAnalyticsEvent
|
|
17
|
+
dispatchAnalyticsEvent,
|
|
18
|
+
editorView
|
|
17
19
|
}) => /*#__PURE__*/React.createElement(ToolbarHighlightColor, {
|
|
18
20
|
popupsMountPoint: popupsMountPoint,
|
|
19
21
|
popupsBoundariesElement: popupsBoundariesElement,
|
|
@@ -21,7 +23,8 @@ export const highlightPlugin = ({
|
|
|
21
23
|
disabled: disabled,
|
|
22
24
|
isToolbarReducedSpacing: isToolbarReducedSpacing,
|
|
23
25
|
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
|
|
24
|
-
pluginInjectionApi: api
|
|
26
|
+
pluginInjectionApi: api,
|
|
27
|
+
editorView: editorView
|
|
25
28
|
});
|
|
26
29
|
return {
|
|
27
30
|
name: 'highlight',
|
|
@@ -33,6 +36,11 @@ export const highlightPlugin = ({
|
|
|
33
36
|
plugin: () => createPlugin({
|
|
34
37
|
api
|
|
35
38
|
})
|
|
39
|
+
}, {
|
|
40
|
+
name: 'highlightKeymap',
|
|
41
|
+
plugin: () => keymapPlugin({
|
|
42
|
+
api
|
|
43
|
+
})
|
|
36
44
|
}],
|
|
37
45
|
getSharedState(editorState) {
|
|
38
46
|
if (!editorState) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { bindKeymapWithCommand, keymap, toggleHighlightPalette } from '@atlaskit/editor-common/keymaps';
|
|
2
|
+
import { togglePalette } from '../commands';
|
|
3
|
+
export function keymapPlugin({
|
|
4
|
+
api
|
|
5
|
+
}) {
|
|
6
|
+
const list = {};
|
|
7
|
+
bindKeymapWithCommand(toggleHighlightPalette.common, togglePalette(api), list);
|
|
8
|
+
return keymap(list);
|
|
9
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { getActiveColor } from '
|
|
4
|
-
import { getDisabledState } from '
|
|
3
|
+
import { getActiveColor } from '../utils/color';
|
|
4
|
+
import { getDisabledState } from '../utils/disabled';
|
|
5
5
|
export const highlightPluginKey = new PluginKey('highlight');
|
|
6
6
|
export let HighlightPluginAction = /*#__PURE__*/function (HighlightPluginAction) {
|
|
7
7
|
HighlightPluginAction[HighlightPluginAction["CHANGE_COLOR"] = 0] = "CHANGE_COLOR";
|
|
8
|
+
HighlightPluginAction[HighlightPluginAction["TOGGLE_PALETTE"] = 1] = "TOGGLE_PALETTE";
|
|
8
9
|
return HighlightPluginAction;
|
|
9
10
|
}({});
|
|
10
11
|
export const createPlugin = ({
|
|
@@ -15,7 +16,8 @@ export const createPlugin = ({
|
|
|
15
16
|
state: {
|
|
16
17
|
init: (_, editorState) => ({
|
|
17
18
|
activeColor: null,
|
|
18
|
-
disabled: getDisabledState(editorState)
|
|
19
|
+
disabled: getDisabledState(editorState),
|
|
20
|
+
isPaletteOpen: false
|
|
19
21
|
}),
|
|
20
22
|
apply: (tr, pluginState, _oldState, newState) => {
|
|
21
23
|
var _tr$getMeta;
|
|
@@ -29,6 +31,14 @@ export const createPlugin = ({
|
|
|
29
31
|
...pluginState,
|
|
30
32
|
activeColor: color
|
|
31
33
|
};
|
|
34
|
+
case HighlightPluginAction.TOGGLE_PALETTE:
|
|
35
|
+
const {
|
|
36
|
+
isPaletteOpen
|
|
37
|
+
} = tr.getMeta(highlightPluginKey);
|
|
38
|
+
return {
|
|
39
|
+
...pluginState,
|
|
40
|
+
isPaletteOpen
|
|
41
|
+
};
|
|
32
42
|
default:
|
|
33
43
|
return {
|
|
34
44
|
...pluginState,
|