@atlaskit/editor-plugin-selection 1.5.6 → 1.6.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,27 @@
1
1
  # @atlaskit/editor-plugin-selection
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 1.6.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#169428](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/169428)
14
+ [`dc52eec1d2269`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/dc52eec1d2269) -
15
+ [ux] ED-25865 Auto include inline node as a part of selection when selection ends on an inline
16
+ node
17
+ - [#169428](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/169428)
18
+ [`ded743b539788`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ded743b539788) -
19
+ [ux] ED-25865 auto expand selection to include inline node
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies
24
+
3
25
  ## 1.5.6
4
26
 
5
27
  ### Patch Changes
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.autoExpandSelectionRangeOnInlineNodePluginKey = void 0;
7
+ var _state = require("@atlaskit/editor-prosemirror/state");
8
+ var autoExpandSelectionRangeOnInlineNodePluginKey = exports.autoExpandSelectionRangeOnInlineNodePluginKey = new _state.PluginKey('autoExpandSelectionRangeOnInlineNodePlugin');
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAutoExpandSelectionRangeOnInlineNodePlugin = void 0;
7
+ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
10
+ var _autoExpandSelectionRangeOnInlineNodeKey = require("./auto-expand-selection-range-on-inline-node-key");
11
+ var createAutoExpandSelectionRangeOnInlineNodePlugin = exports.createAutoExpandSelectionRangeOnInlineNodePlugin = function createAutoExpandSelectionRangeOnInlineNodePlugin() {
12
+ var mouseDownElement = null;
13
+ return new _safePlugin.SafePlugin({
14
+ key: _autoExpandSelectionRangeOnInlineNodeKey.autoExpandSelectionRangeOnInlineNodePluginKey,
15
+ props: {
16
+ handleDOMEvents: {
17
+ mousedown: function mousedown(_view, event) {
18
+ mouseDownElement = event.target;
19
+ },
20
+ mouseup: function mouseup(view, event) {
21
+ var mouseUpElement = event.target;
22
+
23
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
24
+ if (mouseDownElement === mouseUpElement) {
25
+ return;
26
+ }
27
+
28
+ // terminate early if mouse up event is not fired on inline node
29
+ if (!isMouseUpOnSupportedNode(mouseUpElement)) {
30
+ return;
31
+ }
32
+ var dispatch = view.dispatch,
33
+ state = view.state;
34
+ var selection = state.selection;
35
+
36
+ // terminate early if current selection is on a node
37
+ if (selection instanceof _state.NodeSelection) {
38
+ return;
39
+ }
40
+
41
+ // only expand range when experiment is enabled, also fire exposure events here
42
+ if ((0, _experiments.editorExperiment)('expand_selection_range_to_include_inline_node', true, {
43
+ exposure: true
44
+ })) {
45
+ // find the document position of the mouse up element
46
+ var elementStartPosition = view.posAtDOM(mouseUpElement, 0);
47
+
48
+ // find out the direction of selection
49
+ var isAnchorBeforeElement = selection.$anchor.pos <= elementStartPosition;
50
+ var expandedSelectionHeadPosition = isAnchorBeforeElement ? elementStartPosition + 1 : elementStartPosition;
51
+
52
+ // expand the selection to include the mouse up element
53
+ var tr = state.tr.setSelection(_state.TextSelection.create(state.doc, selection.$anchor.pos, expandedSelectionHeadPosition));
54
+ dispatch(tr);
55
+ }
56
+ }
57
+ }
58
+ }
59
+ });
60
+ };
61
+ var isMouseUpOnSupportedNode = function isMouseUpOnSupportedNode(mouseUpElement) {
62
+ var supportedNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
63
+ var supportedNodeViewContentClassNamesList = supportedNodes.map(function (nodeType) {
64
+ return ".".concat(nodeType, "View-content-wrap");
65
+ }).join(', ');
66
+ return !!mouseUpElement.closest(supportedNodeViewContentClassNamesList);
67
+ };
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.selectionPlugin = exports.default = void 0;
8
8
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
9
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
+ var _autoExpandSelectionRangeOnInlineNodeMain = require("./pm-plugins/auto-expand-selection-range-on-inline-node-main");
10
11
  var _commands = require("./pm-plugins/commands");
11
12
  var _gapCursorKeymap = _interopRequireDefault(require("./pm-plugins/gap-cursor-keymap"));
12
13
  var _gapCursorMain = _interopRequireDefault(require("./pm-plugins/gap-cursor-main"));
@@ -77,6 +78,11 @@ var selectionPlugin = exports.selectionPlugin = function selectionPlugin(_ref2)
77
78
  plugin: function plugin() {
78
79
  return (0, _markBoundaryCursorMain.createMarkBoundaryCursorPlugin)();
79
80
  }
81
+ }] : []), (0, _toConsumableArray2.default)((0, _platformFeatureFlags.fg)('editor_auto_expand_selection_on_inline_node') ? [{
82
+ name: 'autoExpandSelectionRangeOnInlineNode',
83
+ plugin: function plugin() {
84
+ return (0, _autoExpandSelectionRangeOnInlineNodeMain.createAutoExpandSelectionRangeOnInlineNodePlugin)();
85
+ }
80
86
  }] : []));
