@atlaskit/editor-plugin-highlight 1.2.0 → 1.4.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 +26 -0
- package/dist/cjs/commands/change-color.js +46 -16
- package/dist/cjs/ui/ToolbarHighlightColor.js +2 -2
- package/dist/cjs/utils/color.js +48 -0
- package/dist/es2019/commands/change-color.js +46 -16
- package/dist/es2019/ui/ToolbarHighlightColor.js +2 -2
- package/dist/es2019/utils/color.js +42 -0
- package/dist/esm/commands/change-color.js +46 -16
- package/dist/esm/ui/ToolbarHighlightColor.js +2 -2
- package/dist/esm/utils/color.js +42 -0
- package/dist/types/commands/change-color.d.ts +1 -1
- package/dist/types/utils/color.d.ts +2 -0
- package/dist/types-ts4.5/commands/change-color.d.ts +1 -1
- package/dist/types-ts4.5/utils/color.d.ts +2 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-highlight
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#100495](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100495)
|
|
8
|
+
[`dbb78a011fac`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dbb78a011fac) -
|
|
9
|
+
[ux] [ED-23150] Added `changeColor` command for editor-plugin-highlight, including new
|
|
10
|
+
`removeMark` command for editor-common. Fixed bug with editor-plugin-text-color which prevented
|
|
11
|
+
color from being removed when user selects all.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
17
|
+
## 1.3.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [#100553](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/100553)
|
|
22
|
+
[`e0c2a4b9c8ae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e0c2a4b9c8ae) -
|
|
23
|
+
[ED-23157] Clear background color (= highlights) when clearing the formatting on a selection
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies
|
|
28
|
+
|
|
3
29
|
## 1.2.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
|
@@ -4,32 +4,62 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.changeColor = void 0;
|
|
7
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
8
|
+
var _mark = require("@atlaskit/editor-common/mark");
|
|
9
|
+
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
7
10
|
var _pmPlugin = require("../pm-plugin");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// ACTION_SUBJECT,
|
|
11
|
-
// ACTION_SUBJECT_ID,
|
|
12
|
-
// EVENT_TYPE,
|
|
13
|
-
// } from '@atlaskit/editor-common/analytics';
|
|
14
|
-
|
|
15
|
-
var changeColor = exports.changeColor = function changeColor(_editorAnalyticsAPI) {
|
|
11
|
+
var _color = require("../utils/color");
|
|
12
|
+
var changeColor = exports.changeColor = function changeColor(editorAnalyticsAPI) {
|
|
16
13
|
return function (_ref) {
|
|
17
14
|
var color = _ref.color;
|
|
18
15
|
return function (_ref2) {
|
|
19
16
|
var tr = _ref2.tr;
|
|
17
|
+
var backgroundColor = tr.doc.type.schema.marks.backgroundColor;
|
|
18
|
+
if (!backgroundColor) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(createAnalyticsEvent(color, tr))(tr);
|
|
20
22
|
tr.setMeta(_pmPlugin.highlightPluginKey, {
|
|
21
23
|
type: _pmPlugin.HighlightPluginAction.CHANGE_COLOR,
|
|
22
24
|
color: color
|
|
23
25
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
tr.scrollIntoView();
|
|
27
|
+
if (color === _uiColor.REMOVE_HIGHLIGHT_COLOR) {
|
|
28
|
+
(0, _mark.removeMark)(backgroundColor)({
|
|
29
|
+
tr: tr
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
(0, _mark.toggleMark)(backgroundColor, {
|
|
33
|
+
color: color
|
|
34
|
+
})({
|
|
35
|
+
tr: tr
|
|
36
|
+
});
|
|
37
|
+
}
|
|
32
38
|
return tr;
|
|
33
39
|
};
|
|
34
40
|
};
|
|
41
|
+
};
|
|
42
|
+
var createAnalyticsEvent = function createAnalyticsEvent(color, tr) {
|
|
43
|
+
var previousColor = (0, _color.getActiveColor)(tr);
|
|
44
|
+
// get color names from palette
|
|
45
|
+
var newColorFromPalette = _uiColor.highlightColorPalette.find(function (_ref3) {
|
|
46
|
+
var value = _ref3.value;
|
|
47
|
+
return value === color;
|
|
48
|
+
});
|
|
49
|
+
var previousColorFromPalette = _uiColor.highlightColorPalette.find(function (_ref4) {
|
|
50
|
+
var value = _ref4.value;
|
|
51
|
+
return value === previousColor;
|
|
52
|
+
});
|
|
53
|
+
var newColorLabel = newColorFromPalette ? newColorFromPalette.label : color;
|
|
54
|
+
var previousColorLabel = previousColorFromPalette ? previousColorFromPalette.label : previousColor || '';
|
|
55
|
+
return {
|
|
56
|
+
action: _analytics.ACTION.FORMATTED,
|
|
57
|
+
actionSubject: _analytics.ACTION_SUBJECT.TEXT,
|
|
58
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
59
|
+
eventType: _analytics.EVENT_TYPE.TRACK,
|
|
60
|
+
attributes: {
|
|
61
|
+
newColor: newColorLabel.toLowerCase(),
|
|
62
|
+
previousColor: previousColorLabel.toLowerCase()
|
|
63
|
+
}
|
|
64
|
+
};
|
|
35
65
|
};
|
|
@@ -50,7 +50,7 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
50
50
|
dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
|
|
51
51
|
action: isOpen ? _analytics.ACTION.OPENED : _analytics.ACTION.CLOSED,
|
|
52
52
|
actionSubject: _analytics.ACTION_SUBJECT.TOOLBAR,
|
|
53
|
-
actionSubjectId: _analytics.ACTION_SUBJECT_ID.
|
|
53
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
54
54
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
55
55
|
});
|
|
56
56
|
setIsDropdownOpen(isOpen);
|
|
@@ -127,7 +127,7 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
127
127
|
isPopupPositioned: true
|
|
128
128
|
},
|
|
129
129
|
trigger: (0, _react2.jsx)(_uiMenu.ToolbarButton, {
|
|
130
|
-
buttonId: _uiMenu.TOOLBAR_BUTTON.
|
|
130
|
+
buttonId: _uiMenu.TOOLBAR_BUTTON.BACKGROUND_COLOR,
|
|
131
131
|
spacing: isToolbarReducedSpacing ? 'none' : 'default',
|
|
132
132
|
disabled: disabled || highlightState.disabled,
|
|
133
133
|
selected: isDropdownOpen,
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getActiveColor = void 0;
|
|
7
|
+
var _uiColor = require("@atlaskit/editor-common/ui-color");
|
|
8
|
+
var getActiveColor = exports.getActiveColor = function getActiveColor(tr) {
|
|
9
|
+
var _ref = tr.selection,
|
|
10
|
+
$from = _ref.$from,
|
|
11
|
+
$to = _ref.$to,
|
|
12
|
+
$cursor = _ref.$cursor;
|
|
13
|
+
var _ref2 = tr.doc.type.schema.marks,
|
|
14
|
+
backgroundColor = _ref2.backgroundColor;
|
|
15
|
+
|
|
16
|
+
// Filter out other marks
|
|
17
|
+
var marks = [];
|
|
18
|
+
if ($cursor) {
|
|
19
|
+
marks.push(backgroundColor.isInSet(tr.storedMarks || $cursor.marks()) || undefined);
|
|
20
|
+
} else {
|
|
21
|
+
tr.doc.nodesBetween($from.pos, $to.pos, function (currentNode) {
|
|
22
|
+
if (currentNode.isLeaf) {
|
|
23
|
+
var mark = backgroundColor.isInSet(currentNode.marks) || undefined;
|
|
24
|
+
marks.push(mark);
|
|
25
|
+
return !mark;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Merge consecutive same color marks
|
|
32
|
+
var prevMark;
|
|
33
|
+
marks = marks.filter(function (mark) {
|
|
34
|
+
if (mark && prevMark && mark.attrs.color === prevMark.attrs.color) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
prevMark = mark;
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
40
|
+
var marksWithColor = marks.filter(function (mark) {
|
|
41
|
+
return !!mark;
|
|
42
|
+
});
|
|
43
|
+
// When multiple colors are selected revert back to default color
|
|
44
|
+
if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return marksWithColor.length ? marksWithColor[0].attrs.color : _uiColor.REMOVE_HIGHLIGHT_COLOR;
|
|
48
|
+
};
|
|
@@ -1,27 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ACTION_SUBJECT_ID,
|
|
5
|
-
// EVENT_TYPE,
|
|
6
|
-
// } from '@atlaskit/editor-common/analytics';
|
|
7
|
-
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
+
import { highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
|
|
8
4
|
import { HighlightPluginAction, highlightPluginKey } from '../pm-plugin';
|
|
9
|
-
|
|
5
|
+
import { getActiveColor } from '../utils/color';
|
|
6
|
+
export const changeColor = editorAnalyticsAPI => ({
|
|
10
7
|
color
|
|
11
8
|
}) => ({
|
|
12
9
|
tr
|
|
13
10
|
}) => {
|
|
11
|
+
const {
|
|
12
|
+
backgroundColor
|
|
13
|
+
} = tr.doc.type.schema.marks;
|
|
14
|
+
if (!backgroundColor) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.attachAnalyticsEvent(createAnalyticsEvent(color, tr))(tr);
|
|
14
18
|
tr.setMeta(highlightPluginKey, {
|
|
15
19
|
type: HighlightPluginAction.CHANGE_COLOR,
|
|
16
20
|
color
|
|
17
21
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
tr.scrollIntoView();
|
|
23
|
+
if (color === REMOVE_HIGHLIGHT_COLOR) {
|
|
24
|
+
removeMark(backgroundColor)({
|
|
25
|
+
tr
|
|
26
|
+
});
|
|
27
|
+
} else {
|
|
28
|
+
toggleMark(backgroundColor, {
|
|
29
|
+
color
|
|
30
|
+
})({
|
|
31
|
+
tr
|
|
32
|
+
});
|
|
33
|
+
}
|
|
26
34
|
return tr;
|
|
35
|
+
};
|
|
36
|
+
const createAnalyticsEvent = (color, tr) => {
|
|
37
|
+
const previousColor = getActiveColor(tr);
|
|
38
|
+
// get color names from palette
|
|
39
|
+
const newColorFromPalette = highlightColorPalette.find(({
|
|
40
|
+
value
|
|
41
|
+
}) => value === color);
|
|
42
|
+
const previousColorFromPalette = highlightColorPalette.find(({
|
|
43
|
+
value
|
|
44
|
+
}) => value === previousColor);
|
|
45
|
+
const newColorLabel = newColorFromPalette ? newColorFromPalette.label : color;
|
|
46
|
+
const previousColorLabel = previousColorFromPalette ? previousColorFromPalette.label : previousColor || '';
|
|
47
|
+
return {
|
|
48
|
+
action: ACTION.FORMATTED,
|
|
49
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
50
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
51
|
+
eventType: EVENT_TYPE.TRACK,
|
|
52
|
+
attributes: {
|
|
53
|
+
newColor: newColorLabel.toLowerCase(),
|
|
54
|
+
previousColor: previousColorLabel.toLowerCase()
|
|
55
|
+
}
|
|
56
|
+
};
|
|
27
57
|
};
|
|
@@ -36,7 +36,7 @@ const ToolbarHighlightColor = ({
|
|
|
36
36
|
dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 ? void 0 : dispatchAnalyticsEvent({
|
|
37
37
|
action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
|
|
38
38
|
actionSubject: ACTION_SUBJECT.TOOLBAR,
|
|
39
|
-
actionSubjectId: ACTION_SUBJECT_ID.
|
|
39
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
40
40
|
eventType: EVENT_TYPE.TRACK
|
|
41
41
|
});
|
|
42
42
|
setIsDropdownOpen(isOpen);
|
|
@@ -112,7 +112,7 @@ const ToolbarHighlightColor = ({
|
|
|
112
112
|
isPopupPositioned: true
|
|
113
113
|
},
|
|
114
114
|
trigger: jsx(ToolbarButton, {
|
|
115
|
-
buttonId: TOOLBAR_BUTTON.
|
|
115
|
+
buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
|
|
116
116
|
spacing: isToolbarReducedSpacing ? 'none' : 'default',
|
|
117
117
|
disabled: disabled || highlightState.disabled,
|
|
118
118
|
selected: isDropdownOpen,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
|
|
2
|
+
export const getActiveColor = tr => {
|
|
3
|
+
const {
|
|
4
|
+
$from,
|
|
5
|
+
$to,
|
|
6
|
+
$cursor
|
|
7
|
+
} = tr.selection;
|
|
8
|
+
const {
|
|
9
|
+
backgroundColor
|
|
10
|
+
} = tr.doc.type.schema.marks;
|
|
11
|
+
|
|
12
|
+
// Filter out other marks
|
|
13
|
+
let marks = [];
|
|
14
|
+
if ($cursor) {
|
|
15
|
+
marks.push(backgroundColor.isInSet(tr.storedMarks || $cursor.marks()) || undefined);
|
|
16
|
+
} else {
|
|
17
|
+
tr.doc.nodesBetween($from.pos, $to.pos, currentNode => {
|
|
18
|
+
if (currentNode.isLeaf) {
|
|
19
|
+
const mark = backgroundColor.isInSet(currentNode.marks) || undefined;
|
|
20
|
+
marks.push(mark);
|
|
21
|
+
return !mark;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Merge consecutive same color marks
|
|
28
|
+
let prevMark;
|
|
29
|
+
marks = marks.filter(mark => {
|
|
30
|
+
if (mark && prevMark && mark.attrs.color === prevMark.attrs.color) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
prevMark = mark;
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
const marksWithColor = marks.filter(mark => !!mark);
|
|
37
|
+
// When multiple colors are selected revert back to default color
|
|
38
|
+
if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return marksWithColor.length ? marksWithColor[0].attrs.color : REMOVE_HIGHLIGHT_COLOR;
|
|
42
|
+
};
|
|
@@ -1,29 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// ACTION_SUBJECT_ID,
|
|
5
|
-
// EVENT_TYPE,
|
|
6
|
-
// } from '@atlaskit/editor-common/analytics';
|
|
7
|
-
|
|
1
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
|
+
import { removeMark, toggleMark } from '@atlaskit/editor-common/mark';
|
|
3
|
+
import { highlightColorPalette, REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
|
|
8
4
|
import { HighlightPluginAction, highlightPluginKey } from '../pm-plugin';
|
|
9
|
-
|
|
5
|
+
import { getActiveColor } from '../utils/color';
|
|
6
|
+
export var changeColor = function changeColor(editorAnalyticsAPI) {
|
|
10
7
|
return function (_ref) {
|
|
11
8
|
var color = _ref.color;
|
|
12
9
|
return function (_ref2) {
|
|
13
10
|
var tr = _ref2.tr;
|
|
11
|
+
var backgroundColor = tr.doc.type.schema.marks.backgroundColor;
|
|
12
|
+
if (!backgroundColor) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent(createAnalyticsEvent(color, tr))(tr);
|
|
14
16
|
tr.setMeta(highlightPluginKey, {
|
|
15
17
|
type: HighlightPluginAction.CHANGE_COLOR,
|
|
16
18
|
color: color
|
|
17
19
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
tr.scrollIntoView();
|
|
21
|
+
if (color === REMOVE_HIGHLIGHT_COLOR) {
|
|
22
|
+
removeMark(backgroundColor)({
|
|
23
|
+
tr: tr
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
toggleMark(backgroundColor, {
|
|
27
|
+
color: color
|
|
28
|
+
})({
|
|
29
|
+
tr: tr
|
|
30
|
+
});
|
|
31
|
+
}
|
|
26
32
|
return tr;
|
|
27
33
|
};
|
|
28
34
|
};
|
|
35
|
+
};
|
|
36
|
+
var createAnalyticsEvent = function createAnalyticsEvent(color, tr) {
|
|
37
|
+
var previousColor = getActiveColor(tr);
|
|
38
|
+
// get color names from palette
|
|
39
|
+
var newColorFromPalette = highlightColorPalette.find(function (_ref3) {
|
|
40
|
+
var value = _ref3.value;
|
|
41
|
+
return value === color;
|
|
42
|
+
});
|
|
43
|
+
var previousColorFromPalette = highlightColorPalette.find(function (_ref4) {
|
|
44
|
+
var value = _ref4.value;
|
|
45
|
+
return value === previousColor;
|
|
46
|
+
});
|
|
47
|
+
var newColorLabel = newColorFromPalette ? newColorFromPalette.label : color;
|
|
48
|
+
var previousColorLabel = previousColorFromPalette ? previousColorFromPalette.label : previousColor || '';
|
|
49
|
+
return {
|
|
50
|
+
action: ACTION.FORMATTED,
|
|
51
|
+
actionSubject: ACTION_SUBJECT.TEXT,
|
|
52
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
53
|
+
eventType: EVENT_TYPE.TRACK,
|
|
54
|
+
attributes: {
|
|
55
|
+
newColor: newColorLabel.toLowerCase(),
|
|
56
|
+
previousColor: previousColorLabel.toLowerCase()
|
|
57
|
+
}
|
|
58
|
+
};
|
|
29
59
|
};
|
|
@@ -39,7 +39,7 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
39
39
|
dispatchAnalyticsEvent === null || dispatchAnalyticsEvent === void 0 || dispatchAnalyticsEvent({
|
|
40
40
|
action: isOpen ? ACTION.OPENED : ACTION.CLOSED,
|
|
41
41
|
actionSubject: ACTION_SUBJECT.TOOLBAR,
|
|
42
|
-
actionSubjectId: ACTION_SUBJECT_ID.
|
|
42
|
+
actionSubjectId: ACTION_SUBJECT_ID.FORMAT_BACKGROUND_COLOR,
|
|
43
43
|
eventType: EVENT_TYPE.TRACK
|
|
44
44
|
});
|
|
45
45
|
setIsDropdownOpen(isOpen);
|
|
@@ -116,7 +116,7 @@ var ToolbarHighlightColor = function ToolbarHighlightColor(_ref) {
|
|
|
116
116
|
isPopupPositioned: true
|
|
117
117
|
},
|
|
118
118
|
trigger: jsx(ToolbarButton, {
|
|
119
|
-
buttonId: TOOLBAR_BUTTON.
|
|
119
|
+
buttonId: TOOLBAR_BUTTON.BACKGROUND_COLOR,
|
|
120
120
|
spacing: isToolbarReducedSpacing ? 'none' : 'default',
|
|
121
121
|
disabled: disabled || highlightState.disabled,
|
|
122
122
|
selected: isDropdownOpen,
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { REMOVE_HIGHLIGHT_COLOR } from '@atlaskit/editor-common/ui-color';
|
|
2
|
+
export var getActiveColor = function getActiveColor(tr) {
|
|
3
|
+
var _ref = tr.selection,
|
|
4
|
+
$from = _ref.$from,
|
|
5
|
+
$to = _ref.$to,
|
|
6
|
+
$cursor = _ref.$cursor;
|
|
7
|
+
var _ref2 = tr.doc.type.schema.marks,
|
|
8
|
+
backgroundColor = _ref2.backgroundColor;
|
|
9
|
+
|
|
10
|
+
// Filter out other marks
|
|
11
|
+
var marks = [];
|
|
12
|
+
if ($cursor) {
|
|
13
|
+
marks.push(backgroundColor.isInSet(tr.storedMarks || $cursor.marks()) || undefined);
|
|
14
|
+
} else {
|
|
15
|
+
tr.doc.nodesBetween($from.pos, $to.pos, function (currentNode) {
|
|
16
|
+
if (currentNode.isLeaf) {
|
|
17
|
+
var mark = backgroundColor.isInSet(currentNode.marks) || undefined;
|
|
18
|
+
marks.push(mark);
|
|
19
|
+
return !mark;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Merge consecutive same color marks
|
|
26
|
+
var prevMark;
|
|
27
|
+
marks = marks.filter(function (mark) {
|
|
28
|
+
if (mark && prevMark && mark.attrs.color === prevMark.attrs.color) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
prevMark = mark;
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
var marksWithColor = marks.filter(function (mark) {
|
|
35
|
+
return !!mark;
|
|
36
|
+
});
|
|
37
|
+
// When multiple colors are selected revert back to default color
|
|
38
|
+
if (marksWithColor.length > 1 || marksWithColor.length === 1 && marks.length > 1) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return marksWithColor.length ? marksWithColor[0].attrs.color : REMOVE_HIGHLIGHT_COLOR;
|
|
42
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
-
export declare const changeColor: (
|
|
3
|
+
export declare const changeColor: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ color }: {
|
|
4
4
|
color: string;
|
|
5
5
|
}) => EditorCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
-
export declare const changeColor: (
|
|
3
|
+
export declare const changeColor: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => ({ color }: {
|
|
4
4
|
color: string;
|
|
5
5
|
}) => EditorCommand;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-highlight",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Highlight plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@atlaskit/adf-schema": "^36.3.0",
|
|
42
|
-
"@atlaskit/editor-common": "^80.
|
|
42
|
+
"@atlaskit/editor-common": "^80.4.0",
|
|
43
43
|
"@atlaskit/editor-palette": "1.6.0",
|
|
44
44
|
"@atlaskit/editor-plugin-analytics": "^1.2.0",
|
|
45
|
-
"@atlaskit/editor-plugin-text-formatting": "^1.
|
|
45
|
+
"@atlaskit/editor-plugin-text-formatting": "^1.6.0",
|
|
46
46
|
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
47
47
|
"@atlaskit/editor-shared-styles": "^2.11.0",
|
|
48
48
|
"@atlaskit/icon": "^22.2.0",
|
|
49
|
-
"@atlaskit/primitives": "^6.
|
|
49
|
+
"@atlaskit/primitives": "^6.2.0",
|
|
50
50
|
"@babel/runtime": "^7.0.0",
|
|
51
51
|
"@emotion/react": "^11.7.1"
|
|
52
52
|
},
|