@atlaskit/editor-plugin-selection-marker 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-selection-marker
2
2
 
3
+ ## 1.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#79359](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/79359) [`3441b8062083`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3441b8062083) - [ux] Make the selection marker styling more subtle.
8
+
3
9
  ## 1.1.2
4
10
 
5
11
  ### Patch Changes
@@ -9,11 +9,30 @@ exports.dispatchShouldHideDecorations = dispatchShouldHideDecorations;
9
9
  exports.key = void 0;
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
+ var _utils = require("@atlaskit/editor-common/utils");
12
13
  var _state = require("@atlaskit/editor-prosemirror/state");
13
14
  var _view = require("@atlaskit/editor-prosemirror/view");
14
15
  var _selectionDecoration = require("../ui/selection-decoration");
15
16
  var _widgetDecoration = require("../ui/widget-decoration");
16
17
  var key = exports.key = new _state.PluginKey('selectionMarker');
18
+ function getDecorations(tr, type) {
19
+ var selection = tr.selection;
20
+ switch (type) {
21
+ case 'none':
22
+ return _view.DecorationSet.empty;
23
+ case 'highlight':
24
+ return _view.DecorationSet.create(tr.doc, [].concat((0, _toConsumableArray2.default)((0, _widgetDecoration.createWidgetDecoration)(selection.$anchor, 'anchor', selection, true)), [(0, _selectionDecoration.selectionDecoration)(selection, true)], (0, _toConsumableArray2.default)((0, _widgetDecoration.createWidgetDecoration)(selection.$head, 'head', selection, true))));
25
+ case 'blur':
26
+ return _view.DecorationSet.create(tr.doc, [].concat((0, _toConsumableArray2.default)((0, _widgetDecoration.createWidgetDecoration)(selection.$anchor, 'anchor', selection, false)), [(0, _selectionDecoration.selectionDecoration)(selection, false)]));
27
+ }
28
+ }
29
+ function getDecorationType(tr, forceHide, shouldHideDecorations) {
30
+ if (shouldHideDecorations || forceHide || (0, _utils.isEmptyDocument)(tr.doc)) {
31
+ return 'none';
32
+ }
33
+ // TODO: implement "highlight" for AI features
34
+ return 'blur';
35
+ }
17
36
  var createPlugin = exports.createPlugin = function createPlugin(api) {
18
37
  return new _safePlugin.SafePlugin({
19
38
  key: key,
@@ -29,10 +48,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
29
48
  var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
30
49
  var forceHide = (_tr$getMeta$forceHide = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.forceHide) !== null && _tr$getMeta$forceHide !== void 0 ? _tr$getMeta$forceHide : currentState.forceHide;
31
50
  var shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta2 = tr.getMeta(key)) === null || _tr$getMeta2 === void 0 ? void 0 : _tr$getMeta2.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
32
- var selection = tr.selection;
33
- var decorations = shouldHideDecorations || forceHide ? _view.DecorationSet.empty : _view.DecorationSet.create(tr.doc, [].concat((0, _toConsumableArray2.default)((0, _widgetDecoration.createWidgetDecoration)(selection.$anchor, 'anchor', selection)), [(0, _selectionDecoration.selectionDecoration)(selection)], (0, _toConsumableArray2.default)((0, _widgetDecoration.createWidgetDecoration)(selection.$head, 'head', selection))));
51
+ var type = getDecorationType(tr, forceHide, shouldHideDecorations);
34
52
  return {
35
- decorations: decorations,
53
+ decorations: getDecorations(tr, type),
36
54
  shouldHideDecorations: shouldHideDecorations,
37
55
  forceHide: forceHide
38
56
  };
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.selectionDecoration = void 0;
7
7
  var _view = require("@atlaskit/editor-prosemirror/view");
8
- var decorationStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FF)", ";\n border-bottom: 2px solid ", "var(--ds-background-accent-blue-subtler, #cce0ff)", ";\n ");
9
- var selectionDecoration = exports.selectionDecoration = function selectionDecoration(selection) {
8
+ var decorationStyle = "\n background-color: ".concat("var(--ds-background-accent-gray-subtler, #DCDFE4)", ";\n ");
9
+ var decorationHighlightStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FF)", ";\n border-bottom: 2px solid ", "var(--ds-background-accent-blue-subtler, #cce0ff)", ";\n ");
10
+ var selectionDecoration = exports.selectionDecoration = function selectionDecoration(selection, isHighlight) {
10
11
  return _view.Decoration.inline(selection.from, selection.to, {
11
- style: decorationStyle,
12
+ style: isHighlight ? decorationHighlightStyle : decorationStyle,
12
13
  'data-testid': 'selection-marker-selection'
13
14
  });
14
15
  };
@@ -10,8 +10,8 @@ var _reactDom = _interopRequireDefault(require("react-dom"));
10
10
  var _state = require("@atlaskit/editor-prosemirror/state");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
12
  var _primitives = require("@atlaskit/primitives");
13
- // Copied from: platform/packages/editor/editor-plugin-ai/src/ui/modal/styles.tsx
14
- var selectionMarkerStyles = (0, _primitives.xcss)({
13
+ var _colors = require("@atlaskit/theme/colors");
14
+ var selectionMarkerHighlightStyles = (0, _primitives.xcss)({
15
15
  content: "''",
16
16
  position: 'absolute',
17
17
  backgroundImage: "url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMyIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDMgMjAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMSAxSDBMMSAxLjg1NzE0VjE4LjE0MzNMMCAxOS4wMDA0SDNMMiAxOC4xNDMzVjEuODU3MTRMMyAxSDJIMVoiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3QgeT0iMTkiIHdpZHRoPSIzIiBoZWlnaHQ9IjEiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3Qgd2lkdGg9IjMiIGhlaWdodD0iMSIgZmlsbD0iIzU3OURGRiIvPgo8L3N2Zz4K')",
@@ -28,21 +28,37 @@ var selectionMarkerStyles = (0, _primitives.xcss)({
28
28
  marginRight: '-0.1em',
29
29
  pointerEvents: 'none'
30
30
  });
31
+ var selectionMarkerCursorStyles = (0, _primitives.xcss)({
32
+ content: "''",
33
+ position: 'absolute',
34
+ background: "var(--ds-text, ".concat(_colors.N500, ")"),
35
+ width: "var(--ds-space-025, 2px)",
36
+ display: 'inline-block',
37
+ top: 'space.0',
38
+ bottom: "var(--ds-space-negative-025, -2px)",
39
+ left: '1px',
40
+ marginLeft: '-0.1em',
41
+ right: '0px',
42
+ marginRight: '-0.1em',
43
+ pointerEvents: 'none'
44
+ });
31
45
  var Widget = function Widget(_ref) {
32
- var type = _ref.type;
46
+ var type = _ref.type,
47
+ isHighlight = _ref.isHighlight;
33
48
  return /*#__PURE__*/_react.default.createElement(_primitives.Box, {
34
49
  as: 'span',
35
- xcss: selectionMarkerStyles,
50
+ xcss: isHighlight ? selectionMarkerHighlightStyles : selectionMarkerCursorStyles,
36
51
  testId: "selection-marker-".concat(type, "-cursor"),
37
52
  contentEditable: false
38
53
  });
39
54
  };
40
- var toDOM = function toDOM(type) {
55
+ var toDOM = function toDOM(type, isHighlight) {
41
56
  var element = document.createElement('span');
42
57
  element.contentEditable = 'false';
43
58
  element.setAttribute('style', "position: relative;");
44
59
  _reactDom.default.render( /*#__PURE__*/_react.default.createElement(Widget, {
45
- type: type
60
+ type: type,
61
+ isHighlight: isHighlight
46
62
  }), element);
47
63
  return element;
48
64
  };
@@ -51,13 +67,13 @@ var containsText = function containsText(resolvedPos) {
51
67
  nodeAfter = resolvedPos.nodeAfter;
52
68
  return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
53
69
  };
54
- var createWidgetDecoration = exports.createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection) {
70
+ var createWidgetDecoration = exports.createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection, isHighlight) {
55
71
  // We don't want the cursor to show if it's not text selection
56
72
  // ie. if it's on media selection
57
- if (!(selection instanceof _state.TextSelection) || containsText(resolvedPos) === false) {
73
+ if (!(selection instanceof _state.TextSelection) || containsText(resolvedPos) === false || !selection.empty) {
58
74
  return [];
59
75
  }
60
- return [_view.Decoration.widget(resolvedPos.pos, toDOM(type), {
76
+ return [_view.Decoration.widget(resolvedPos.pos, toDOM(type, isHighlight), {
61
77
  side: -1,
62
78
  key: "".concat(type, "WidgetDecoration"),
63
79
  stopEvent: function stopEvent() {
@@ -1,9 +1,30 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { isEmptyDocument } from '@atlaskit/editor-common/utils';
2
3
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
4
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
5
  import { selectionDecoration } from '../ui/selection-decoration';
5
6
  import { createWidgetDecoration } from '../ui/widget-decoration';
6
7
  export const key = new PluginKey('selectionMarker');
8
+ function getDecorations(tr, type) {
9
+ const {
10
+ selection
11
+ } = tr;
12
+ switch (type) {
13
+ case 'none':
14
+ return DecorationSet.empty;
15
+ case 'highlight':
16
+ return DecorationSet.create(tr.doc, [...createWidgetDecoration(selection.$anchor, 'anchor', selection, true), selectionDecoration(selection, true), ...createWidgetDecoration(selection.$head, 'head', selection, true)]);
17
+ case 'blur':
18
+ return DecorationSet.create(tr.doc, [...createWidgetDecoration(selection.$anchor, 'anchor', selection, false), selectionDecoration(selection, false)]);
19
+ }
20
+ }
21
+ function getDecorationType(tr, forceHide, shouldHideDecorations) {
22
+ if (shouldHideDecorations || forceHide || isEmptyDocument(tr.doc)) {
23
+ return 'none';
24
+ }
25
+ // TODO: implement "highlight" for AI features
26
+ return 'blur';
27
+ }
7
28
  export const createPlugin = api => {
8
29
  return new SafePlugin({
9
30
  key,
@@ -19,12 +40,9 @@ export const createPlugin = api => {
19
40
  var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
20
41
  const forceHide = (_tr$getMeta$forceHide = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.forceHide) !== null && _tr$getMeta$forceHide !== void 0 ? _tr$getMeta$forceHide : currentState.forceHide;
21
42
  const shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta2 = tr.getMeta(key)) === null || _tr$getMeta2 === void 0 ? void 0 : _tr$getMeta2.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
22
- const {
23
- selection
24
- } = tr;
25
- const decorations = shouldHideDecorations || forceHide ? DecorationSet.empty : DecorationSet.create(tr.doc, [...createWidgetDecoration(selection.$anchor, 'anchor', selection), selectionDecoration(selection), ...createWidgetDecoration(selection.$head, 'head', selection)]);
43
+ const type = getDecorationType(tr, forceHide, shouldHideDecorations);
26
44
  return {
27
- decorations,
45
+ decorations: getDecorations(tr, type),
28
46
  shouldHideDecorations,
29
47
  forceHide
30
48
  };
@@ -1,11 +1,14 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
2
  const decorationStyle = `
3
+ background-color: ${"var(--ds-background-accent-gray-subtler, #DCDFE4)"};
4
+ `;
5
+ const decorationHighlightStyle = `
3
6
  background-color: ${"var(--ds-background-accent-blue-subtlest, #E9F2FF)"};
4
7
  border-bottom: 2px solid ${"var(--ds-background-accent-blue-subtler, #cce0ff)"};
5
8
  `;
6
- export const selectionDecoration = selection => {
9
+ export const selectionDecoration = (selection, isHighlight) => {
7
10
  return Decoration.inline(selection.from, selection.to, {
8
- style: decorationStyle,
11
+ style: isHighlight ? decorationHighlightStyle : decorationStyle,
9
12
  'data-testid': 'selection-marker-selection'
10
13
  });
11
14
  };
@@ -3,8 +3,8 @@ import ReactDOM from 'react-dom';
3
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
5
  import { Box, xcss } from '@atlaskit/primitives';
6
- // Copied from: platform/packages/editor/editor-plugin-ai/src/ui/modal/styles.tsx
7
- const selectionMarkerStyles = xcss({
6
+ import { N500 } from '@atlaskit/theme/colors';
7
+ const selectionMarkerHighlightStyles = xcss({
8
8
  content: "''",
9
9
  position: 'absolute',
10
10
  backgroundImage: "url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMyIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDMgMjAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMSAxSDBMMSAxLjg1NzE0VjE4LjE0MzNMMCAxOS4wMDA0SDNMMiAxOC4xNDMzVjEuODU3MTRMMyAxSDJIMVoiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3QgeT0iMTkiIHdpZHRoPSIzIiBoZWlnaHQ9IjEiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3Qgd2lkdGg9IjMiIGhlaWdodD0iMSIgZmlsbD0iIzU3OURGRiIvPgo8L3N2Zz4K')",
@@ -21,22 +21,38 @@ const selectionMarkerStyles = xcss({
21
21
  marginRight: '-0.1em',
22
22
  pointerEvents: 'none'
23
23
  });
24
+ const selectionMarkerCursorStyles = xcss({
25
+ content: "''",
26
+ position: 'absolute',
27
+ background: `var(--ds-text, ${N500})`,
28
+ width: "var(--ds-space-025, 2px)",
29
+ display: 'inline-block',
30
+ top: 'space.0',
31
+ bottom: "var(--ds-space-negative-025, -2px)",
32
+ left: '1px',
33
+ marginLeft: '-0.1em',
34
+ right: '0px',
35
+ marginRight: '-0.1em',
36
+ pointerEvents: 'none'
37
+ });
24
38
  const Widget = ({
25
- type
39
+ type,
40
+ isHighlight
26
41
  }) => {
27
42
  return /*#__PURE__*/React.createElement(Box, {
28
43
  as: 'span',
29
- xcss: selectionMarkerStyles,
44
+ xcss: isHighlight ? selectionMarkerHighlightStyles : selectionMarkerCursorStyles,
30
45
  testId: `selection-marker-${type}-cursor`,
31
46
  contentEditable: false
32
47
  });
33
48
  };
34
- const toDOM = type => {
49
+ const toDOM = (type, isHighlight) => {
35
50
  let element = document.createElement('span');
36
51
  element.contentEditable = 'false';
37
52
  element.setAttribute('style', `position: relative;`);
38
53
  ReactDOM.render( /*#__PURE__*/React.createElement(Widget, {
39
- type: type
54
+ type: type,
55
+ isHighlight: isHighlight
40
56
  }), element);
41
57
  return element;
42
58
  };
@@ -47,13 +63,13 @@ const containsText = resolvedPos => {
47
63
  } = resolvedPos;
48
64
  return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
49
65
  };
50
- export const createWidgetDecoration = (resolvedPos, type, selection) => {
66
+ export const createWidgetDecoration = (resolvedPos, type, selection, isHighlight) => {
51
67
  // We don't want the cursor to show if it's not text selection
52
68
  // ie. if it's on media selection
53
- if (!(selection instanceof TextSelection) || containsText(resolvedPos) === false) {
69
+ if (!(selection instanceof TextSelection) || containsText(resolvedPos) === false || !selection.empty) {
54
70
  return [];
55
71
  }
56
- return [Decoration.widget(resolvedPos.pos, toDOM(type), {
72
+ return [Decoration.widget(resolvedPos.pos, toDOM(type, isHighlight), {
57
73
  side: -1,
58
74
  key: `${type}WidgetDecoration`,
59
75
  stopEvent: () => true,
@@ -1,10 +1,29 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { isEmptyDocument } from '@atlaskit/editor-common/utils';
3
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
5
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
6
  import { selectionDecoration } from '../ui/selection-decoration';
6
7
  import { createWidgetDecoration } from '../ui/widget-decoration';
7
8
  export var key = new PluginKey('selectionMarker');
9
+ function getDecorations(tr, type) {
10
+ var selection = tr.selection;
11
+ switch (type) {
12
+ case 'none':
13
+ return DecorationSet.empty;
14
+ case 'highlight':
15
+ return DecorationSet.create(tr.doc, [].concat(_toConsumableArray(createWidgetDecoration(selection.$anchor, 'anchor', selection, true)), [selectionDecoration(selection, true)], _toConsumableArray(createWidgetDecoration(selection.$head, 'head', selection, true))));
16
+ case 'blur':
17
+ return DecorationSet.create(tr.doc, [].concat(_toConsumableArray(createWidgetDecoration(selection.$anchor, 'anchor', selection, false)), [selectionDecoration(selection, false)]));
18
+ }
19
+ }
20
+ function getDecorationType(tr, forceHide, shouldHideDecorations) {
21
+ if (shouldHideDecorations || forceHide || isEmptyDocument(tr.doc)) {
22
+ return 'none';
23
+ }
24
+ // TODO: implement "highlight" for AI features
25
+ return 'blur';
26
+ }
8
27
  export var createPlugin = function createPlugin(api) {
9
28
  return new SafePlugin({
10
29
  key: key,
@@ -20,10 +39,9 @@ export var createPlugin = function createPlugin(api) {
20
39
  var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
21
40
  var forceHide = (_tr$getMeta$forceHide = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.forceHide) !== null && _tr$getMeta$forceHide !== void 0 ? _tr$getMeta$forceHide : currentState.forceHide;
22
41
  var shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta2 = tr.getMeta(key)) === null || _tr$getMeta2 === void 0 ? void 0 : _tr$getMeta2.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
23
- var selection = tr.selection;
24
- var decorations = shouldHideDecorations || forceHide ? DecorationSet.empty : DecorationSet.create(tr.doc, [].concat(_toConsumableArray(createWidgetDecoration(selection.$anchor, 'anchor', selection)), [selectionDecoration(selection)], _toConsumableArray(createWidgetDecoration(selection.$head, 'head', selection))));
42
+ var type = getDecorationType(tr, forceHide, shouldHideDecorations);
25
43
  return {
26
- decorations: decorations,
44
+ decorations: getDecorations(tr, type),
27
45
  shouldHideDecorations: shouldHideDecorations,
28
46
  forceHide: forceHide
29
47
  };
@@ -1,8 +1,9 @@
1
1
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
2
- var decorationStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FF)", ";\n border-bottom: 2px solid ", "var(--ds-background-accent-blue-subtler, #cce0ff)", ";\n ");
3
- export var selectionDecoration = function selectionDecoration(selection) {
2
+ var decorationStyle = "\n background-color: ".concat("var(--ds-background-accent-gray-subtler, #DCDFE4)", ";\n ");
3
+ var decorationHighlightStyle = "\n background-color: ".concat("var(--ds-background-accent-blue-subtlest, #E9F2FF)", ";\n border-bottom: 2px solid ", "var(--ds-background-accent-blue-subtler, #cce0ff)", ";\n ");
4
+ export var selectionDecoration = function selectionDecoration(selection, isHighlight) {
4
5
  return Decoration.inline(selection.from, selection.to, {
5
- style: decorationStyle,
6
+ style: isHighlight ? decorationHighlightStyle : decorationStyle,
6
7
  'data-testid': 'selection-marker-selection'
7
8
  });
8
9
  };
@@ -3,8 +3,8 @@ import ReactDOM from 'react-dom';
3
3
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
5
5
  import { Box, xcss } from '@atlaskit/primitives';
6
- // Copied from: platform/packages/editor/editor-plugin-ai/src/ui/modal/styles.tsx
7
- var selectionMarkerStyles = xcss({
6
+ import { N500 } from '@atlaskit/theme/colors';
7
+ var selectionMarkerHighlightStyles = xcss({
8
8
  content: "''",
9
9
  position: 'absolute',
10
10
  backgroundImage: "url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMyIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDMgMjAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMSAxSDBMMSAxLjg1NzE0VjE4LjE0MzNMMCAxOS4wMDA0SDNMMiAxOC4xNDMzVjEuODU3MTRMMyAxSDJIMVoiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3QgeT0iMTkiIHdpZHRoPSIzIiBoZWlnaHQ9IjEiIGZpbGw9IiM1NzlERkYiLz4KPHJlY3Qgd2lkdGg9IjMiIGhlaWdodD0iMSIgZmlsbD0iIzU3OURGRiIvPgo8L3N2Zz4K')",
@@ -21,21 +21,37 @@ var selectionMarkerStyles = xcss({
21
21
  marginRight: '-0.1em',
22
22
  pointerEvents: 'none'
23
23
  });
24
+ var selectionMarkerCursorStyles = xcss({
25
+ content: "''",
26
+ position: 'absolute',
27
+ background: "var(--ds-text, ".concat(N500, ")"),
28
+ width: "var(--ds-space-025, 2px)",
29
+ display: 'inline-block',
30
+ top: 'space.0',
31
+ bottom: "var(--ds-space-negative-025, -2px)",
32
+ left: '1px',
33
+ marginLeft: '-0.1em',
34
+ right: '0px',
35
+ marginRight: '-0.1em',
36
+ pointerEvents: 'none'
37
+ });
24
38
  var Widget = function Widget(_ref) {
25
- var type = _ref.type;
39
+ var type = _ref.type,
40
+ isHighlight = _ref.isHighlight;
26
41
  return /*#__PURE__*/React.createElement(Box, {
27
42
  as: 'span',
28
- xcss: selectionMarkerStyles,
43
+ xcss: isHighlight ? selectionMarkerHighlightStyles : selectionMarkerCursorStyles,
29
44
  testId: "selection-marker-".concat(type, "-cursor"),
30
45
  contentEditable: false
31
46
  });
32
47
  };
33
- var toDOM = function toDOM(type) {
48
+ var toDOM = function toDOM(type, isHighlight) {
34
49
  var element = document.createElement('span');
35
50
  element.contentEditable = 'false';
36
51
  element.setAttribute('style', "position: relative;");
37
52
  ReactDOM.render( /*#__PURE__*/React.createElement(Widget, {
38
- type: type
53
+ type: type,
54
+ isHighlight: isHighlight
39
55
  }), element);
40
56
  return element;
41
57
  };
@@ -44,13 +60,13 @@ var containsText = function containsText(resolvedPos) {
44
60
  nodeAfter = resolvedPos.nodeAfter;
45
61
  return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
46
62
  };
47
- export var createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection) {
63
+ export var createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection, isHighlight) {
48
64
  // We don't want the cursor to show if it's not text selection
49
65
  // ie. if it's on media selection
50
- if (!(selection instanceof TextSelection) || containsText(resolvedPos) === false) {
66
+ if (!(selection instanceof TextSelection) || containsText(resolvedPos) === false || !selection.empty) {
51
67
  return [];
52
68
  }
53
- return [Decoration.widget(resolvedPos.pos, toDOM(type), {
69
+ return [Decoration.widget(resolvedPos.pos, toDOM(type, isHighlight), {
54
70
  side: -1,
55
71
  key: "".concat(type, "WidgetDecoration"),
56
72
  stopEvent: function stopEvent() {
@@ -1,3 +1,3 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- export declare const selectionDecoration: (selection: Selection) => Decoration;
3
+ export declare const selectionDecoration: (selection: Selection, isHighlight: boolean) => Decoration;
@@ -2,5 +2,5 @@ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
4
  type SelectionType = 'anchor' | 'head';
5
- export declare const createWidgetDecoration: (resolvedPos: ResolvedPos, type: SelectionType, selection: Selection) => Decoration[];
5
+ export declare const createWidgetDecoration: (resolvedPos: ResolvedPos, type: SelectionType, selection: Selection, isHighlight: boolean) => Decoration[];
6
6
  export {};
@@ -1,3 +1,3 @@
1
1
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
2
2
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
3
- export declare const selectionDecoration: (selection: Selection) => Decoration;
3
+ export declare const selectionDecoration: (selection: Selection, isHighlight: boolean) => Decoration;
@@ -2,5 +2,5 @@ import type { ResolvedPos } from '@atlaskit/editor-prosemirror/model';
2
2
  import type { Selection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { Decoration } from '@atlaskit/editor-prosemirror/view';
4
4
  type SelectionType = 'anchor' | 'head';
5
- export declare const createWidgetDecoration: (resolvedPos: ResolvedPos, type: SelectionType, selection: Selection) => Decoration[];
5
+ export declare const createWidgetDecoration: (resolvedPos: ResolvedPos, type: SelectionType, selection: Selection, isHighlight: boolean) => Decoration[];
6
6
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-marker",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Selection marker plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,11 +31,12 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^78.17.0",
34
+ "@atlaskit/editor-common": "^78.18.0",
35
35
  "@atlaskit/editor-plugin-focus": "^1.1.0",
36
36
  "@atlaskit/editor-plugin-type-ahead": "^1.0.2",
37
37
  "@atlaskit/editor-prosemirror": "3.0.0",
38
38
  "@atlaskit/primitives": "^5.1.0",
39
+ "@atlaskit/theme": "^12.6.0",
39
40
  "@atlaskit/tokens": "^1.42.0",
40
41
  "@babel/runtime": "^7.0.0",
41
42
  "@emotion/react": "^11.7.1"