81
87
  }
82
88
  };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export const autoExpandSelectionRangeOnInlineNodePluginKey = new PluginKey('autoExpandSelectionRangeOnInlineNodePlugin');
@@ -0,0 +1,63 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
+ import { autoExpandSelectionRangeOnInlineNodePluginKey } from './auto-expand-selection-range-on-inline-node-key';
5
+ export const createAutoExpandSelectionRangeOnInlineNodePlugin = () => {
6
+ let mouseDownElement = null;
7
+ return new SafePlugin({
8
+ key: autoExpandSelectionRangeOnInlineNodePluginKey,
9
+ props: {
10
+ handleDOMEvents: {
11
+ mousedown: (_view, event) => {
12
+ mouseDownElement = event.target;
13
+ },
14
+ mouseup: (view, event) => {
15
+ const mouseUpElement = event.target;
16
+
17
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
18
+ if (mouseDownElement === mouseUpElement) {
19
+ return;
20
+ }
21
+
22
+ // terminate early if mouse up event is not fired on inline node
23
+ if (!isMouseUpOnSupportedNode(mouseUpElement)) {
24
+ return;
25
+ }
26
+ const {
27
+ dispatch,
28
+ state
29
+ } = view;
30
+ const {
31
+ selection
32
+ } = state;
33
+
34
+ // terminate early if current selection is on a node
35
+ if (selection instanceof NodeSelection) {
36
+ return;
37
+ }
38
+
39
+ // only expand range when experiment is enabled, also fire exposure events here
40
+ if (editorExperiment('expand_selection_range_to_include_inline_node', true, {
41
+ exposure: true
42
+ })) {
43
+ // find the document position of the mouse up element
44
+ const elementStartPosition = view.posAtDOM(mouseUpElement, 0);
45
+
46
+ // find out the direction of selection
47
+ const isAnchorBeforeElement = selection.$anchor.pos <= elementStartPosition;
48
+ const expandedSelectionHeadPosition = isAnchorBeforeElement ? elementStartPosition + 1 : elementStartPosition;
49
+
50
+ // expand the selection to include the mouse up element
51
+ const tr = state.tr.setSelection(TextSelection.create(state.doc, selection.$anchor.pos, expandedSelectionHeadPosition));
52
+ dispatch(tr);
53
+ }
54
+ }
55
+ }
56
+ }
57
+ });
58
+ };
59
+ const isMouseUpOnSupportedNode = mouseUpElement => {
60
+ const supportedNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
61
+ const supportedNodeViewContentClassNamesList = supportedNodes.map(nodeType => `.${nodeType}View-content-wrap`).join(', ');
62
+ return !!mouseUpElement.closest(supportedNodeViewContentClassNamesList);
63
+ };
@@ -1,4 +1,5 @@
1
1
  import { fg } from '@atlaskit/platform-feature-flags';
2
+ import { createAutoExpandSelectionRangeOnInlineNodePlugin } from './pm-plugins/auto-expand-selection-range-on-inline-node-main';
2
3
  import { selectNearNode } from './pm-plugins/commands';
3
4
  import gapCursorKeymapPlugin from './pm-plugins/gap-cursor-keymap';
4
5
  import gapCursorPlugin from './pm-plugins/gap-cursor-main';
@@ -60,6 +61,9 @@ export const selectionPlugin = ({
60
61
  }, ...(fg('platform_editor_mark_boundary_cursor') ? [{
61
62
  name: 'markBoundaryCursor',
62
63
  plugin: () => createMarkBoundaryCursorPlugin()
64
+ }] : []), ...(fg('editor_auto_expand_selection_on_inline_node') ? [{
65
+ name: 'autoExpandSelectionRangeOnInlineNode',
66
+ plugin: () => createAutoExpandSelectionRangeOnInlineNodePlugin()
63
67
  }] : [])];
64
68
  }
