@atlaskit/editor-plugin-selection-marker 1.0.0 → 1.1.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 CHANGED
@@ -1 +1,13 @@
1
1
  # @atlaskit/editor-plugin-selection-marker
2
+
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#80131](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80131) [`336116d18762`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/336116d18762) - Expose a new method hideDecoration on selection marker which can be used to temporarily disable the selection marker behaviour.
8
+
9
+ ## 1.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#81026](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81026) [`9f75ed822487`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9f75ed822487) - [ux] Fix selection marker background with input fields (ie. expands).
@@ -9,8 +9,8 @@ var _react = _interopRequireWildcard(require("react"));
9
9
  var _hooks = require("@atlaskit/editor-common/hooks");
10
10
  var _main = require("./pm-plugins/main");
11
11
  var _globalStyles = require("./ui/global-styles");
12
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
12
+ 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); }
13
+ 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; }
14
14
  var selectionMarkerPlugin = exports.selectionMarkerPlugin = function selectionMarkerPlugin(_ref) {
15
15
  var api = _ref.api;
16
16
  return {
@@ -23,14 +23,43 @@ var selectionMarkerPlugin = exports.selectionMarkerPlugin = function selectionMa
23
23
  }
24
24
  }];
25
25
  },
26
- usePluginHook: function usePluginHook(_ref2) {
27
- var editorView = _ref2.editorView;
26
+ getSharedState: function getSharedState(editorState) {
27
+ var _key$getState$forceHi, _key$getState;
28
+ if (!editorState) {
29
+ return undefined;
30
+ }
31
+ return {
32
+ isForcedHidden: (_key$getState$forceHi = (_key$getState = _main.key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.forceHide) !== null && _key$getState$forceHi !== void 0 ? _key$getState$forceHi : false
33
+ };
34
+ },
35
+ actions: {
36
+ // For now this is a very simple locking mechanism that only allows one
37
+ // plugin to hide / release at a time.
38
+ hideDecoration: function hideDecoration() {
39
+ var _api$selectionMarker, _api$core;
40
+ if (api !== null && api !== void 0 && (_api$selectionMarker = api.selectionMarker) !== null && _api$selectionMarker !== void 0 && (_api$selectionMarker = _api$selectionMarker.sharedState.currentState()) !== null && _api$selectionMarker !== void 0 && _api$selectionMarker.isForcedHidden) {
41
+ return undefined;
42
+ }
43
+ var success = api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(function (_ref2) {
44
+ var tr = _ref2.tr;
45
+ return tr.setMeta(_main.key, {
46
+ forceHide: true
47
+ });
48
+ });
49
+ if (!success) {
50
+ return undefined;
51
+ }
52
+ return cleanupHiddenDecoration(api);
53
+ }
54
+ },
55
+ usePluginHook: function usePluginHook(_ref3) {
56
+ var editorView = _ref3.editorView;
28
57
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['focus', 'typeAhead']),
29
58
  focusState = _useSharedPluginState.focusState,
30
59
  typeAheadState = _useSharedPluginState.typeAheadState;
31
60
  (0, _react.useEffect)(function () {
32
- var _ref3, _typeAheadState$isOpe;
33
- var shouldHide = (_ref3 = (focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus) || ((_typeAheadState$isOpe = typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen) !== null && _typeAheadState$isOpe !== void 0 ? _typeAheadState$isOpe : false)) !== null && _ref3 !== void 0 ? _ref3 : true;
61
+ var _ref4, _typeAheadState$isOpe;
62
+ var shouldHide = (_ref4 = (focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus) || ((_typeAheadState$isOpe = typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen) !== null && _typeAheadState$isOpe !== void 0 ? _typeAheadState$isOpe : false)) !== null && _ref4 !== void 0 ? _ref4 : true;
34
63
  requestAnimationFrame(function () {
35
64
  return (0, _main.dispatchShouldHideDecorations)(editorView, shouldHide);
36
65
  });
@@ -40,4 +69,20 @@ var selectionMarkerPlugin = exports.selectionMarkerPlugin = function selectionMa
40
69
  return /*#__PURE__*/_react.default.createElement(_globalStyles.GlobalStylesWrapper, null);
41
70
  }
42
71
  };
43
- };
72
+ };
73
+ function cleanupHiddenDecoration(api) {
74
+ var hasRun = false;
75
+ return function () {
76
+ var _api$selectionMarker2;
77
+ if (!hasRun && api !== null && api !== void 0 && (_api$selectionMarker2 = api.selectionMarker) !== null && _api$selectionMarker2 !== void 0 && (_api$selectionMarker2 = _api$selectionMarker2.sharedState.currentState()) !== null && _api$selectionMarker2 !== void 0 && _api$selectionMarker2.isForcedHidden) {
78
+ var _api$core2;
79
+ hasRun = true;
80
+ return api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(function (_ref5) {
81
+ var tr = _ref5.tr;
82
+ return tr.setMeta(_main.key, {
83
+ forceHide: false
84
+ });
85
+ });
86
+ }
87
+ };
88
+ }
@@ -21,22 +21,20 @@ var createPlugin = exports.createPlugin = function createPlugin(api) {
21
21
  init: function init() {
22
22
  return {
23
23
  decorations: _view.DecorationSet.empty,
24
- shouldHideDecorations: true
24
+ shouldHideDecorations: true,
25
+ forceHide: false
25
26
  };
26
27
  },
27
28
  apply: function apply(tr, currentState) {
28
- var _tr$getMeta$shouldHid, _tr$getMeta;
29
- var shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
29
+ var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
30
+ 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
+ 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;
30
32
  var selection = tr.selection;
31
- if (shouldHideDecorations) {
32
- return {
33
- decorations: _view.DecorationSet.empty,
34
- shouldHideDecorations: shouldHideDecorations
35
- };
36
- }
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))));
37
34
  return {
38
- decorations: _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)))),
39
- shouldHideDecorations: shouldHideDecorations
35
+ decorations: decorations,
36
+ shouldHideDecorations: shouldHideDecorations,
37
+ forceHide: forceHide
40
38
  };
