@atlaskit/editor-plugin-selection 7.0.0 → 7.0.2

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,19 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 7.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 7.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`0bf8d0bd8bf2c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0bf8d0bd8bf2c) -
14
+ [ux] EDITOR-4276 Apply block selection visual style only from drag handle
15
+ - Updated dependencies
16
+
3
17
  ## 7.0.0
4
18
 
5
19
  ### Patch Changes
@@ -96,7 +96,9 @@ var getSelectionFragment = exports.getSelectionFragment = function getSelectionF
96
96
  return fragment;
97
97
  };
98
98
  };
99
- var getSelectionLocalIds = exports.getSelectionLocalIds = function getSelectionLocalIds(api) {
99
+ var getSelectionLocalIds = exports.getSelectionLocalIds =
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
+ function getSelectionLocalIds(api) {
100
102
  return function () {
101
103
  var _api$selection$shared2, _selection;
102
104
  var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
@@ -26,6 +26,7 @@ var getInitialState = exports.getInitialState = function getInitialState(state)
26
26
  var createPlugin = exports.createPlugin = function createPlugin(api, dispatch, dispatchAnalyticsEvent) {
27
27
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
28
28
  var cursorHidden = false;
29
+ var blockSelection;
29
30
  return new _safePlugin.SafePlugin({
30
31
  key: _types.selectionPluginKey,
31
32
  state: (0, _pluginFactory.createPluginState)(dispatch, getInitialState),
@@ -33,36 +34,46 @@ var createPlugin = exports.createPlugin = function createPlugin(api, dispatch, d
33
34
  var tr = newEditorState.tr;
34
35
  var manualSelection;
35
36
  var hideCursorChanged = false;
37
+ var blockSelectionChanged = false;
36
38
  var needsHideCursor = (0, _platformFeatureFlags.fg)('platform_editor_ai_generic_prep_for_aifc_2');
37
39
  var needsManualSelection = (0, _experiments.editorExperiment)('platform_editor_element_drag_and_drop_multiselect', true);
38
- if (needsHideCursor || needsManualSelection) {
39
- for (var i = transactions.length - 1; i >= 0; i--) {
40
- var meta = transactions[i].getMeta(_types.selectionPluginKey);
41
- if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
42
- var newHideCursorValue = meta.hideCursor;
43
- if (cursorHidden !== newHideCursorValue) {
44
- cursorHidden = newHideCursorValue;
45
- hideCursorChanged = true;
46
- }
40
+ var needsBlockSelection = (0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true);
41
+ for (var i = transactions.length - 1; i >= 0; i--) {
42
+ var meta = transactions[i].getMeta(_types.selectionPluginKey);
43
+ if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
44
+ var newHideCursorValue = meta.hideCursor;
45
+ if (cursorHidden !== newHideCursorValue) {
46
+ cursorHidden = newHideCursorValue;
47
+ hideCursorChanged = true;
47
48
  }
48
- if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
49
- manualSelection = meta.manualSelection;
50
- if (!needsHideCursor) {
51
- break;
52
- }
49
+ }
50
+ if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
51
+ manualSelection = meta.manualSelection;
52
+ if (!needsHideCursor && !needsBlockSelection) {
53
+ break;
54
+ }
55
+ }
56
+ if (needsBlockSelection) {
57
+ if (meta !== null && meta !== void 0 && meta.setBlockSelection) {
58
+ blockSelection = meta.setBlockSelection;
59
+ blockSelectionChanged = true;
60
+ }
61
+ if (meta !== null && meta !== void 0 && meta.clearBlockSelection) {
62
+ blockSelection = undefined;
63
+ blockSelectionChanged = true;
53
64
  }
54
65
  }
55
66
  }
56
67
  if (!(0, _utils.shouldRecalcDecorations)({
57
68
  oldEditorState: oldEditorState,
58
69
  newEditorState: newEditorState
59
- }) && !manualSelection && !hideCursorChanged) {
70
+ }) && !manualSelection && !hideCursorChanged && !blockSelectionChanged) {
60
71
  return;
61
72
  }
62
73
  tr.setMeta(_types.selectionPluginKey, {
63
74
  type: _actions.SelectionActionTypes.SET_DECORATIONS,
64
75
  selection: tr.selection,
65
- decorationSet: (0, _utils.getDecorations)(tr, manualSelection, cursorHidden)
76
+ decorationSet: (0, _utils.getDecorations)(tr, manualSelection, cursorHidden, blockSelection)
66
77
  });
67
78
  return tr;
68
79
  },
@@ -14,9 +14,10 @@ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
14
14
  var _view = require("@atlaskit/editor-prosemirror/view");
15
15
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
17
18
  var _types = require("../types");
18
19
  var _hideCursorDecoration = require("./cursor/ui/hide-cursor-decoration");
19
- var getDecorations = exports.getDecorations = function getDecorations(tr, manualSelection, hideCursor) {
20
+ var getDecorations = exports.getDecorations = function getDecorations(tr, manualSelection, hideCursor, blockSelection) {
20
21
  var selection = tr.selection;
21
22
  var decorations = [];
22
23
  if (hideCursor && (0, _platformFeatureFlags.fg)('platform_editor_ai_generic_prep_for_aifc_2')) {
@@ -32,14 +33,19 @@ var getDecorations = exports.getDecorations = function getDecorations(tr, manual
32
33
  if (manualSelection && manualSelection.anchor >= 0 && manualSelection.head >= 0 && manualSelection.anchor <= tr.doc.nodeSize && manualSelection.head <= tr.doc.nodeSize) {
33
34
  selection = _state.TextSelection.create(tr.doc, manualSelection.anchor, manualSelection.head);
34
35
  }
35
- var selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(function (_ref) {
36
- var node = _ref.node,
37
- pos = _ref.pos;
38
- return _view.Decoration.node(pos, pos + node.nodeSize, {
39
- class: _editorSharedStyles.akEditorSelectedNodeClassName
36
+
37
+ // Only apply node decorations when there is an active block selection.
38
+ // When there is no block selection, text selections should use native browser selection appearance.
39
+ if (!(0, _expValEquals.expValEquals)('platform_editor_block_menu', 'isEnabled', true) || blockSelection) {
40
+ var selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(function (_ref) {
41
+ var node = _ref.node,
42
+ pos = _ref.pos;
43
+ return _view.Decoration.node(pos, pos + node.nodeSize, {
44
+ class: _editorSharedStyles.akEditorSelectedNodeClassName
45
+ });
40
46
  });
41
- });
42
- decorations.push.apply(decorations, (0, _toConsumableArray2.default)(selectionDecorations));
47
+ decorations.push.apply(decorations, (0, _toConsumableArray2.default)(selectionDecorations));
48
+ }
43
49
  return _view.DecorationSet.create(tr.doc, decorations);
44
50
  }
45
51
  return decorations.length > 0 ? _view.DecorationSet.create(tr.doc, decorations) : _view.DecorationSet.empty;
@@ -56,21 +56,41 @@ var hideCursor = function hideCursor(hide) {
56
56
  }));
57
57
  };
58
58
  };
59
- var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref5) {
60
- var api = _ref5.api,
61
- options = _ref5.config;
59
+ var setBlockSelection = function setBlockSelection(selection) {
60
+ return function (_ref5) {
61
+ var tr = _ref5.tr;
62
+ var currMeta = tr.getMeta(_types.selectionPluginKey);
63
+ return tr.setMeta(_types.selectionPluginKey, _objectSpread(_objectSpread({}, currMeta), {}, {
64
+ setBlockSelection: selection
65
+ }));
66
+ };
67
+ };
68
+ var clearBlockSelection = function clearBlockSelection() {
69
+ return function (_ref6) {
70
+ var tr = _ref6.tr;
71
+ var currMeta = tr.getMeta(_types.selectionPluginKey);
72
+ return tr.setMeta(_types.selectionPluginKey, _objectSpread(_objectSpread({}, currMeta), {}, {
73
+ clearBlockSelection: true
74
+ }));
75
+ };
76
+ };
77
+ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref7) {
78
+ var api = _ref7.api,
79
+ options = _ref7.config;
62
80
  return {
63
81
  name: 'selection',
64
82
  commands: {
65
83
  displayGapCursor: displayGapCursor,
66
84
  clearManualSelection: clearManualSelection,
67
85
  hideCursor: hideCursor,
68
- setManualSelection: setManualSelection
86
+ setManualSelection: setManualSelection,
87
+ setBlockSelection: setBlockSelection,
88
+ clearBlockSelection: clearBlockSelection
69
89
  },
70
90
  actions: {
71
- selectNearNode: function selectNearNode(_ref6) {
72
- var selectionRelativeToNode = _ref6.selectionRelativeToNode,
73
- selection = _ref6.selection;
91
+ selectNearNode: function selectNearNode(_ref8) {
92
+ var selectionRelativeToNode = _ref8.selectionRelativeToNode,
93
+ selection = _ref8.selection;
74
94
  return function (state) {
75
95
  return (0, _commands.selectNearNode)(selectionRelativeToNode, selection)({
76
96
  tr: state.tr
@@ -93,9 +113,9 @@ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref5)
93
113
  pmPlugins: function pmPlugins() {
94
114
  return [{
95
115
  name: 'selection',
96
- plugin: function plugin(_ref7) {
97
- var dispatch = _ref7.dispatch,
98
- dispatchAnalyticsEvent = _ref7.dispatchAnalyticsEvent;
116
+ plugin: function plugin(_ref9) {
117
+ var dispatch = _ref9.dispatch,
118
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
99
119
  return (0, _selectionMain.createPlugin)(api, dispatch, dispatchAnalyticsEvent, options);
100
120
  }
101
121
  }, {
@@ -76,7 +76,9 @@ export const getSelectionFragment = api => () => {
76
76
  });
77
77
  return fragment;
78
78
  };
79
- export const getSelectionLocalIds = api => () => {
79
+ export const getSelectionLocalIds =
80
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
+ api => () => {
80
82
  var _api$selection$shared3, _api$selection$shared4, _selection;
81
83
  let selection = api === null || api === void 0 ? void 0 : (_api$selection$shared3 = api.selection.sharedState) === null || _api$selection$shared3 === void 0 ? void 0 : (_api$selection$shared4 = _api$selection$shared3.currentState()) === null || _api$selection$shared4 === void 0 ? void 0 : _api$selection$shared4.selection;
82
84
  if ((_selection = selection) !== null && _selection !== void 0 && _selection.empty) {
@@ -17,6 +17,7 @@ export const getInitialState = state => ({
17
17
  });
18
18
  export const createPlugin = (api, dispatch, dispatchAnalyticsEvent, options = {}) => {
19
19
  let cursorHidden = false;
20
+ let blockSelection;
20
21
  return new SafePlugin({
21
22
  key: selectionPluginKey,
22
23
  state: createPluginState(dispatch, getInitialState),
@@ -26,36 +27,46 @@ export const createPlugin = (api, dispatch, dispatchAnalyticsEvent, options = {}
26
27
  } = newEditorState;
27
28
  let manualSelection;
28
29
  let hideCursorChanged = false;
30
+ let blockSelectionChanged = false;
29
31
  const needsHideCursor = fg('platform_editor_ai_generic_prep_for_aifc_2');
30
32
  const needsManualSelection = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
31
- if (needsHideCursor || needsManualSelection) {
32
- for (let i = transactions.length - 1; i >= 0; i--) {
33
- const meta = transactions[i].getMeta(selectionPluginKey);
34
- if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
35
- const newHideCursorValue = meta.hideCursor;
36
- if (cursorHidden !== newHideCursorValue) {
37
- cursorHidden = newHideCursorValue;
38
- hideCursorChanged = true;
39
- }
33
+ const needsBlockSelection = expValEquals('platform_editor_block_menu', 'isEnabled', true);
34
+ for (let i = transactions.length - 1; i >= 0; i--) {
35
+ const meta = transactions[i].getMeta(selectionPluginKey);
36
+ if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
37
+ const newHideCursorValue = meta.hideCursor;
38
+ if (cursorHidden !== newHideCursorValue) {
39
+ cursorHidden = newHideCursorValue;
40
+ hideCursorChanged = true;
40
41
  }
41
- if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
42
- manualSelection = meta.manualSelection;
43
- if (!needsHideCursor) {
44
- break;
45
- }
42
+ }
43
+ if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
44
+ manualSelection = meta.manualSelection;
45
+ if (!needsHideCursor && !needsBlockSelection) {
46
+ break;
47
+ }
48
+ }
49
+ if (needsBlockSelection) {
50
+ if (meta !== null && meta !== void 0 && meta.setBlockSelection) {
51
+ blockSelection = meta.setBlockSelection;
52
+ blockSelectionChanged = true;
53
+ }
54
+ if (meta !== null && meta !== void 0 && meta.clearBlockSelection) {
55
+ blockSelection = undefined;
56
+ blockSelectionChanged = true;
46
57
  }
47
58
  }
48
59
  }
49
60
  if (!shouldRecalcDecorations({
50
61
  oldEditorState,
51
62
  newEditorState
52
- }) && !manualSelection && !hideCursorChanged) {
63
+ }) && !manualSelection && !hideCursorChanged && !blockSelectionChanged) {
53
64
  return;
54
65
  }
55
66
  tr.setMeta(selectionPluginKey, {
56
67
  type: SelectionActionTypes.SET_DECORATIONS,
57
68
  selection: tr.selection,
58
- decorationSet: getDecorations(tr, manualSelection, cursorHidden)
69
+ decorationSet: getDecorations(tr, manualSelection, cursorHidden, blockSelection)
59
70
  });
60
71
  return tr;
61
72
  },
@@ -5,9 +5,10 @@ import { findParentNode, findParentNodeClosestToPos, flatten, hasParentNode } fr
5
5
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
7
7
  import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
8
9
  import { selectionPluginKey } from '../types';
9
10
  import { createHideCursorDecoration } from './cursor/ui/hide-cursor-decoration';
10
- export const getDecorations = (tr, manualSelection, hideCursor) => {
11
+ export const getDecorations = (tr, manualSelection, hideCursor, blockSelection) => {
11
12
  let selection = tr.selection;
12
13
  const decorations = [];
13
14
  if (hideCursor && fg('platform_editor_ai_generic_prep_for_aifc_2')) {
@@ -23,15 +24,20 @@ export const getDecorations = (tr, manualSelection, hideCursor) => {
23
24
  if (manualSelection && manualSelection.anchor >= 0 && manualSelection.head >= 0 && manualSelection.anchor <= tr.doc.nodeSize && manualSelection.head <= tr.doc.nodeSize) {
24
25
  selection = TextSelection.create(tr.doc, manualSelection.anchor, manualSelection.head);
25
26
  }
26
- const selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(({
27
- node,
28
- pos
29
- }) => {
30
- return Decoration.node(pos, pos + node.nodeSize, {
31
- class: akEditorSelectedNodeClassName
27
+
28
+ // Only apply node decorations when there is an active block selection.
29
+ // When there is no block selection, text selections should use native browser selection appearance.
30
+ if (!expValEquals('platform_editor_block_menu', 'isEnabled', true) || blockSelection) {
31
+ const selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(({
32
+ node,
33
+ pos
34
+ }) => {
35
+ return Decoration.node(pos, pos + node.nodeSize, {
36
+ class: akEditorSelectedNodeClassName
37
+ });
32
38
  });
33
- });
34
- decorations.push(...selectionDecorations);
39
+ decorations.push(...selectionDecorations);
40
+ }
35
41
  return DecorationSet.create(tr.doc, decorations);
36
42
  }
37
43
  return decorations.length > 0 ? DecorationSet.create(tr.doc, decorations) : DecorationSet.empty;
@@ -45,6 +45,24 @@ const hideCursor = hide => ({
45
45
  hideCursor: hide
46
46
  });
47
47
  };
48
+ const setBlockSelection = selection => ({
49
+ tr
50
+ }) => {
51
+ const currMeta = tr.getMeta(selectionPluginKey);
52
+ return tr.setMeta(selectionPluginKey, {
53
+ ...currMeta,
54
+ setBlockSelection: selection
55
+ });
56
+ };
57
+ const clearBlockSelection = () => ({
58
+ tr
59
+ }) => {
60
+ const currMeta = tr.getMeta(selectionPluginKey);
61
+ return tr.setMeta(selectionPluginKey, {
62
+ ...currMeta,
63
+ clearBlockSelection: true
64
+ });
65
+ };
48
66
  export const selectionPlugin = ({
49
67
  api,
50
68
  config: options
@@ -54,7 +72,9 @@ export const selectionPlugin = ({
54
72
  displayGapCursor,
55
73
  clearManualSelection,
56
74
  hideCursor,
57
- setManualSelection
75
+ setManualSelection,
76
+ setBlockSelection,
77
+ clearBlockSelection
58
78
  },
59
79
  actions: {
60
80
  selectNearNode: ({
@@ -89,7 +89,9 @@ export var getSelectionFragment = function getSelectionFragment(api) {
89
89
  return fragment;
90
90
  };
91
91
  };
92
- export var getSelectionLocalIds = function getSelectionLocalIds(api) {
92
+ export var getSelectionLocalIds =
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ function getSelectionLocalIds(api) {
93
95
  return function () {
94
96
  var _api$selection$shared2, _selection;
95
97
  var selection = api === null || api === void 0 || (_api$selection$shared2 = api.selection.sharedState) === null || _api$selection$shared2 === void 0 || (_api$selection$shared2 = _api$selection$shared2.currentState()) === null || _api$selection$shared2 === void 0 ? void 0 : _api$selection$shared2.selection;
@@ -20,6 +20,7 @@ export var getInitialState = function getInitialState(state) {
20
20
  export var createPlugin = function createPlugin(api, dispatch, dispatchAnalyticsEvent) {
21
21
  var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
22
22
  var cursorHidden = false;
23
+ var blockSelection;
23
24
  return new SafePlugin({
24
25
  key: selectionPluginKey,
25
26
  state: createPluginState(dispatch, getInitialState),
@@ -27,36 +28,46 @@ export var createPlugin = function createPlugin(api, dispatch, dispatchAnalytics
27
28
  var tr = newEditorState.tr;
28
29
  var manualSelection;
29
30
  var hideCursorChanged = false;
31
+ var blockSelectionChanged = false;
30
32
  var needsHideCursor = fg('platform_editor_ai_generic_prep_for_aifc_2');
31
33
  var needsManualSelection = editorExperiment('platform_editor_element_drag_and_drop_multiselect', true);
32
- if (needsHideCursor || needsManualSelection) {
33
- for (var i = transactions.length - 1; i >= 0; i--) {
34
- var meta = transactions[i].getMeta(selectionPluginKey);
35
- if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
36
- var newHideCursorValue = meta.hideCursor;
37
- if (cursorHidden !== newHideCursorValue) {
38
- cursorHidden = newHideCursorValue;
39
- hideCursorChanged = true;
40
- }
34
+ var needsBlockSelection = expValEquals('platform_editor_block_menu', 'isEnabled', true);
35
+ for (var i = transactions.length - 1; i >= 0; i--) {
36
+ var meta = transactions[i].getMeta(selectionPluginKey);
37
+ if (needsHideCursor && (meta === null || meta === void 0 ? void 0 : meta.hideCursor) !== undefined) {
38
+ var newHideCursorValue = meta.hideCursor;
39
+ if (cursorHidden !== newHideCursorValue) {
40
+ cursorHidden = newHideCursorValue;
41
+ hideCursorChanged = true;
41
42
  }
42
- if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
43
- manualSelection = meta.manualSelection;
44
- if (!needsHideCursor) {
45
- break;
46
- }
43
+ }
44
+ if (needsManualSelection && meta !== null && meta !== void 0 && meta.manualSelection && !manualSelection) {
45
+ manualSelection = meta.manualSelection;
46
+ if (!needsHideCursor && !needsBlockSelection) {
47
+ break;
48
+ }
49
+ }
50
+ if (needsBlockSelection) {
51
+ if (meta !== null && meta !== void 0 && meta.setBlockSelection) {
52
+ blockSelection = meta.setBlockSelection;
53
+ blockSelectionChanged = true;
54
+ }
55
+ if (meta !== null && meta !== void 0 && meta.clearBlockSelection) {
56
+ blockSelection = undefined;
57
+ blockSelectionChanged = true;
47
58
  }
48
59
  }
49
60
  }
50
61
  if (!shouldRecalcDecorations({
51
62
  oldEditorState: oldEditorState,
52
63
  newEditorState: newEditorState
53
- }) && !manualSelection && !hideCursorChanged) {
64
+ }) && !manualSelection && !hideCursorChanged && !blockSelectionChanged) {
54
65
  return;
55
66
  }
56
67
  tr.setMeta(selectionPluginKey, {
57
68
  type: SelectionActionTypes.SET_DECORATIONS,
58
69
  selection: tr.selection,
59
- decorationSet: getDecorations(tr, manualSelection, cursorHidden)
70
+ decorationSet: getDecorations(tr, manualSelection, cursorHidden, blockSelection)
60
71
  });
61
72
  return tr;
62
73
  },
@@ -6,9 +6,10 @@ import { findParentNode, findParentNodeClosestToPos, flatten, hasParentNode } fr
6
6
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
10
  import { selectionPluginKey } from '../types';
10
11
  import { createHideCursorDecoration } from './cursor/ui/hide-cursor-decoration';
11
- export var getDecorations = function getDecorations(tr, manualSelection, hideCursor) {
12
+ export var getDecorations = function getDecorations(tr, manualSelection, hideCursor, blockSelection) {
12
13
  var selection = tr.selection;
13
14
  var decorations = [];
14
15
  if (hideCursor && fg('platform_editor_ai_generic_prep_for_aifc_2')) {
@@ -24,14 +25,19 @@ export var getDecorations = function getDecorations(tr, manualSelection, hideCur
24
25
  if (manualSelection && manualSelection.anchor >= 0 && manualSelection.head >= 0 && manualSelection.anchor <= tr.doc.nodeSize && manualSelection.head <= tr.doc.nodeSize) {
25
26
  selection = TextSelection.create(tr.doc, manualSelection.anchor, manualSelection.head);
26
27
  }
27
- var selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(function (_ref) {
28
- var node = _ref.node,
29
- pos = _ref.pos;
30
- return Decoration.node(pos, pos + node.nodeSize, {
31
- class: akEditorSelectedNodeClassName
28
+
29
+ // Only apply node decorations when there is an active block selection.
30
+ // When there is no block selection, text selections should use native browser selection appearance.
31
+ if (!expValEquals('platform_editor_block_menu', 'isEnabled', true) || blockSelection) {
32
+ var selectionDecorations = getNodesToDecorateFromSelection(selection, tr.doc).map(function (_ref) {
33
+ var node = _ref.node,
34
+ pos = _ref.pos;
35
+ return Decoration.node(pos, pos + node.nodeSize, {
36
+ class: akEditorSelectedNodeClassName
37
+ });
32
38
  });
33
- });
34
- decorations.push.apply(decorations, _toConsumableArray(selectionDecorations));
39
+ decorations.push.apply(decorations, _toConsumableArray(selectionDecorations));
40
+ }
35
41
  return DecorationSet.create(tr.doc, decorations);
36
42
  }
37
43
  return decorations.length > 0 ? DecorationSet.create(tr.doc, decorations) : DecorationSet.empty;
@@ -49,21 +49,41 @@ var hideCursor = function hideCursor(hide) {
49
49
  }));
50
50
  };
51
51
  };
52
- export var selectionPlugin = function selectionPlugin(_ref5) {
53
- var api = _ref5.api,
54
- options = _ref5.config;
52
+ var setBlockSelection = function setBlockSelection(selection) {
53
+ return function (_ref5) {
54
+ var tr = _ref5.tr;
55
+ var currMeta = tr.getMeta(selectionPluginKey);
56
+ return tr.setMeta(selectionPluginKey, _objectSpread(_objectSpread({}, currMeta), {}, {
57
+ setBlockSelection: selection
58
+ }));
59
+ };
60
+ };
61
+ var clearBlockSelection = function clearBlockSelection() {
62
+ return function (_ref6) {
63
+ var tr = _ref6.tr;
64
+ var currMeta = tr.getMeta(selectionPluginKey);
65
+ return tr.setMeta(selectionPluginKey, _objectSpread(_objectSpread({}, currMeta), {}, {
66
+ clearBlockSelection: true
67
+ }));
68
+ };
69
+ };
70
+ export var selectionPlugin = function selectionPlugin(_ref7) {
71
+ var api = _ref7.api,
72
+ options = _ref7.config;
55
73
  return {
56
74
  name: 'selection',
57
75
  commands: {
58
76
  displayGapCursor: displayGapCursor,
59
77
  clearManualSelection: clearManualSelection,
60
78
  hideCursor: hideCursor,
61
- setManualSelection: setManualSelection
79
+ setManualSelection: setManualSelection,
80
+ setBlockSelection: setBlockSelection,
81
+ clearBlockSelection: clearBlockSelection
62
82
  },
63
83
  actions: {
64
- selectNearNode: function selectNearNode(_ref6) {
65
- var selectionRelativeToNode = _ref6.selectionRelativeToNode,
66
- selection = _ref6.selection;
84
+ selectNearNode: function selectNearNode(_ref8) {
85
+ var selectionRelativeToNode = _ref8.selectionRelativeToNode,
86
+ selection = _ref8.selection;
67
87
  return function (state) {
68
88
  return _selectNearNode(selectionRelativeToNode, selection)({
69
89
  tr: state.tr
@@ -86,9 +106,9 @@ export var selectionPlugin = function selectionPlugin(_ref5) {
86
106
  pmPlugins: function pmPlugins() {
87
107
  return [{
88
108
  name: 'selection',
89
- plugin: function plugin(_ref7) {
90
- var dispatch = _ref7.dispatch,
91
- dispatchAnalyticsEvent = _ref7.dispatchAnalyticsEvent;
109
+ plugin: function plugin(_ref9) {
110
+ var dispatch = _ref9.dispatch,
111
+ dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent;
92
112
  return createPlugin(api, dispatch, dispatchAnalyticsEvent, options);
93
113
  }
94
114
  }, {
@@ -6,7 +6,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  export declare const getDecorations: (tr: Transaction | ReadonlyTransaction, manualSelection?: {
7
7
  anchor: number;
8
8
  head: number;
9
- }, hideCursor?: boolean) => DecorationSet;
9
+ }, hideCursor?: boolean, blockSelection?: Selection) => DecorationSet;
10
10
  /**
11
11
  * Use `getNodesToDecorateFromSelection` to collect and return
12
12
  * a list of nodes within the Selection that should have Selection
@@ -1,13 +1,16 @@
1
1
  import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
2
2
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
4
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
5
  import type { EditorSelectionAPI, SelectionPluginOptions } from './types';
5
6
  export type SelectionPlugin = NextEditorPlugin<'selection', {
6
7
  actions: EditorSelectionAPI;
7
8
  commands: {
9
+ clearBlockSelection: () => EditorCommand;
8
10
  clearManualSelection: () => EditorCommand;
9
11
  displayGapCursor: (toggle: boolean) => EditorCommand;
10
12
  hideCursor: (hide: boolean) => EditorCommand;
13
+ setBlockSelection: (selection: Selection) => EditorCommand;
11
14
  setManualSelection: (anchor: number, head: number) => EditorCommand;
12
15
  };
13
16
  dependencies: [OptionalPlugin<InteractionPlugin>];
@@ -6,7 +6,7 @@ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
6
  export declare const getDecorations: (tr: Transaction | ReadonlyTransaction, manualSelection?: {
7
7
  anchor: number;
8
8
  head: number;
9
- }, hideCursor?: boolean) => DecorationSet;
9
+ }, hideCursor?: boolean, blockSelection?: Selection) => DecorationSet;
10
10
  /**
11
11
  * Use `getNodesToDecorateFromSelection` to collect and return
12
12
  * a list of nodes within the Selection that should have Selection
@@ -1,13 +1,16 @@
1
1
  import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
2
2
  import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
4
+ import type { Selection } from '@atlaskit/editor-prosemirror/state';
4
5
  import type { EditorSelectionAPI, SelectionPluginOptions } from './types';
5
6
  export type SelectionPlugin = NextEditorPlugin<'selection', {
6
7
  actions: EditorSelectionAPI;
7
8
  commands: {
9
+ clearBlockSelection: () => EditorCommand;
8
10
  clearManualSelection: () => EditorCommand;
9
11
  displayGapCursor: (toggle: boolean) => EditorCommand;
10
12
  hideCursor: (hide: boolean) => EditorCommand;
13
+ setBlockSelection: (selection: Selection) => EditorCommand;
11
14
  setManualSelection: (anchor: number, head: number) => EditorCommand;
12
15
  };
13
16
  dependencies: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,17 +20,17 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@atlaskit/editor-json-transformer": "^8.31.0",
23
- "@atlaskit/editor-plugin-interaction": "^12.0.0",
23
+ "@atlaskit/editor-plugin-interaction": "^13.0.0",
24
24
  "@atlaskit/editor-prosemirror": "^7.2.0",
25
25
  "@atlaskit/editor-shared-styles": "^3.10.0",
26
26
  "@atlaskit/editor-tables": "^2.9.0",
27
27
  "@atlaskit/platform-feature-flags": "^1.1.0",
28
- "@atlaskit/tmp-editor-statsig": "^16.3.0",
29
- "@atlaskit/tokens": "^9.0.0",
28
+ "@atlaskit/tmp-editor-statsig": "^16.23.0",
29
+ "@atlaskit/tokens": "^10.0.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
32
32
  "peerDependencies": {
33
- "@atlaskit/editor-common": "^111.0.0",
33
+ "@atlaskit/editor-common": "^111.8.0",
34
34
  "react": "^18.2.0"
35
35
  },
36
36
  "techstack": {