65
69
  });
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export var autoExpandSelectionRangeOnInlineNodePluginKey = new PluginKey('autoExpandSelectionRangeOnInlineNodePlugin');
@@ -0,0 +1,61 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
+ import { autoExpandSelectionRangeOnInlineNodePluginKey } from './auto-expand-selection-range-on-inline-node-key';
5
+ export var createAutoExpandSelectionRangeOnInlineNodePlugin = function createAutoExpandSelectionRangeOnInlineNodePlugin() {
6
+ var mouseDownElement = null;
7
+ return new SafePlugin({
8
+ key: autoExpandSelectionRangeOnInlineNodePluginKey,
9
+ props: {
10
+ handleDOMEvents: {
11
+ mousedown: function mousedown(_view, event) {
12
+ mouseDownElement = event.target;
13
+ },
14
+ mouseup: function mouseup(view, event) {
15
+ var mouseUpElement = event.target;
16
+
17
+ // terminate early if mouse down and mouse up elements are the same -> e.g a click event
18
+ if (mouseDownElement === mouseUpElement) {
19
+ return;
20
+ }
21
+
22
+ // terminate early if mouse up event is not fired on inline node
23
+ if (!isMouseUpOnSupportedNode(mouseUpElement)) {
24
+ return;
25
+ }
26
+ var dispatch = view.dispatch,
27
+ state = view.state;
28
+ var selection = state.selection;
29
+
30
+ // terminate early if current selection is on a node
31
+ if (selection instanceof NodeSelection) {
32
+ return;
33
+ }
34
+
35
+ // only expand range when experiment is enabled, also fire exposure events here
36
+ if (editorExperiment('expand_selection_range_to_include_inline_node', true, {
37
+ exposure: true
38
+ })) {
39
+ // find the document position of the mouse up element
40
+ var elementStartPosition = view.posAtDOM(mouseUpElement, 0);
41
+
42
+ // find out the direction of selection
43
+ var isAnchorBeforeElement = selection.$anchor.pos <= elementStartPosition;
44
+ var expandedSelectionHeadPosition = isAnchorBeforeElement ? elementStartPosition + 1 : elementStartPosition;
45
+
46
+ // expand the selection to include the mouse up element
47
+ var tr = state.tr.setSelection(TextSelection.create(state.doc, selection.$anchor.pos, expandedSelectionHeadPosition));
48
+ dispatch(tr);
49
+ }
50
+ }
51
+ }
52
+ }
53
+ });
54
+ };
55
+ var isMouseUpOnSupportedNode = function isMouseUpOnSupportedNode(mouseUpElement) {
56
+ var supportedNodes = ['emoji', 'status', 'date', 'mention', 'inlineCard'];
57
+ var supportedNodeViewContentClassNamesList = supportedNodes.map(function (nodeType) {
58
+ return ".".concat(nodeType, "View-content-wrap");
59
+ }).join(', ');
60
+ return !!mouseUpElement.closest(supportedNodeViewContentClassNamesList);
61
+ };
@@ -1,5 +1,6 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
2
  import { fg } from '@atlaskit/platform-feature-flags';
3
+ import { createAutoExpandSelectionRangeOnInlineNodePlugin } from './pm-plugins/auto-expand-selection-range-on-inline-node-main';
3
4
  import { selectNearNode as _selectNearNode } from './pm-plugins/commands';
4
5
  import gapCursorKeymapPlugin from './pm-plugins/gap-cursor-keymap';
5
6
  import gapCursorPlugin from './pm-plugins/gap-cursor-main';
@@ -70,6 +71,11 @@ export var selectionPlugin = function selectionPlugin(_ref2) {
70
71
  plugin: function plugin() {
71
72
  return createMarkBoundaryCursorPlugin();
72
73
  }
74
+ }] : []), _toConsumableArray(fg('editor_auto_expand_selection_on_inline_node') ? [{
75
+ name: 'autoExpandSelectionRangeOnInlineNode',
76
+ plugin: function plugin() {
77
+ return createAutoExpandSelectionRangeOnInlineNodePlugin();
78
+ }
73
79
  }] : []));
74
80
  }
75
81
  };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const autoExpandSelectionRangeOnInlineNodePluginKey: PluginKey<any>;
@@ -0,0 +1,2 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ export declare const createAutoExpandSelectionRangeOnInlineNodePlugin: () => SafePlugin<any>;
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const autoExpandSelectionRangeOnInlineNodePluginKey: PluginKey<any>;
@@ -0,0 +1,2 @@
1
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
+ export declare const createAutoExpandSelectionRangeOnInlineNodePlugin: () => SafePlugin<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-selection",
3
- "version": "1.5.6",
3
+ "version": "1.6.1",
4
4
  "description": "Selection plugin for @atlaskit/editor-core",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,12 +20,12 @@
20
20
  "runReact18": true
21
21
  },
22
22
  "dependencies": {
23
- "@atlaskit/editor-common": "^96.3.0",
23
+ "@atlaskit/editor-common": "^96.4.0",
24
24
  "@atlaskit/editor-prosemirror": "6.2.1",
25
25
  "@atlaskit/editor-shared-styles": "^3.2.0",
26
26
  "@atlaskit/editor-tables": "^2.8.0",
27
27
  "@atlaskit/platform-feature-flags": "^0.3.0",
28
- "@atlaskit/tmp-editor-statsig": "2.24.0",
28
+ "@atlaskit/tmp-editor-statsig": "2.26.0",
29
29
  "@atlaskit/tokens": "^2.4.0",
30
30
  "@babel/runtime": "^7.0.0"
31
31
  },
@@ -89,6 +89,9 @@
89
89
  },
90
90
  "platform_editor_fix_drag_and_drop_lists": {
91
91
  "type": "boolean"
92
+ },
93
+ "editor_auto_expand_selection_on_inline_node": {
94
+ "type": "boolean"
92
95
  }
93
96
  }
94
97
  }