41
39
  }
42
40
  },
@@ -9,9 +9,11 @@ var _react = require("@emotion/react");
9
9
 
10
10
  // Unset the selection background color as we are using our own
11
11
  // Otherwise we might have a mix of grey + our selection marker depending on the state.
12
+ // We do not apply this reset to input fields (ie. expand case) because otherwise
13
+ // selection highlight will not show on those.
12
14
  var globalStyles = (0, _react.css)({
13
15
  // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
14
- '.ProseMirror:not(:focus) ::selection': {
16
+ '.ProseMirror:not(:focus) ::selection:not(input)': {
15
17
  background: 'unset'
16
18
  }
17
19
  });
@@ -49,7 +49,7 @@ var toDOM = function toDOM(type) {
49
49
  var containsText = function containsText(resolvedPos) {
50
50
  var nodeBefore = resolvedPos.nodeBefore,
51
51
  nodeAfter = resolvedPos.nodeAfter;
52
- return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isText) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isText);
52
+ return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
53
53
  };
54
54
  var createWidgetDecoration = exports.createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection) {
55
55
  // We don't want the cursor to show if it's not text selection
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
- import { createPlugin, dispatchShouldHideDecorations } from './pm-plugins/main';
3
+ import { createPlugin, dispatchShouldHideDecorations, key } from './pm-plugins/main';
4
4
  import { GlobalStylesWrapper } from './ui/global-styles';
5
5
  export const selectionMarkerPlugin = ({
6
6
  api
@@ -13,6 +13,34 @@ export const selectionMarkerPlugin = ({
13
13
  plugin: () => createPlugin(api)
14
14
  }];
15
15
  },
16
+ getSharedState(editorState) {
17
+ var _key$getState$forceHi, _key$getState;
18
+ if (!editorState) {
19
+ return undefined;
20
+ }
21
+ return {
22
+ isForcedHidden: (_key$getState$forceHi = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.forceHide) !== null && _key$getState$forceHi !== void 0 ? _key$getState$forceHi : false
23
+ };
24
+ },
25
+ actions: {
26
+ // For now this is a very simple locking mechanism that only allows one
27
+ // plugin to hide / release at a time.
28
+ hideDecoration: () => {
29
+ var _api$selectionMarker, _api$selectionMarker$, _api$core;
30
+ if (api !== null && api !== void 0 && (_api$selectionMarker = api.selectionMarker) !== null && _api$selectionMarker !== void 0 && (_api$selectionMarker$ = _api$selectionMarker.sharedState.currentState()) !== null && _api$selectionMarker$ !== void 0 && _api$selectionMarker$.isForcedHidden) {
31
+ return undefined;
32
+ }
33
+ const success = api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
34
+ tr
35
+ }) => tr.setMeta(key, {
36
+ forceHide: true
37
+ }));
38
+ if (!success) {
39
+ return undefined;
40
+ }
41
+ return cleanupHiddenDecoration(api);
42
+ }
43
+ },
16
44
  usePluginHook({
17
45
  editorView
18
46
  }) {
@@ -30,4 +58,19 @@ export const selectionMarkerPlugin = ({
30
58
  return /*#__PURE__*/React.createElement(GlobalStylesWrapper, null);
31
59
  }
32
60
  };
33
- };
61
+ };
62
+ function cleanupHiddenDecoration(api) {
63
+ let hasRun = false;
64
+ return () => {
65
+ var _api$selectionMarker2, _api$selectionMarker3;
66
+ if (!hasRun && api !== null && api !== void 0 && (_api$selectionMarker2 = api.selectionMarker) !== null && _api$selectionMarker2 !== void 0 && (_api$selectionMarker3 = _api$selectionMarker2.sharedState.currentState()) !== null && _api$selectionMarker3 !== void 0 && _api$selectionMarker3.isForcedHidden) {
67
+ var _api$core2;
68
+ hasRun = true;
69
+ return api === null || api === void 0 ? void 0 : (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(({
70
+ tr
71
+ }) => tr.setMeta(key, {
72
+ forceHide: false
73
+ }));
74
+ }
75
+ };
76
+ }
@@ -11,24 +11,22 @@ export const createPlugin = api => {
11
11
  init() {
12
12
  return {
13
13
  decorations: DecorationSet.empty,
14
- shouldHideDecorations: true
14
+ shouldHideDecorations: true,
15
+ forceHide: false
15
16
  };
16
17
  },
17
18
  apply(tr, currentState) {
18
- var _tr$getMeta$shouldHid, _tr$getMeta;
19
- const shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
19
+ var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
20
+ 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
+ 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;
20
22
  const {
21
23
  selection
22
24
  } = tr;
23
- if (shouldHideDecorations) {
24
- return {
25
- decorations: DecorationSet.empty,
26
- shouldHideDecorations
27
- };
28
- }
25
+ const decorations = shouldHideDecorations || forceHide ? DecorationSet.empty : DecorationSet.create(tr.doc, [...createWidgetDecoration(selection.$anchor, 'anchor', selection), selectionDecoration(selection), ...createWidgetDecoration(selection.$head, 'head', selection)]);
29
26
  return {
30
- decorations: DecorationSet.create(tr.doc, [...createWidgetDecoration(selection.$anchor, 'anchor', selection), selectionDecoration(selection), ...createWidgetDecoration(selection.$head, 'head', selection)]),
31
- shouldHideDecorations
27
+ decorations,
28
+ shouldHideDecorations,
29
+ forceHide
32
30
  };
33
31
  }
34
32
  },
@@ -3,9 +3,11 @@ import { css, Global, jsx } from '@emotion/react';
3
3
 
4
4
  // Unset the selection background color as we are using our own
5
5
  // Otherwise we might have a mix of grey + our selection marker depending on the state.
6
+ // We do not apply this reset to input fields (ie. expand case) because otherwise
7
+ // selection highlight will not show on those.
6
8
  const globalStyles = css({
7
9
  // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
8
- '.ProseMirror:not(:focus) ::selection': {
10
+ '.ProseMirror:not(:focus) ::selection:not(input)': {
9
11
  background: 'unset'
10
12
  }
11
13
  });
@@ -45,7 +45,7 @@ const containsText = resolvedPos => {
45
45
  nodeBefore,
46
46
  nodeAfter
47
47
  } = resolvedPos;
48
- return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isText) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isText);
48
+ return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
49
49
  };
