@atlaskit/editor-plugin-paste-options-toolbar 9.1.1 → 9.1.3

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,23 @@
1
1
  # @atlaskit/editor-plugin-paste-options-toolbar
2
2
 
3
+ ## 9.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0fe3de6aa5e9c`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0fe3de6aa5e9c) -
8
+ [ux] EDITOR-5978 Add additional buttons and update thresholds for Editor AI paste actions. Only
9
+ show existing paste actions if pasting greater than 100 characters.
10
+
11
+ ## 9.1.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [`0386f83e8c2b8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0386f83e8c2b8) -
16
+ Fix paste actions menu dismissing when pressing modifier keys (Ctrl, Shift, Alt, Meta/Cmd).
17
+ Modifier-only key presses no longer hide the toolbar, gated behind
18
+ platform_editor_paste_actions_keypress_fix feature flag.
19
+ - Updated dependencies
20
+
3
21
  ## 9.1.1
4
22
 
5
23
  ### Patch Changes
@@ -7,10 +7,17 @@ exports.createPlugin = createPlugin;
7
7
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
8
8
  var _model = require("@atlaskit/editor-prosemirror/model");
9
9
  var _view2 = require("@atlaskit/editor-prosemirror/view");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
10
11
  var _commands = require("../editor-commands/commands");
11
12
  var _types = require("../types/types");
12
13
  var _constants = require("./constants");
13
14
  var _pluginFactory = require("./plugin-factory");
