@atlaskit/editor-plugin-selection 2.1.9 → 2.2.1

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,21 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 2.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#149285](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/149285)
8
+ [`d00629c3a33cf`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d00629c3a33cf) -
9
+ Clean up feature gate platform_editor_lcm_inline_node_selection_fix
10
+
11
+ ## 2.2.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#147781](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/147781)
16
+ [`154676654d6ce`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/154676654d6ce) -
17
+ [ED-27777] Remove selection decorator until interaction for live pages
18
+
3
19
  ## 2.1.9
4
20
 
5
21
  ### Patch Changes
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createAutoExpandSelectionRangeOnInlineNodePlugin = void 0;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _state = require("@atlaskit/editor-prosemirror/state");
9
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
9
  var _autoExpandSelectionRangeOnInlineNodeKey = require("./auto-expand-selection-range-on-inline-node-key");
11
10
  var createAutoExpandSelectionRangeOnInlineNodePlugin = exports.createAutoExpandSelectionRangeOnInlineNodePlugin = function createAutoExpandSelectionRangeOnInlineNodePlugin() {
12
11
  var mouseDownElement = null;
@@ -23,22 +22,16 @@ var createAutoExpandSelectionRangeOnInlineNodePlugin = exports.createAutoExpandS
23
22
  // Ignored via go/ees005
24
23
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
25
24
  var mouseUpElement = event.target;
26
- if ((0, _platformFeatureFlags.fg)('platform_editor_lcm_inline_node_selection_fix')) {
27
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
28
- // or mouse down doesn't trigger
29
- if (!mouseDownElement || mouseDownElement === mouseUpElement) {
30
- mouseDownElement = null;
31
- return;
32
- }
33
- // reset mouse down element after mouse up event
34
- // so that we can detect the next mouse down event is triggered right after mouse up event or not
25
+
26
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
27
+ // or mouse down doesn't trigger
28
+ if (!mouseDownElement || mouseDownElement === mouseUpElement) {
35
29
  mouseDownElement = null;
36
- } else {
37
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
38
- if (mouseDownElement === mouseUpElement) {
39
- return;
40
- }
30
+ return;
41
31
  }
32
+ // reset mouse down element after mouse up event
33
+ // so that we can detect the next mouse down event is triggered right after mouse up event or not
34
+ mouseDownElement = null;
42
35
 
43
36
  // terminate early if mouse up event is not fired on inline node
44
37
  if (!isMouseUpOnSupportedNode(mouseUpElement)) {
@@ -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',
@@ -1,6 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { fg } from '@atlaskit/platform-feature-flags';
4
3
  import { autoExpandSelectionRangeOnInlineNodePluginKey } from './auto-expand-selection-range-on-inline-node-key';
5
4
  export const createAutoExpandSelectionRangeOnInlineNodePlugin = () => {
6
5
  let mouseDownElement = null;
@@ -17,22 +16,16 @@ export const createAutoExpandSelectionRangeOnInlineNodePlugin = () => {
17
16
  // Ignored via go/ees005
18
17
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
19
18
  const mouseUpElement = event.target;
20
- if (fg('platform_editor_lcm_inline_node_selection_fix')) {
21
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
22
- // or mouse down doesn't trigger
23
- if (!mouseDownElement || mouseDownElement === mouseUpElement) {
24
- mouseDownElement = null;
25
- return;
26
- }
27
- // reset mouse down element after mouse up event
28
- // so that we can detect the next mouse down event is triggered right after mouse up event or not
19
+
20
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
21
+ // or mouse down doesn't trigger
22
+ if (!mouseDownElement || mouseDownElement === mouseUpElement) {
29
23
  mouseDownElement = null;
30
- } else {
31
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
32
- if (mouseDownElement === mouseUpElement) {
33
- return;
34
- }
24
+ return;
35
25
  }
26
+ // reset mouse down element after mouse up event
27
+ // so that we can detect the next mouse down event is triggered right after mouse up event or not
28
+ mouseDownElement = null;
36
29
 
37
30
  // terminate early if mouse up event is not fired on inline node
38
31
  if (!isMouseUpOnSupportedNode(mouseUpElement)) {
@@ -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
@@ -1,6 +1,5 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { fg } from '@atlaskit/platform-feature-flags';
4
3
  import { autoExpandSelectionRangeOnInlineNodePluginKey } from './auto-expand-selection-range-on-inline-node-key';
5
4
  export var createAutoExpandSelectionRangeOnInlineNodePlugin = function createAutoExpandSelectionRangeOnInlineNodePlugin() {
6
5
  var mouseDownElement = null;
@@ -17,22 +16,16 @@ export var createAutoExpandSelectionRangeOnInlineNodePlugin = function createAut
17
16
  // Ignored via go/ees005
18
17
  // eslint-disable-next-line @atlaskit/editor/no-as-casting
19
18
  var mouseUpElement = event.target;
20
- if (fg('platform_editor_lcm_inline_node_selection_fix')) {
21
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
22
- // or mouse down doesn't trigger
23
- if (!mouseDownElement || mouseDownElement === mouseUpElement) {
24
- mouseDownElement = null;
25
- return;
26
- }
27
- // reset mouse down element after mouse up event
28
- // so that we can detect the next mouse down event is triggered right after mouse up event or not
19
+
20
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
21
+ // or mouse down doesn't trigger
22
+ if (!mouseDownElement || mouseDownElement === mouseUpElement) {
29
23
  mouseDownElement = null;
30
- } else {
31
- // terminate early if mouse down and mouse up elements are the same -> e.g a click event
32
- if (mouseDownElement === mouseUpElement) {
33
- return;
34
- }
24
+ return;
35
25
  }
26
+ // reset mouse down element after mouse up event
27
+ // so that we can detect the next mouse down event is triggered right after mouse up event or not
28
+ mouseDownElement = null;
36
29
 
37
30
  // terminate early if mouse up event is not fired on inline node
38
31
  if (!isMouseUpOnSupportedNode(mouseUpElement)) {
@@ -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.9",
3
+ "version": "2.2.1",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,12 +20,13 @@
20
20
  "runReact18": true
21
21
  },
22
22
  "dependencies": {
23
- "@atlaskit/editor-common": "^103.12.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.12.0",
29
+ "@atlaskit/tmp-editor-statsig": "^4.15.0",
29
30
  "@atlaskit/tokens": "^4.8.0",
30
31
  "@babel/runtime": "^7.0.0"
31
32
  },
@@ -87,10 +88,10 @@
87
88
  "platform_editor_fix_drag_and_drop_lists": {
88
89
  "type": "boolean"
89
90
  },
90
- "platform_editor_lcm_inline_node_selection_fix": {
91
+ "platform_editor_nested_tables_gap_cursor": {
91
92
  "type": "boolean"
92
93
  },
93
- "platform_editor_nested_tables_gap_cursor": {
94
+ "platform_editor_no_selection_decorations": {
94
95
  "type": "boolean"
95
96
  }
96
97
  }