50
50
  export const createWidgetDecoration = (resolvedPos, type, selection) => {
51
51
  // We don't want the cursor to show if it's not text selection
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
- import { createPlugin, dispatchShouldHideDecorations } from './pm-plugins/main';
3
+ import { createPlugin, dispatchShouldHideDecorations, key } from './pm-plugins/main';
4
4
  import { GlobalStylesWrapper } from './ui/global-styles';
5
5
  export var selectionMarkerPlugin = function selectionMarkerPlugin(_ref) {
6
6
  var api = _ref.api;
@@ -14,14 +14,43 @@ export var selectionMarkerPlugin = function selectionMarkerPlugin(_ref) {
14
14
  }
15
15
  }];
16
16
  },
17
- usePluginHook: function usePluginHook(_ref2) {
18
- var editorView = _ref2.editorView;
17
+ getSharedState: function getSharedState(editorState) {
18
+ var _key$getState$forceHi, _key$getState;
19
+ if (!editorState) {
20
+ return undefined;
21
+ }
22
+ return {
23
+ isForcedHidden: (_key$getState$forceHi = (_key$getState = key.getState(editorState)) === null || _key$getState === void 0 ? void 0 : _key$getState.forceHide) !== null && _key$getState$forceHi !== void 0 ? _key$getState$forceHi : false
24
+ };
25
+ },
26
+ actions: {
27
+ // For now this is a very simple locking mechanism that only allows one
28
+ // plugin to hide / release at a time.
29
+ hideDecoration: function hideDecoration() {
30
+ var _api$selectionMarker, _api$core;
31
+ if (api !== null && api !== void 0 && (_api$selectionMarker = api.selectionMarker) !== null && _api$selectionMarker !== void 0 && (_api$selectionMarker = _api$selectionMarker.sharedState.currentState()) !== null && _api$selectionMarker !== void 0 && _api$selectionMarker.isForcedHidden) {
32
+ return undefined;
33
+ }
34
+ var success = api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(function (_ref2) {
35
+ var tr = _ref2.tr;
36
+ return tr.setMeta(key, {
37
+ forceHide: true
38
+ });
39
+ });
40
+ if (!success) {
41
+ return undefined;
42
+ }
43
+ return cleanupHiddenDecoration(api);
44
+ }
45
+ },
46
+ usePluginHook: function usePluginHook(_ref3) {
47
+ var editorView = _ref3.editorView;
19
48
  var _useSharedPluginState = useSharedPluginState(api, ['focus', 'typeAhead']),
20
49
  focusState = _useSharedPluginState.focusState,
21
50
  typeAheadState = _useSharedPluginState.typeAheadState;
22
51
  useEffect(function () {
23
- var _ref3, _typeAheadState$isOpe;
24
- var shouldHide = (_ref3 = (focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus) || ((_typeAheadState$isOpe = typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen) !== null && _typeAheadState$isOpe !== void 0 ? _typeAheadState$isOpe : false)) !== null && _ref3 !== void 0 ? _ref3 : true;
52
+ var _ref4, _typeAheadState$isOpe;
53
+ var shouldHide = (_ref4 = (focusState === null || focusState === void 0 ? void 0 : focusState.hasFocus) || ((_typeAheadState$isOpe = typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen) !== null && _typeAheadState$isOpe !== void 0 ? _typeAheadState$isOpe : false)) !== null && _ref4 !== void 0 ? _ref4 : true;
25
54
  requestAnimationFrame(function () {
26
55
  return dispatchShouldHideDecorations(editorView, shouldHide);
27
56
  });
@@ -31,4 +60,20 @@ export var selectionMarkerPlugin = function selectionMarkerPlugin(_ref) {
31
60
  return /*#__PURE__*/React.createElement(GlobalStylesWrapper, null);
32
61
  }
33
62
  };
34
- };
63
+ };
64
+ function cleanupHiddenDecoration(api) {
65
+ var hasRun = false;
66
+ return function () {
67
+ var _api$selectionMarker2;
68
+ if (!hasRun && api !== null && api !== void 0 && (_api$selectionMarker2 = api.selectionMarker) !== null && _api$selectionMarker2 !== void 0 && (_api$selectionMarker2 = _api$selectionMarker2.sharedState.currentState()) !== null && _api$selectionMarker2 !== void 0 && _api$selectionMarker2.isForcedHidden) {
69
+ var _api$core2;
70
+ hasRun = true;
71
+ return api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions.execute(function (_ref5) {
72
+ var tr = _ref5.tr;
73
+ return tr.setMeta(key, {
74
+ forceHide: false
75
+ });
76
+ });
77
+ }
78
+ };
79
+ }
@@ -12,22 +12,20 @@ export var createPlugin = function createPlugin(api) {
12
12
  init: function init() {
13
13
  return {
14
14
  decorations: DecorationSet.empty,
15
- shouldHideDecorations: true
15
+ shouldHideDecorations: true,
16
+ forceHide: false
16
17
  };
17
18
  },
18
19
  apply: function apply(tr, currentState) {
19
- var _tr$getMeta$shouldHid, _tr$getMeta;
20
- var shouldHideDecorations = (_tr$getMeta$shouldHid = (_tr$getMeta = tr.getMeta(key)) === null || _tr$getMeta === void 0 ? void 0 : _tr$getMeta.shouldHideDecorations) !== null && _tr$getMeta$shouldHid !== void 0 ? _tr$getMeta$shouldHid : currentState.shouldHideDecorations;
20
+ var _tr$getMeta$forceHide, _tr$getMeta, _tr$getMeta$shouldHid, _tr$getMeta2;
21
+ 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
+ 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;
21
23
  var selection = tr.selection;
22
- if (shouldHideDecorations) {
23
- return {
24
- decorations: DecorationSet.empty,
25
- shouldHideDecorations: shouldHideDecorations
26
- };
27
- }
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))));
28
25
  return {
29
- decorations: DecorationSet.create(tr.doc, [].concat(_toConsumableArray(createWidgetDecoration(selection.$anchor, 'anchor', selection)), [selectionDecoration(selection)], _toConsumableArray(createWidgetDecoration(selection.$head, 'head', selection)))),
30
- shouldHideDecorations: shouldHideDecorations
26
+ decorations: decorations,
27
+ shouldHideDecorations: shouldHideDecorations,
28
+ forceHide: forceHide
31
29
  };