15
+ var MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta',
16
+ // Cmd on Mac, Win on Windows
17
+ 'CapsLock', 'NumLock', 'ScrollLock', 'Fn', 'FnLock']);
18
+ function isModifierKey(event) {
19
+ return MODIFIER_KEYS.has(event.key);
20
+ }
14
21
  function createPlugin(dispatch, options) {
15
22
  return new _safePlugin.SafePlugin({
16
23
  key: _types.pasteOptionsPluginKey,
@@ -46,7 +53,11 @@ function createPlugin(dispatch, options) {
46
53
  // Hide toolbar when clicked anywhere within the editor, tr.getMeta('pointer') does not work if clicked on the same line after pasting so relying on mousedown event
47
54
  mousedown: _commands.checkAndHideToolbar
48
55
  },
49
- handleKeyDown: function handleKeyDown(view) {
56
+ handleKeyDown: function handleKeyDown(view, event) {
57
+ // Don't hide toolbar when pressing modifier keys alone (Ctrl, Shift, Alt, Meta/Cmd)
58
+ if (isModifierKey(event) && (0, _platformFeatureFlags.fg)('platform_editor_paste_actions_keypress_fix')) {
59
+ return false;
60
+ }
50
61
  (0, _commands.checkAndHideToolbar)(view);
51
62
  return false;
52
63
  },
@@ -99,6 +99,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
99
99
  lastContentPasted = _useSharedPluginState.lastContentPasted;
100
100
  var prevShowToolbarRef = (0, _react.useRef)(false);
101
101
  (0, _react.useEffect)(function () {
102
+ var _lastContentPasted$te, _lastContentPasted$te2;
102
103
  if (!lastContentPasted) {
103
104
  (0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
104
105
  return;
@@ -116,7 +117,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
116
117
  for (var depth = $pos.depth; depth > 0; depth--) {
117
118
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
118
119
  }
119
- var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
120
+ var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
120
121
  (0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
121
122
  }, [lastContentPasted, editorView]);
122
123
  var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
@@ -1,10 +1,17 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { Slice } from '@atlaskit/editor-prosemirror/model';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { checkAndHideToolbar } from '../editor-commands/commands';
5
6
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from '../types/types';
6
7
  import { PASTE_HIGHLIGHT_DECORATION_KEY, TEXT_HIGHLIGHT_CLASS } from './constants';
7
8
  import { createPluginState } from './plugin-factory';
9
+ const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta',
10
+ // Cmd on Mac, Win on Windows
11
+ 'CapsLock', 'NumLock', 'ScrollLock', 'Fn', 'FnLock']);
12
+ function isModifierKey(event) {
13
+ return MODIFIER_KEYS.has(event.key);
14
+ }
8
15
  export function createPlugin(dispatch, options) {
9
16
  return new SafePlugin({
10
17
  key: pasteOptionsPluginKey,
@@ -40,7 +47,11 @@ export function createPlugin(dispatch, options) {
40
47
  // Hide toolbar when clicked anywhere within the editor, tr.getMeta('pointer') does not work if clicked on the same line after pasting so relying on mousedown event
41
48
  mousedown: checkAndHideToolbar
42
49
  },
43
- handleKeyDown: view => {
50
+ handleKeyDown: (view, event) => {
51
+ // Don't hide toolbar when pressing modifier keys alone (Ctrl, Shift, Alt, Meta/Cmd)
52
+ if (isModifierKey(event) && fg('platform_editor_paste_actions_keypress_fix')) {
53
+ return false;
54
+ }
44
55
  checkAndHideToolbar(view);
45
56
  return false;
46
57
  },
@@ -89,6 +89,7 @@ export const PasteActionsMenu = ({
89
89
  });
90
90
  const prevShowToolbarRef = useRef(false);
91
91
  useEffect(() => {
92
+ var _lastContentPasted$te, _lastContentPasted$te2;
92
93
  if (!lastContentPasted) {
93
94
  hideToolbar()(editorView.state, editorView.dispatch);
94
95
  return;
@@ -106,7 +107,7 @@ export const PasteActionsMenu = ({
106
107
  for (let depth = $pos.depth; depth > 0; depth--) {
107
108
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
108
109
  }
109
- const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
110
+ const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
110
111
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
111
112
  }, [lastContentPasted, editorView]);
112
113
  const {
@@ -1,10 +1,17 @@
1
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
2
  import { Slice } from '@atlaskit/editor-prosemirror/model';
3
3
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
4
5
  import { checkAndHideToolbar } from '../editor-commands/commands';
5
6
  import { pasteOptionsPluginKey, ToolbarDropdownOption } from '../types/types';
6
7
  import { PASTE_HIGHLIGHT_DECORATION_KEY, TEXT_HIGHLIGHT_CLASS } from './constants';
7
8
  import { createPluginState } from './plugin-factory';
9
+ var MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta',
10
+ // Cmd on Mac, Win on Windows
11
+ 'CapsLock', 'NumLock', 'ScrollLock', 'Fn', 'FnLock']);
12
+ function isModifierKey(event) {
13
+ return MODIFIER_KEYS.has(event.key);
14
+ }
8
15
  export function createPlugin(dispatch, options) {
9
16
  return new SafePlugin({
10
17
  key: pasteOptionsPluginKey,
@@ -40,7 +47,11 @@ export function createPlugin(dispatch, options) {
40
47
  // Hide toolbar when clicked anywhere within the editor, tr.getMeta('pointer') does not work if clicked on the same line after pasting so relying on mousedown event
41
48
  mousedown: checkAndHideToolbar
42
49
  },
43
- handleKeyDown: function handleKeyDown(view) {
50
+ handleKeyDown: function handleKeyDown(view, event) {
51
+ // Don't hide toolbar when pressing modifier keys alone (Ctrl, Shift, Alt, Meta/Cmd)
52
+ if (isModifierKey(event) && fg('platform_editor_paste_actions_keypress_fix')) {
53
+ return false;
54
+ }
44
55
  checkAndHideToolbar(view);
45
56
  return false;
46
57
  },
@@ -89,6 +89,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
89
89
  lastContentPasted = _useSharedPluginState.lastContentPasted;
90
90
  var prevShowToolbarRef = useRef(false);
91
91
  useEffect(function () {
92
+ var _lastContentPasted$te, _lastContentPasted$te2;
92
93
  if (!lastContentPasted) {
93
94
  hideToolbar()(editorView.state, editorView.dispatch);
94
95
  return;
@@ -106,7 +107,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
106
107
  for (var depth = $pos.depth; depth > 0; depth--) {
107
108
  pasteAncestorNodeNames.push($pos.node(depth).type.name);
108
109
  }
109
- var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
110
+ var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted) && ((_lastContentPasted$te = (_lastContentPasted$te2 = lastContentPasted.text) === null || _lastContentPasted$te2 === void 0 ? void 0 : _lastContentPasted$te2.length) !== null && _lastContentPasted$te !== void 0 ? _lastContentPasted$te : 0) >= 100;
110
111
  showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
111
112
  }, [lastContentPasted, editorView]);
112
113
  var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-paste-options-toolbar",
3
- "version": "9.1.1",
3
+ "version": "9.1.3",
4
4
  "description": "Paste options toolbar for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -48,7 +48,7 @@
48
48
  "react-intl-next": "npm:react-intl@^5.18.1"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^112.4.0",
51
+ "@atlaskit/editor-common": "^112.5.0",
52
52
  "react": "^18.2.0",
53
53
  "react-dom": "^18.2.0"
54
54
  },
@@ -56,6 +56,11 @@
56
56
  "@testing-library/react": "^16.3.0",
57
57
  "wait-for-expect": "^1.2.0"
58
58
  },
59
+ "platform-feature-flags": {
60
+ "platform_editor_paste_actions_keypress_fix": {
61
+ "type": "boolean"
62
+ }
63
+ },
59
64
  "techstack": {
60
65
  "@atlassian/frontend": {
61
66
  "code-structure": [