@atlaskit/editor-plugin-selection 2.1.8 → 2.2.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,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#147781](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/147781)
8
+ [`154676654d6ce`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/154676654d6ce) -
9
+ [ED-27777] Remove selection decorator until interaction for live pages
10
+
11
+ ## 2.1.9
12
+
13
+ ### Patch Changes
14
+
15
+ - [#142352](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/142352)
16
+ [`05903fde6d94d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/05903fde6d94d) -
17
+ Internal change to use Compiled variant of `@atlaskit/primitives`.
18
+ - Updated dependencies
19
+
3
20
  ## 2.1.8
4
21
 
5
22
  ### Patch Changes
@@ -23,8 +23,10 @@ var shouldSkipGapCursor = exports.shouldSkipGapCursor = function shouldSkipGapCu
23
23
  }
24
24
  return (0, _utils.isPositionNearTableRow)($pos, schema, 'before') || (0, _utils3.isTextBlockNearPos)(doc, schema, $pos, -1) || (0, _utils.isNodeBeforeMediaNode)($pos, state);
25
25
  case _direction.Direction.DOWN:
26
- return (0, _selection.atTheEndOfDoc)(state) || (0, _utils3.isTextBlockNearPos)(doc, schema, $pos, 1) || (0, _utils.isPositionNearTableRow)($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter // end of a paragraph
27
- ;
26
+ return (
27
+ // end of a paragraph
28
+ (0, _selection.atTheEndOfDoc)(state) || (0, _utils3.isTextBlockNearPos)(doc, schema, $pos, 1) || (0, _utils.isPositionNearTableRow)($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter
29
+ );
28
30
  default:
29
31
  return false;
30
32
  }
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getInitialState = exports.createPlugin = void 0;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _view = require("@atlaskit/editor-prosemirror/view");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
11
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
12
  var _types = require("../types");
11
13
  var _actions = require("./actions");
@@ -20,8 +22,8 @@ var getInitialState = exports.getInitialState = function getInitialState(state)
20
22
  selection: state.selection
21
23
  };
22
24
  };
23
- var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent) {
24
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25
+ var createPlugin = exports.createPlugin = function createPlugin(api, dispatch, dispatchAnalyticsEvent) {
26
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
25
27
  return new _safePlugin.SafePlugin({
26
28
  key: _types.selectionPluginKey,
27
29
  state: (0, _pluginFactory.createPluginState)(dispatch, getInitialState),
@@ -68,6 +70,17 @@ var createPlugin = exports.createPlugin = function createPlugin(dispatch, dispat
68
70
  props: {
69
71
  createSelectionBetween: _createSelectionBetween.onCreateSelectionBetween,
70
72
  decorations: function decorations(state) {
73
+ var _api$interaction;
74
+ // TODO: ED-27865 - This has to be explicitly checked against false to ensure that
75
+ // we don't change behaviour when hasHadInteraction is undefined.
76
+ var hasHadInteraction = (api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.hasHadInteraction) !== false;
77
+
78
+ // Do not show selection decorations for live pages where the user has not
79
+ // interacted with the page. We do not show cursor until interaction and we do not
80
+ // want to show selections either.
81
+ if (options.__livePage && !hasHadInteraction && (0, _platformFeatureFlags.fg)('platform_editor_no_selection_decorations')) {
82
+ return _view.DecorationSet.empty;
83
+ }
71
84
  return (0, _pluginFactory.getPluginState)(state).decorationSet;
72
85
  },
73
86
  handleDOMEvents: {
@@ -47,7 +47,8 @@ var setManualSelection = function setManualSelection(anchor, head) {
47
47
  };
48
48
  };
49
49
  var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref4) {
50
- var options = _ref4.config;
50
+ var api = _ref4.api,
51
+ options = _ref4.config;
51
52
  return {
52
53
  name: 'selection',
53
54
  commands: {
@@ -82,7 +83,7 @@ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref4)
82
83
  plugin: function plugin(_ref6) {
83
84
  var dispatch = _ref6.dispatch,
84
85
  dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
85
- return (0, _selectionMain.createPlugin)(dispatch, dispatchAnalyticsEvent, options);
86
+ return (0, _selectionMain.createPlugin)(api, dispatch, dispatchAnalyticsEvent, options);
86
87
  }
87
88
  }, {
88
89
  name: 'selectionKeymap',
@@ -19,8 +19,10 @@ export const shouldSkipGapCursor = (direction, state, $pos) => {
19
19
  }
20
20
  return isPositionNearTableRow($pos, schema, 'before') || isTextBlockNearPos(doc, schema, $pos, -1) || isNodeBeforeMediaNode($pos, state);
21
21
  case Direction.DOWN:
22
- return atTheEndOfDoc(state) || isTextBlockNearPos(doc, schema, $pos, 1) || isPositionNearTableRow($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter // end of a paragraph
23
- ;
22
+ return (
23
+ // end of a paragraph
24
+ atTheEndOfDoc(state) || isTextBlockNearPos(doc, schema, $pos, 1) || isPositionNearTableRow($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter
25
+ );
24
26
  default:
25
27
  return false;
26
28
  }
@@ -1,5 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
3
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
6
  import { selectionPluginKey } from '../types';
5
7
  import { SelectionActionTypes } from './actions';
@@ -12,7 +14,7 @@ export const getInitialState = state => ({
12
14
  decorationSet: getDecorations(state.tr),
13
15
  selection: state.selection
14
16
  });
15
- export const createPlugin = (dispatch, dispatchAnalyticsEvent, options = {}) => {
17
+ export const createPlugin = (api, dispatch, dispatchAnalyticsEvent, options = {}) => {
16
18
  return new SafePlugin({
17
19
  key: selectionPluginKey,
18
20
  state: createPluginState(dispatch, getInitialState),
@@ -61,6 +63,17 @@ export const createPlugin = (dispatch, dispatchAnalyticsEvent, options = {}) =>
61
63
  props: {
62
64
  createSelectionBetween: onCreateSelectionBetween,
63
65
  decorations(state) {
66
+ var _api$interaction, _api$interaction$shar;
67
+ // TODO: ED-27865 - This has to be explicitly checked against false to ensure that
68
+ // we don't change behaviour when hasHadInteraction is undefined.
69
+ const hasHadInteraction = (api === null || api === void 0 ? void 0 : (_api$interaction = api.interaction) === null || _api$interaction === void 0 ? void 0 : (_api$interaction$shar = _api$interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.hasHadInteraction) !== false;
70
+
71
+ // Do not show selection decorations for live pages where the user has not
72
+ // interacted with the page. We do not show cursor until interaction and we do not
73
+ // want to show selections either.
74
+ if (options.__livePage && !hasHadInteraction && fg('platform_editor_no_selection_decorations')) {
75
+ return DecorationSet.empty;
76
+ }
64
77
  return getPluginState(state).decorationSet;
65
78
  },
66
79
  handleDOMEvents: {
@@ -36,6 +36,7 @@ const setManualSelection = (anchor, head) => ({
36
36
  });
37
37
  };
38
38
  export const selectionPlugin = ({
39
+ api,
39
40
  config: options
40
41
  }) => ({
41
42
  name: 'selection',
@@ -70,7 +71,7 @@ export const selectionPlugin = ({
70
71
  plugin: ({
71
72
  dispatch,
72
73
  dispatchAnalyticsEvent
73
- }) => createPlugin(dispatch, dispatchAnalyticsEvent, options)
74
+ }) => createPlugin(api, dispatch, dispatchAnalyticsEvent, options)
74
75
  }, {
75
76
  name: 'selectionKeymap',
76
77
  plugin: selectionKeymapPlugin
@@ -17,8 +17,10 @@ export var shouldSkipGapCursor = function shouldSkipGapCursor(direction, state,
17
17
  }
18
18
  return isPositionNearTableRow($pos, schema, 'before') || isTextBlockNearPos(doc, schema, $pos, -1) || isNodeBeforeMediaNode($pos, state);
19
19
  case Direction.DOWN:
20
- return atTheEndOfDoc(state) || isTextBlockNearPos(doc, schema, $pos, 1) || isPositionNearTableRow($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter // end of a paragraph
21
- ;
20
+ return (
21
+ // end of a paragraph
22
+ atTheEndOfDoc(state) || isTextBlockNearPos(doc, schema, $pos, 1) || isPositionNearTableRow($pos, schema, 'after') || ((_$pos$nodeBefore = $pos.nodeBefore) === null || _$pos$nodeBefore === void 0 ? void 0 : _$pos$nodeBefore.type.name) === 'text' && !$pos.nodeAfter
23
+ );
22
24
  default:
23
25
  return false;
24
26
  }
@@ -1,5 +1,7 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
3
5
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
6
  import { selectionPluginKey } from '../types';
5
7
  import { SelectionActionTypes } from './actions';
@@ -14,8 +16,8 @@ export var getInitialState = function getInitialState(state) {
14
16
  selection: state.selection
15
17
  };
16
18
  };
17
- export var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent) {
18
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
19
+ export var createPlugin = function createPlugin(api, dispatch, dispatchAnalyticsEvent) {
20
+ var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
19
21
  return new SafePlugin({
20
22
  key: selectionPluginKey,
21
23
  state: createPluginState(dispatch, getInitialState),
@@ -62,6 +64,17 @@ export var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent
62
64
  props: {
63
65
  createSelectionBetween: onCreateSelectionBetween,
64
66
  decorations: function decorations(state) {
67
+ var _api$interaction;
68
+ // TODO: ED-27865 - This has to be explicitly checked against false to ensure that
69
+ // we don't change behaviour when hasHadInteraction is undefined.
70
+ var hasHadInteraction = (api === null || api === void 0 || (_api$interaction = api.interaction) === null || _api$interaction === void 0 || (_api$interaction = _api$interaction.sharedState.currentState()) === null || _api$interaction === void 0 ? void 0 : _api$interaction.hasHadInteraction) !== false;
71
+
72
+ // Do not show selection decorations for live pages where the user has not
73
+ // interacted with the page. We do not show cursor until interaction and we do not
74
+ // want to show selections either.
75
+ if (options.__livePage && !hasHadInteraction && fg('platform_editor_no_selection_decorations')) {
76
+ return DecorationSet.empty;
77
+ }
65
78
  return getPluginState(state).decorationSet;
66
79
  },
67
80
  handleDOMEvents: {
@@ -40,7 +40,8 @@ var setManualSelection = function setManualSelection(anchor, head) {
40
40
  };
41
41
  };
42
42
  export var selectionPlugin = function selectionPlugin(_ref4) {
43
- var options = _ref4.config;
43
+ var api = _ref4.api,
44
+ options = _ref4.config;
44
45
  return {
45
46
  name: 'selection',
46
47
  commands: {
@@ -75,7 +76,7 @@ export var selectionPlugin = function selectionPlugin(_ref4) {
75
76
  plugin: function plugin(_ref6) {
76
77
  var dispatch = _ref6.dispatch,
77
78
  dispatchAnalyticsEvent = _ref6.dispatchAnalyticsEvent;
78
- return createPlugin(dispatch, dispatchAnalyticsEvent, options);
79
+ return createPlugin(api, dispatch, dispatchAnalyticsEvent, options);
79
80
  }
80
81
  }, {
81
82
  name: 'selectionKeymap',
@@ -2,7 +2,9 @@ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
2
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import type { SelectionPluginState } from '@atlaskit/editor-common/selection';
5
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
6
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
7
+ import { SelectionPlugin } from '../selectionPluginType';
6
8
  import type { SelectionPluginOptions } from '../types';
7
9
  export declare const getInitialState: (state: EditorState) => SelectionPluginState;
8
- export declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, options?: SelectionPluginOptions) => SafePlugin<SelectionPluginState>;
10
+ export declare const createPlugin: (api: ExtractInjectionAPI<SelectionPlugin> | undefined, dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, options?: SelectionPluginOptions) => SafePlugin<SelectionPluginState>;
@@ -1,9 +1,11 @@
1
1
  import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
2
- import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
3
4
  import type { EditorSelectionAPI, SelectionPluginOptions } from './types';
4
5
  export type SelectionPlugin = NextEditorPlugin<'selection', {
5
6
  pluginConfiguration: SelectionPluginOptions | undefined;
6
7
  actions: EditorSelectionAPI;
8
+ dependencies: [OptionalPlugin<InteractionPlugin>];
7
9
  commands: {
8
10
  displayGapCursor: (toggle: boolean) => EditorCommand;
9
11
  clearManualSelection: () => EditorCommand;
@@ -2,7 +2,9 @@ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
2
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import type { SelectionPluginState } from '@atlaskit/editor-common/selection';
5
+ import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
5
6
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
7
+ import { SelectionPlugin } from '../selectionPluginType';
6
8
  import type { SelectionPluginOptions } from '../types';
7
9
  export declare const getInitialState: (state: EditorState) => SelectionPluginState;
8
- export declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, options?: SelectionPluginOptions) => SafePlugin<SelectionPluginState>;
10
+ export declare const createPlugin: (api: ExtractInjectionAPI<SelectionPlugin> | undefined, dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, options?: SelectionPluginOptions) => SafePlugin<SelectionPluginState>;
@@ -1,9 +1,13 @@
1
1
  import type { SelectionSharedState } from '@atlaskit/editor-common/selection';
2
- import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
2
+ import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
+ import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
3
4
  import type { EditorSelectionAPI, SelectionPluginOptions } from './types';
4
5
  export type SelectionPlugin = NextEditorPlugin<'selection', {
5
6
  pluginConfiguration: SelectionPluginOptions | undefined;
6
7
  actions: EditorSelectionAPI;
8
+ dependencies: [
9
+ OptionalPlugin<InteractionPlugin>
10
+ ];
7
11
  commands: {
8
12
  displayGapCursor: (toggle: boolean) => EditorCommand;
9
13
  clearManualSelection: () => EditorCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "2.1.8",
3
+ "version": "2.2.0",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,13 +20,14 @@
20
20
  "runReact18": true
21
21
  },
22
22
  "dependencies": {
23
- "@atlaskit/editor-common": "^103.4.0",
23
+ "@atlaskit/editor-common": "^103.22.0",
24
+ "@atlaskit/editor-plugin-interaction": "^1.0.0",
24
25
  "@atlaskit/editor-prosemirror": "7.0.0",
25
26
  "@atlaskit/editor-shared-styles": "^3.4.0",
26
27
  "@atlaskit/editor-tables": "^2.9.0",
27
28
  "@atlaskit/platform-feature-flags": "^1.1.0",
28
- "@atlaskit/tmp-editor-statsig": "^4.6.0",
29
- "@atlaskit/tokens": "^4.7.0",
29
+ "@atlaskit/tmp-editor-statsig": "^4.15.0",
30
+ "@atlaskit/tokens": "^4.8.0",
30
31
  "@babel/runtime": "^7.0.0"
31
32
  },
32
33
  "peerDependencies": {
@@ -92,6 +93,9 @@
92
93
  },
93
94
  "platform_editor_nested_tables_gap_cursor": {
94
95
  "type": "boolean"
96
+ },
97
+ "platform_editor_no_selection_decorations": {
98
+ "type": "boolean"
95
99
  }
96
100
  }
97
101
  }