@atlaskit/editor-plugin-paste-options-toolbar 13.0.7 → 13.0.9
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 +16 -0
- package/dist/cjs/ui/on-paste-actions-menu/PasteActionsMenu.js +40 -7
- package/dist/es2019/ui/on-paste-actions-menu/PasteActionsMenu.js +33 -7
- package/dist/esm/ui/on-paste-actions-menu/PasteActionsMenu.js +39 -7
- package/dist/types/ui/on-paste-actions-menu/PasteActionsMenu.d.ts +6 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-paste-options-toolbar
|
|
2
2
|
|
|
3
|
+
## 13.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
|
|
9
|
+
## 13.0.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`75bc915c1fe98`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/75bc915c1fe98) -
|
|
14
|
+
Hide paste actions when pasting agent mentions behind the platform_editor_agent_mentions
|
|
15
|
+
experiment. The paste plugin now exposes the source pasted slice so consumers can inspect the
|
|
16
|
+
paste handler content without depending on the last transaction step slice.
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 13.0.7
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -5,13 +5,14 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.PasteActionsMenu = void 0;
|
|
8
|
+
exports.containsAgentMention = exports.PasteActionsMenu = void 0;
|
|
9
9
|
exports.findBlockAncestorDOM = findBlockAncestorDOM;
|
|
10
10
|
exports.getTargetElement = getTargetElement;
|
|
11
11
|
exports.getVisualEndBottom = getVisualEndBottom;
|
|
12
12
|
exports.onInlinePositionCalculated = onInlinePositionCalculated;
|
|
13
13
|
exports.onPositionCalculated = onPositionCalculated;
|
|
14
14
|
exports.resolveTableAfterPos = resolveTableAfterPos;
|
|
15
|
+
exports.shouldSuppressPasteActionsForAgentMention = void 0;
|
|
15
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
17
|
var _react = _interopRequireWildcard(require("react"));
|
|
17
18
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
@@ -22,6 +23,7 @@ var _uiReact = require("@atlaskit/editor-common/ui-react");
|
|
|
22
23
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
23
24
|
var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
|
|
24
25
|
var _editorToolbar = require("@atlaskit/editor-toolbar");
|
|
26
|
+
var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
|
|
25
27
|
var _commands = require("../../editor-commands/commands");
|
|
26
28
|
var _constants = require("../../pm-plugins/constants");
|
|
27
29
|
var _types = require("../../types/types");
|
|
@@ -32,6 +34,28 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
32
34
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
33
35
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
34
36
|
var PopupWithListeners = (0, _uiReact.withReactEditorViewOuterListeners)(_ui.Popup);
|
|
37
|
+
var isAgentMentionUserType = function isAgentMentionUserType(userType) {
|
|
38
|
+
return userType === 'APP' || userType === 'AGENT';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Checks whether a pasted ProseMirror slice contains an app or agent mention node.
|
|
43
|
+
*/
|
|
44
|
+
var containsAgentMention = exports.containsAgentMention = function containsAgentMention(slice) {
|
|
45
|
+
if (!slice) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
var hasAgentMention = false;
|
|
49
|
+
slice.content.descendants(function (node) {
|
|
50
|
+
if (node.type.name === 'mention' && isAgentMentionUserType(node.attrs.userType)) {
|
|
51
|
+
hasAgentMention = true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return hasAgentMention;
|
|
55
|
+
};
|
|
56
|
+
var shouldSuppressPasteActionsForAgentMention = exports.shouldSuppressPasteActionsForAgentMention = function shouldSuppressPasteActionsForAgentMention(slice) {
|
|
57
|
+
return (0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false) && containsAgentMention(slice);
|
|
58
|
+
};
|
|
35
59
|
/**
|
|
36
60
|
* Returns the DOM element at the given document position for use as a Popup anchor.
|
|
37
61
|
* For empty blocks (BR elements), returns the parent element to ensure correct positioning.
|
|
@@ -239,6 +263,10 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
239
263
|
};
|
|
240
264
|
}),
|
|
241
265
|
lastContentPasted = _useSharedPluginState.lastContentPasted;
|
|
266
|
+
var sliceForAgentMentionSuppression = lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.sourcePastedSlice;
|
|
267
|
+
var shouldSuppressPasteActions = (0, _react.useMemo)(function () {
|
|
268
|
+
return shouldSuppressPasteActionsForAgentMention(sliceForAgentMentionSuppression);
|
|
269
|
+
}, [sliceForAgentMentionSuppression]);
|
|
242
270
|
var prevShowToolbarRef = (0, _react.useRef)(false);
|
|
243
271
|
var popupContentRef = (0, _react.useRef)(null);
|
|
244
272
|
(0, _react.useEffect)(function () {
|
|
@@ -246,6 +274,10 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
246
274
|
(0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
|
|
247
275
|
return;
|
|
248
276
|
}
|
|
277
|
+
if (shouldSuppressPasteActions) {
|
|
278
|
+
(0, _commands.hideToolbar)()(editorView.state, editorView.dispatch);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
249
281
|
var selectedOption = _types.ToolbarDropdownOption.None;
|
|
250
282
|
if (!lastContentPasted.isPlainText) {
|
|
251
283
|
selectedOption = _types.ToolbarDropdownOption.RichText;
|
|
@@ -266,7 +298,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
266
298
|
}
|
|
267
299
|
var legacyVisible = (0, _toolbar2.isToolbarVisible)(editorView.state, lastContentPasted);
|
|
268
300
|
(0, _commands.showToolbar)(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
269
|
-
}, [lastContentPasted, editorView]);
|
|
301
|
+
}, [lastContentPasted, shouldSuppressPasteActions, editorView]);
|
|
270
302
|
var _useSharedPluginState2 = (0, _hooks.useSharedPluginStateWithSelector)(api, ['pasteOptionsToolbarPlugin'], function (states) {
|
|
271
303
|
var _pluginState$showTool, _pluginState$pasteSta, _pluginState$pasteEnd;
|
|
272
304
|
var pluginState = states.pasteOptionsToolbarPluginState;
|
|
@@ -302,13 +334,14 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
302
334
|
handleDismiss();
|
|
303
335
|
}
|
|
304
336
|
}, [handleDismiss]);
|
|
337
|
+
var shouldRenderToolbar = isToolbarShown && !shouldSuppressPasteActions;
|
|
305
338
|
|
|
306
339
|
// Find the actual scroll container using the same utility the Popup's
|
|
307
340
|
// stick prop uses internally. We pass this as the scrollableElement prop
|
|
308
341
|
// so the Popup attaches its built-in scroll listener, which calls
|
|
309
342
|
// scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
|
|
310
343
|
// onPositionCalculated with fresh viewport coordinates.
|
|
311
|
-
var overflowScrollParent =
|
|
344
|
+
var overflowScrollParent = shouldRenderToolbar ? (0, _ui.findOverflowScrollParent)(editorView.dom) : false;
|
|
312
345
|
var effectiveScrollableElement = overflowScrollParent || scrollableElement;
|
|
313
346
|
var pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_toolbar.PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
314
347
|
var anyComponentVisible = (0, _hasVisibleButton.hasVisibleButton)(pasteMenuComponents);
|
|
@@ -329,7 +362,7 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
329
362
|
// of the content block, aligned with paste start.
|
|
330
363
|
var hasVisibleAiActions = visibleAiActionKeys.length > 0;
|
|
331
364
|
(0, _react.useEffect)(function () {
|
|
332
|
-
if (!prevShowToolbarRef.current &&
|
|
365
|
+
if (!prevShowToolbarRef.current && shouldRenderToolbar) {
|
|
333
366
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
|
|
334
367
|
action: _analytics.ACTION.OPENED,
|
|
335
368
|
actionSubject: _analytics.ACTION_SUBJECT.PASTE_ACTIONS_MENU,
|
|
@@ -339,11 +372,11 @@ var PasteActionsMenu = exports.PasteActionsMenu = function PasteActionsMenu(_ref
|
|
|
339
372
|
}
|
|
340
373
|
});
|
|
341
374
|
}
|
|
342
|
-
prevShowToolbarRef.current =
|
|
375
|
+
prevShowToolbarRef.current = shouldRenderToolbar;
|
|
343
376
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
344
|
-
}, [
|
|
377
|
+
}, [shouldRenderToolbar, editorAnalyticsAPI]);
|
|
345
378
|
var useInlinePosition = !hasVisibleAiActions;
|
|
346
|
-
if (!
|
|
379
|
+
if (!shouldRenderToolbar) {
|
|
347
380
|
return null;
|
|
348
381
|
}
|
|
349
382
|
if (!anyComponentVisible) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
4
4
|
import { AI_PASTE_MENU_SECTION, EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
@@ -7,6 +7,7 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
|
|
|
7
7
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
8
8
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
9
9
|
import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
|
|
10
|
+
import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
10
11
|
import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
|
|
11
12
|
import { PASTE_MENU_GAP_HORIZONTAL, PASTE_MENU_GAP_TOP } from '../../pm-plugins/constants';
|
|
12
13
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
@@ -14,6 +15,24 @@ import { isToolbarVisible } from '../toolbar';
|
|
|
14
15
|
import { getVisibleKeys, hasVisibleButton } from './hasVisibleButton';
|
|
15
16
|
import { PasteActionsMenuContent } from './PasteActionsMenuContent';
|
|
16
17
|
const PopupWithListeners = withReactEditorViewOuterListeners(Popup);
|
|
18
|
+
const isAgentMentionUserType = userType => userType === 'APP' || userType === 'AGENT';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether a pasted ProseMirror slice contains an app or agent mention node.
|
|
22
|
+
*/
|
|
23
|
+
export const containsAgentMention = slice => {
|
|
24
|
+
if (!slice) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
let hasAgentMention = false;
|
|
28
|
+
slice.content.descendants(node => {
|
|
29
|
+
if (node.type.name === 'mention' && isAgentMentionUserType(node.attrs.userType)) {
|
|
30
|
+
hasAgentMention = true;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return hasAgentMention;
|
|
34
|
+
};
|
|
35
|
+
export const shouldSuppressPasteActionsForAgentMention = slice => expVal('platform_editor_agent_mentions', 'isEnabled', false) && containsAgentMention(slice);
|
|
17
36
|
/**
|
|
18
37
|
* Returns the DOM element at the given document position for use as a Popup anchor.
|
|
19
38
|
* For empty blocks (BR elements), returns the parent element to ensure correct positioning.
|
|
@@ -225,6 +244,8 @@ export const PasteActionsMenu = ({
|
|
|
225
244
|
lastContentPasted: (_states$pasteState = states.pasteState) === null || _states$pasteState === void 0 ? void 0 : _states$pasteState.lastContentPasted
|
|
226
245
|
};
|
|
227
246
|
});
|
|
247
|
+
const sliceForAgentMentionSuppression = lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.sourcePastedSlice;
|
|
248
|
+
const shouldSuppressPasteActions = useMemo(() => shouldSuppressPasteActionsForAgentMention(sliceForAgentMentionSuppression), [sliceForAgentMentionSuppression]);
|
|
228
249
|
const prevShowToolbarRef = useRef(false);
|
|
229
250
|
const popupContentRef = useRef(null);
|
|
230
251
|
useEffect(() => {
|
|
@@ -232,6 +253,10 @@ export const PasteActionsMenu = ({
|
|
|
232
253
|
hideToolbar()(editorView.state, editorView.dispatch);
|
|
233
254
|
return;
|
|
234
255
|
}
|
|
256
|
+
if (shouldSuppressPasteActions) {
|
|
257
|
+
hideToolbar()(editorView.state, editorView.dispatch);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
235
260
|
let selectedOption = ToolbarDropdownOption.None;
|
|
236
261
|
if (!lastContentPasted.isPlainText) {
|
|
237
262
|
selectedOption = ToolbarDropdownOption.RichText;
|
|
@@ -252,7 +277,7 @@ export const PasteActionsMenu = ({
|
|
|
252
277
|
}
|
|
253
278
|
const legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
|
|
254
279
|
showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
255
|
-
}, [lastContentPasted, editorView]);
|
|
280
|
+
}, [lastContentPasted, shouldSuppressPasteActions, editorView]);
|
|
256
281
|
const {
|
|
257
282
|
showToolbar: isToolbarShown,
|
|
258
283
|
pasteStartPos,
|
|
@@ -289,13 +314,14 @@ export const PasteActionsMenu = ({
|
|
|
289
314
|
handleDismiss();
|
|
290
315
|
}
|
|
291
316
|
}, [handleDismiss]);
|
|
317
|
+
const shouldRenderToolbar = isToolbarShown && !shouldSuppressPasteActions;
|
|
292
318
|
|
|
293
319
|
// Find the actual scroll container using the same utility the Popup's
|
|
294
320
|
// stick prop uses internally. We pass this as the scrollableElement prop
|
|
295
321
|
// so the Popup attaches its built-in scroll listener, which calls
|
|
296
322
|
// scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
|
|
297
323
|
// onPositionCalculated with fresh viewport coordinates.
|
|
298
|
-
const overflowScrollParent =
|
|
324
|
+
const overflowScrollParent = shouldRenderToolbar ? findOverflowScrollParent(editorView.dom) : false;
|
|
299
325
|
const effectiveScrollableElement = overflowScrollParent || scrollableElement;
|
|
300
326
|
const pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 ? void 0 : (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
301
327
|
const anyComponentVisible = hasVisibleButton(pasteMenuComponents);
|
|
@@ -314,7 +340,7 @@ export const PasteActionsMenu = ({
|
|
|
314
340
|
// of the content block, aligned with paste start.
|
|
315
341
|
const hasVisibleAiActions = visibleAiActionKeys.length > 0;
|
|
316
342
|
useEffect(() => {
|
|
317
|
-
if (!prevShowToolbarRef.current &&
|
|
343
|
+
if (!prevShowToolbarRef.current && shouldRenderToolbar) {
|
|
318
344
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 ? void 0 : editorAnalyticsAPI.fireAnalyticsEvent({
|
|
319
345
|
action: ACTION.OPENED,
|
|
320
346
|
actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
|
|
@@ -324,11 +350,11 @@ export const PasteActionsMenu = ({
|
|
|
324
350
|
}
|
|
325
351
|
});
|
|
326
352
|
}
|
|
327
|
-
prevShowToolbarRef.current =
|
|
353
|
+
prevShowToolbarRef.current = shouldRenderToolbar;
|
|
328
354
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
329
|
-
}, [
|
|
355
|
+
}, [shouldRenderToolbar, editorAnalyticsAPI]);
|
|
330
356
|
const useInlinePosition = !hasVisibleAiActions;
|
|
331
|
-
if (!
|
|
357
|
+
if (!shouldRenderToolbar) {
|
|
332
358
|
return null;
|
|
333
359
|
}
|
|
334
360
|
if (!anyComponentVisible) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
import React, { useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
5
5
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
6
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
7
7
|
import { AI_PASTE_MENU_SECTION, EditorToolbarProvider, PASTE_MENU } from '@atlaskit/editor-common/toolbar';
|
|
@@ -10,6 +10,7 @@ import { withReactEditorViewOuterListeners } from '@atlaskit/editor-common/ui-re
|
|
|
10
10
|
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
11
11
|
import { akEditorFloatingPanelZIndex } from '@atlaskit/editor-shared-styles';
|
|
12
12
|
import { ToolbarDropdownMenuProvider } from '@atlaskit/editor-toolbar';
|
|
13
|
+
import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
|
|
13
14
|
import { hideToolbar, highlightContent, showToolbar } from '../../editor-commands/commands';
|
|
14
15
|
import { PASTE_MENU_GAP_HORIZONTAL, PASTE_MENU_GAP_TOP } from '../../pm-plugins/constants';
|
|
15
16
|
import { ToolbarDropdownOption } from '../../types/types';
|
|
@@ -17,6 +18,28 @@ import { isToolbarVisible } from '../toolbar';
|
|
|
17
18
|
import { getVisibleKeys, hasVisibleButton } from './hasVisibleButton';
|
|
18
19
|
import { PasteActionsMenuContent } from './PasteActionsMenuContent';
|
|
19
20
|
var PopupWithListeners = withReactEditorViewOuterListeners(Popup);
|
|
21
|
+
var isAgentMentionUserType = function isAgentMentionUserType(userType) {
|
|
22
|
+
return userType === 'APP' || userType === 'AGENT';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether a pasted ProseMirror slice contains an app or agent mention node.
|
|
27
|
+
*/
|
|
28
|
+
export var containsAgentMention = function containsAgentMention(slice) {
|
|
29
|
+
if (!slice) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
var hasAgentMention = false;
|
|
33
|
+
slice.content.descendants(function (node) {
|
|
34
|
+
if (node.type.name === 'mention' && isAgentMentionUserType(node.attrs.userType)) {
|
|
35
|
+
hasAgentMention = true;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return hasAgentMention;
|
|
39
|
+
};
|
|
40
|
+
export var shouldSuppressPasteActionsForAgentMention = function shouldSuppressPasteActionsForAgentMention(slice) {
|
|
41
|
+
return expVal('platform_editor_agent_mentions', 'isEnabled', false) && containsAgentMention(slice);
|
|
42
|
+
};
|
|
20
43
|
/**
|
|
21
44
|
* Returns the DOM element at the given document position for use as a Popup anchor.
|
|
22
45
|
* For empty blocks (BR elements), returns the parent element to ensure correct positioning.
|
|
@@ -224,6 +247,10 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
224
247
|
};
|
|
225
248
|
}),
|
|
226
249
|
lastContentPasted = _useSharedPluginState.lastContentPasted;
|
|
250
|
+
var sliceForAgentMentionSuppression = lastContentPasted === null || lastContentPasted === void 0 ? void 0 : lastContentPasted.sourcePastedSlice;
|
|
251
|
+
var shouldSuppressPasteActions = useMemo(function () {
|
|
252
|
+
return shouldSuppressPasteActionsForAgentMention(sliceForAgentMentionSuppression);
|
|
253
|
+
}, [sliceForAgentMentionSuppression]);
|
|
227
254
|
var prevShowToolbarRef = useRef(false);
|
|
228
255
|
var popupContentRef = useRef(null);
|
|
229
256
|
useEffect(function () {
|
|
@@ -231,6 +258,10 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
231
258
|
hideToolbar()(editorView.state, editorView.dispatch);
|
|
232
259
|
return;
|
|
233
260
|
}
|
|
261
|
+
if (shouldSuppressPasteActions) {
|
|
262
|
+
hideToolbar()(editorView.state, editorView.dispatch);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
234
265
|
var selectedOption = ToolbarDropdownOption.None;
|
|
235
266
|
if (!lastContentPasted.isPlainText) {
|
|
236
267
|
selectedOption = ToolbarDropdownOption.RichText;
|
|
@@ -251,7 +282,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
251
282
|
}
|
|
252
283
|
var legacyVisible = isToolbarVisible(editorView.state, lastContentPasted);
|
|
253
284
|
showToolbar(lastContentPasted, selectedOption, legacyVisible, pasteAncestorNodeNames)(editorView.state, editorView.dispatch);
|
|
254
|
-
}, [lastContentPasted, editorView]);
|
|
285
|
+
}, [lastContentPasted, shouldSuppressPasteActions, editorView]);
|
|
255
286
|
var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['pasteOptionsToolbarPlugin'], function (states) {
|
|
256
287
|
var _pluginState$showTool, _pluginState$pasteSta, _pluginState$pasteEnd;
|
|
257
288
|
var pluginState = states.pasteOptionsToolbarPluginState;
|
|
@@ -287,13 +318,14 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
287
318
|
handleDismiss();
|
|
288
319
|
}
|
|
289
320
|
}, [handleDismiss]);
|
|
321
|
+
var shouldRenderToolbar = isToolbarShown && !shouldSuppressPasteActions;
|
|
290
322
|
|
|
291
323
|
// Find the actual scroll container using the same utility the Popup's
|
|
292
324
|
// stick prop uses internally. We pass this as the scrollableElement prop
|
|
293
325
|
// so the Popup attaches its built-in scroll listener, which calls
|
|
294
326
|
// scheduledUpdatePosition (RAF-throttled) on each scroll event — triggering
|
|
295
327
|
// onPositionCalculated with fresh viewport coordinates.
|
|
296
|
-
var overflowScrollParent =
|
|
328
|
+
var overflowScrollParent = shouldRenderToolbar ? findOverflowScrollParent(editorView.dom) : false;
|
|
297
329
|
var effectiveScrollableElement = overflowScrollParent || scrollableElement;
|
|
298
330
|
var pasteMenuComponents = (_api$uiControlRegistr = api === null || api === void 0 || (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(PASTE_MENU.key)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
|
|
299
331
|
var anyComponentVisible = hasVisibleButton(pasteMenuComponents);
|
|
@@ -314,7 +346,7 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
314
346
|
// of the content block, aligned with paste start.
|
|
315
347
|
var hasVisibleAiActions = visibleAiActionKeys.length > 0;
|
|
316
348
|
useEffect(function () {
|
|
317
|
-
if (!prevShowToolbarRef.current &&
|
|
349
|
+
if (!prevShowToolbarRef.current && shouldRenderToolbar) {
|
|
318
350
|
editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.fireAnalyticsEvent({
|
|
319
351
|
action: ACTION.OPENED,
|
|
320
352
|
actionSubject: ACTION_SUBJECT.PASTE_ACTIONS_MENU,
|
|
@@ -324,11 +356,11 @@ export var PasteActionsMenu = function PasteActionsMenu(_ref) {
|
|
|
324
356
|
}
|
|
325
357
|
});
|
|
326
358
|
}
|
|
327
|
-
prevShowToolbarRef.current =
|
|
359
|
+
prevShowToolbarRef.current = shouldRenderToolbar;
|
|
328
360
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
329
|
-
}, [
|
|
361
|
+
}, [shouldRenderToolbar, editorAnalyticsAPI]);
|
|
330
362
|
var useInlinePosition = !hasVisibleAiActions;
|
|
331
|
-
if (!
|
|
363
|
+
if (!shouldRenderToolbar) {
|
|
332
364
|
return null;
|
|
333
365
|
}
|
|
334
366
|
if (!anyComponentVisible) {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
4
|
import type { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
4
5
|
import type { PasteOptionsToolbarPlugin } from '../../pasteOptionsToolbarPluginType';
|
|
6
|
+
/**
|
|
7
|
+
* Checks whether a pasted ProseMirror slice contains an app or agent mention node.
|
|
8
|
+
*/
|
|
9
|
+
export declare const containsAgentMention: (slice?: Slice | null) => boolean;
|
|
10
|
+
export declare const shouldSuppressPasteActionsForAgentMention: (slice?: Slice | null) => boolean;
|
|
5
11
|
interface PasteActionsMenuProps {
|
|
6
12
|
api: ExtractInjectionAPI<PasteOptionsToolbarPlugin> | undefined;
|
|
7
13
|
boundariesElement?: HTMLElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-paste-options-toolbar",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.9",
|
|
4
4
|
"description": "Paste options toolbar for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@atlaskit/dropdown-menu": "^17.0.0",
|
|
26
26
|
"@atlaskit/editor-markdown-transformer": "^6.0.0",
|
|
27
27
|
"@atlaskit/editor-plugin-analytics": "^12.0.0",
|
|
28
|
-
"@atlaskit/editor-plugin-paste": "^13.
|
|
28
|
+
"@atlaskit/editor-plugin-paste": "^13.2.0",
|
|
29
29
|
"@atlaskit/editor-plugin-ui-control-registry": "^6.0.0",
|
|
30
30
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
31
31
|
"@atlaskit/editor-shared-styles": "^4.0.0",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"@atlaskit/icon": "^36.0.0",
|
|
35
35
|
"@atlaskit/platform-feature-flags": "^2.0.0",
|
|
36
36
|
"@atlaskit/primitives": "^20.0.0",
|
|
37
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
37
|
+
"@atlaskit/tmp-editor-statsig": "^112.0.0",
|
|
38
38
|
"@atlaskit/tokens": "^15.0.0",
|
|
39
39
|
"@babel/runtime": "^7.0.0",
|
|
40
40
|
"@compiled/react": "^0.20.0",
|
|
41
41
|
"@emotion/react": "^11.7.1"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@atlaskit/editor-common": "^116.
|
|
44
|
+
"@atlaskit/editor-common": "^116.12.0",
|
|
45
45
|
"react": "^18.2.0",
|
|
46
46
|
"react-dom": "^18.2.0",
|
|
47
47
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
@@ -54,6 +54,9 @@
|
|
|
54
54
|
"wait-for-expect": "^1.2.0"
|
|
55
55
|
},
|
|
56
56
|
"platform-feature-flags": {
|
|
57
|
+
"platform_editor_agent_mentions": {
|
|
58
|
+
"type": "experiment"
|
|
59
|
+
},
|
|
57
60
|
"platform_editor_paste_actions_menu_exposure": {
|
|
58
61
|
"type": "boolean"
|
|
59
62
|
},
|