32
30
  }
33
31
  },
@@ -3,9 +3,11 @@ import { css, Global, jsx } from '@emotion/react';
3
3
 
4
4
  // Unset the selection background color as we are using our own
5
5
  // Otherwise we might have a mix of grey + our selection marker depending on the state.
6
+ // We do not apply this reset to input fields (ie. expand case) because otherwise
7
+ // selection highlight will not show on those.
6
8
  var globalStyles = css({
7
9
  // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
8
- '.ProseMirror:not(:focus) ::selection': {
10
+ '.ProseMirror:not(:focus) ::selection:not(input)': {
9
11
  background: 'unset'
10
12
  }
11
13
  });
@@ -42,7 +42,7 @@ var toDOM = function toDOM(type) {
42
42
  var containsText = function containsText(resolvedPos) {
43
43
  var nodeBefore = resolvedPos.nodeBefore,
44
44
  nodeAfter = resolvedPos.nodeAfter;
45
- return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isText) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isText);
45
+ return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.isInline) || (nodeAfter === null || nodeAfter === void 0 ? void 0 : nodeAfter.isInline);
46
46
  };
47
47
  export var createWidgetDecoration = function createWidgetDecoration(resolvedPos, type, selection) {
48
48
  // We don't want the cursor to show if it's not text selection
@@ -1,2 +1,2 @@
1
1
  export { selectionMarkerPlugin } from './plugin';
2
- export type { SelectionMarkerPlugin } from './types';
2
+ export type { SelectionMarkerPlugin, ReleaseHiddenDecoration } from './types';
@@ -7,11 +7,13 @@ import type { SelectionMarkerPlugin } from '../types';
7
7
  interface PluginState {
8
8
  decorations: DecorationSet;
9
9
  shouldHideDecorations: boolean;
10
+ forceHide: boolean;
10
11
  }
11
12
  export declare const key: PluginKey<PluginState>;
12
13
  export declare const createPlugin: (api: ExtractInjectionAPI<SelectionMarkerPlugin> | undefined) => SafePlugin<{
13
14
  decorations: DecorationSet;
14
15
  shouldHideDecorations: any;
16
+ forceHide: any;
15
17
  }>;
16
18
  export declare function dispatchShouldHideDecorations(editorView: EditorView, shouldHideDecorations: boolean): void;
17
19
  export {};
@@ -1,6 +1,13 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
3
3
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
4
+ export type ReleaseHiddenDecoration = () => boolean | undefined;
4
5
  export type SelectionMarkerPlugin = NextEditorPlugin<'selectionMarker', {
5
6
  dependencies: [FocusPlugin, OptionalPlugin<TypeAheadPlugin>];
7
+ sharedState: {
8
+ isForcedHidden: boolean;
9
+ } | undefined;
10
+ actions: {
11
+ hideDecoration: () => ReleaseHiddenDecoration | undefined;
12
+ };
6
13
  }>;
@@ -1,2 +1,2 @@
1
1
  export { selectionMarkerPlugin } from './plugin';
2
- export type { SelectionMarkerPlugin } from './types';
2
+ export type { SelectionMarkerPlugin, ReleaseHiddenDecoration } from './types';
@@ -7,11 +7,13 @@ import type { SelectionMarkerPlugin } from '../types';
7
7
  interface PluginState {
8
8
  decorations: DecorationSet;
9
9
  shouldHideDecorations: boolean;
10
+ forceHide: boolean;
10
11
  }
11
12
  export declare const key: PluginKey<PluginState>;
12
13
  export declare const createPlugin: (api: ExtractInjectionAPI<SelectionMarkerPlugin> | undefined) => SafePlugin<{
13
14
  decorations: DecorationSet;
14
15
  shouldHideDecorations: any;
16
+ forceHide: any;
15
17
  }>;
16
18
  export declare function dispatchShouldHideDecorations(editorView: EditorView, shouldHideDecorations: boolean): void;
17
19
  export {};
@@ -1,9 +1,16 @@
1
1
  import type { NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { FocusPlugin } from '@atlaskit/editor-plugin-focus';
3
3
  import type { TypeAheadPlugin } from '@atlaskit/editor-plugin-type-ahead';
4
+ export type ReleaseHiddenDecoration = () => boolean | undefined;
4
5
  export type SelectionMarkerPlugin = NextEditorPlugin<'selectionMarker', {
5
6
  dependencies: [
6
7
  FocusPlugin,
7
8
  OptionalPlugin<TypeAheadPlugin>
8
9
  ];
10
+ sharedState: {
11
+ isForcedHidden: boolean;
12
+ } | undefined;
13
+ actions: {
14
+ hideDecoration: () => ReleaseHiddenDecoration | undefined;
15
+ };
9
16
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection-marker",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Selection marker plugin for @atlaskit/editor-core.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,12 +31,12 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^78.10.0",
34
+ "@atlaskit/editor-common": "^78.14.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
- "@atlaskit/primitives": "^4.0.0",
39
- "@atlaskit/tokens": "^1.38.0",
38
+ "@atlaskit/primitives": "^4.1.0",
39
+ "@atlaskit/tokens": "^1.41.0",
40
40
  "@babel/runtime": "^7.0.0",
41
41
  "@emotion/react": "^11.7.1"
42
42
  },