@atlaskit/editor-plugin-mentions 15.1.0 → 15.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.
@@ -0,0 +1,139 @@
1
+ /* InlineInvitePopupContainer.tsx generated by @compiled/babel-plugin v2.0.0 */
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
5
+ var findMentionRange = function findMentionRange(doc, localId) {
6
+ var range = null;
7
+ doc.descendants(function (node, pos) {
8
+ if (range) {
9
+ return false;
10
+ }
11
+ if (node.type.name === 'mention' && node.attrs.localId === localId) {
12
+ range = {
13
+ from: pos,
14
+ to: pos + node.nodeSize
15
+ };
16
+ return false;
17
+ }
18
+ return true;
19
+ });
20
+ return range;
21
+ };
22
+ export var InlineInvitePopupContainer = function InlineInvitePopupContainer(_ref) {
23
+ var _api$mention2, _api$core3;
24
+ var mentionProvider = _ref.mentionProvider,
25
+ api = _ref.api,
26
+ editorView = _ref.editorView;
27
+ var _useState = useState(null),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ provider = _useState2[0],
30
+ setProvider = _useState2[1];
31
+ var _useState3 = useState(null),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ anchorElement = _useState4[0],
34
+ setAnchorElement = _useState4[1];
35
+ var pendingMentionRef = useRef(null);
36
+ useEffect(function () {
37
+ if (!mentionProvider) {
38
+ return;
39
+ }
40
+ var isMounted = true;
41
+ mentionProvider.then(function (resolvedProvider) {
42
+ var _providerWithPopup$ge;
43
+ if (!isMounted) {
44
+ return;
45
+ }
46
+ var providerWithPopup = resolvedProvider;
47
+ var originalGetMentionDisabledState = (_providerWithPopup$ge = providerWithPopup.getMentionDisabledState) === null || _providerWithPopup$ge === void 0 ? void 0 : _providerWithPopup$ge.bind(providerWithPopup);
48
+ providerWithPopup.getMentionDisabledState = function (mention) {
49
+ var _pendingMentionRef$cu;
50
+ if (((_pendingMentionRef$cu = pendingMentionRef.current) === null || _pendingMentionRef$cu === void 0 ? void 0 : _pendingMentionRef$cu.localId) === mention.id) {
51
+ return {
52
+ disabled: true
53
+ };
54
+ }
55
+ return originalGetMentionDisabledState === null || originalGetMentionDisabledState === void 0 ? void 0 : originalGetMentionDisabledState(mention);
56
+ };
57
+ setProvider(providerWithPopup);
58
+ }).catch(function () {});
59
+ return function () {
60
+ isMounted = false;
61
+ setProvider(null);
62
+ };
63
+ }, [mentionProvider]);
64
+ var removePendingMention = useCallback(function () {
65
+ var _api$core;
66
+ var pending = pendingMentionRef.current;
67
+ if (pending && api !== null && api !== void 0 && (_api$core = api.core) !== null && _api$core !== void 0 && (_api$core = _api$core.actions) !== null && _api$core !== void 0 && _api$core.execute) {
68
+ api.core.actions.execute(function (_ref2) {
69
+ var tr = _ref2.tr;
70
+ var range = findMentionRange(tr.doc, pending.localId);
71
+ return range ? tr.delete(range.from, range.to) : null;
72
+ });
73
+ }
74
+ pendingMentionRef.current = null;
75
+ setAnchorElement(null);
76
+ }, [api]);
77
+ var handleDismiss = useCallback(function () {
78
+ removePendingMention();
79
+ }, [removePendingMention]);
80
+ var handleInviteComplete = useCallback(function (result) {
81
+ var _result$invited$, _api$core2, _api$mention;
82
+ var pending = pendingMentionRef.current;
83
+ if (!pending) {
84
+ return;
85
+ }
86
+ var invitedUser = (_result$invited$ = result.invited[0]) !== null && _result$invited$ !== void 0 ? _result$invited$ : result.requested[0];
87
+ if (!invitedUser || !(api !== null && api !== void 0 && (_api$core2 = api.core) !== null && _api$core2 !== void 0 && (_api$core2 = _api$core2.actions) !== null && _api$core2 !== void 0 && _api$core2.execute) || !(api !== null && api !== void 0 && (_api$mention = api.mention) !== null && _api$mention !== void 0 && (_api$mention = _api$mention.commands) !== null && _api$mention !== void 0 && _api$mention.insertMention)) {
88
+ removePendingMention();
89
+ return;
90
+ }
91
+ var userId = invitedUser.id,
92
+ email = invitedUser.email;
93
+ var name = email.split('@')[0] || email;
94
+ api.core.actions.execute(function (_ref3) {
95
+ var tr = _ref3.tr;
96
+ var range = findMentionRange(tr.doc, pending.localId);
97
+ return range ? tr.delete(range.from, range.to) : null;
98
+ });
99
+ api.core.actions.execute(api.mention.commands.insertMention({
100
+ id: userId,
101
+ name: name,
102
+ userType: 'DEFAULT',
103
+ accessLevel: 'CONTAINER'
104
+ }));
105
+ pendingMentionRef.current = null;
106
+ setAnchorElement(null);
107
+ }, [api, removePendingMention]);
108
+ var handleReady = useCallback(function (show) {
109
+ if (!provider) {
110
+ return;
111
+ }
112
+ if (show) {
113
+ provider.showInlineInvitePopup = function (email, localId) {
114
+ pendingMentionRef.current = {
115
+ email: email,
116
+ localId: localId
117
+ };
118
+ setTimeout(function () {
119
+ var range = findMentionRange(editorView.state.doc, localId);
120
+ var dom = range ? editorView.nodeDOM(range.from) : null;
121
+ setAnchorElement(dom instanceof HTMLElement ? dom : null);
122
+ show(email);
123
+ }, 0);
124
+ };
125
+ } else {
126
+ delete provider.showInlineInvitePopup;
127
+ }
128
+ }, [provider, editorView]);
129
+ if (!(provider !== null && provider !== void 0 && provider.InlineInvitePopup) || !(api !== null && api !== void 0 && (_api$mention2 = api.mention) !== null && _api$mention2 !== void 0 && (_api$mention2 = _api$mention2.commands) !== null && _api$mention2 !== void 0 && _api$mention2.insertMention) || !(api !== null && api !== void 0 && (_api$core3 = api.core) !== null && _api$core3 !== void 0 && (_api$core3 = _api$core3.actions) !== null && _api$core3 !== void 0 && _api$core3.execute)) {
130
+ return null;
131
+ }
132
+ var PopupComponent = provider.InlineInvitePopup;
133
+ return /*#__PURE__*/React.createElement(PopupComponent, {
134
+ anchorElement: anchorElement,
135
+ onInviteComplete: handleInviteComplete,
136
+ onDismiss: handleDismiss,
137
+ onReady: handleReady
138
+ });
139
+ };
@@ -23,7 +23,6 @@ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
23
23
  import { createSingleMentionFragment } from '../../editor-commands';
24
24
  import { mentionPluginKey } from '../../pm-plugins/key';
25
25
  import { ACTIONS } from '../../pm-plugins/main';
26
- import { mentionPlaceholderPluginKey, MENTION_PLACEHOLDER_ACTIONS } from '../../pm-plugins/mentionPlaceholder';
27
26
  import { getMentionPluginState } from '../../pm-plugins/utils';
28
27
  import InviteItem, { INVITE_ITEM_DESCRIPTION } from '../InviteItem';
29
28
  import InviteItemWithEmailDomain from '../InviteItem/InviteItemWithEmailDomain';
@@ -58,7 +57,7 @@ var createInviteItem = function createInviteItem(_ref) {
58
57
  var isSelected = _ref2.isSelected,
59
58
  onClick = _ref2.onClick,
60
59
  onHover = _ref2.onHover;
61
- return emailDomain && (_mentionProvider$getS = mentionProvider.getShouldEnableInlineInvite) !== null && _mentionProvider$getS !== void 0 && _mentionProvider$getS.call(mentionProvider) && fg('jira_invites_auto_tag_new_user_in_mentions_fg') ? /*#__PURE__*/React.createElement(InviteItemWithEmailDomain, {
60
+ return emailDomain && (_mentionProvider$getS = mentionProvider.getShouldEnableInlineInvite) !== null && _mentionProvider$getS !== void 0 && _mentionProvider$getS.call(mentionProvider) && fg('inline_invite_from_mentions_kill_switch') ? /*#__PURE__*/React.createElement(InviteItemWithEmailDomain, {
62
61
  productName: mentionProvider ? mentionProvider.productName : undefined,
63
62
  selected: isSelected,
64
63
  onMount: onInviteItemMount,
@@ -481,10 +480,10 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref8) {
481
480
  // Don't fire event and the callback with selection by space press
482
481
  if (mode !== 'space') {
483
482
  var _mentionProvider$getS3, _mentionProvider$getS4;
484
- fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, contextIdentifierProvider, mentionProvider.userRole, fg('jira_invites_auto_tag_new_user_in_mentions_fg') ? {
483
+ fireEvent(buildTypeAheadInviteItemClickedPayload(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, query, contextIdentifierProvider, mentionProvider.userRole, fg('inline_invite_from_mentions_kill_switch') ? {
485
484
  isInlineInviteMentionsEnabled: (_mentionProvider$getS3 = mentionProvider.getShouldEnableInlineInvite) === null || _mentionProvider$getS3 === void 0 ? void 0 : _mentionProvider$getS3.call(mentionProvider)
486
485
  } : {}));
487
- if ((_mentionProvider$getS4 = mentionProvider.getShouldEnableInlineInvite) !== null && _mentionProvider$getS4 !== void 0 && _mentionProvider$getS4.call(mentionProvider) && fg('jira_invites_auto_tag_new_user_in_mentions_fg')) {
486
+ if ((_mentionProvider$getS4 = mentionProvider.getShouldEnableInlineInvite) !== null && _mentionProvider$getS4 !== void 0 && _mentionProvider$getS4.call(mentionProvider) && fg('inline_invite_from_mentions_kill_switch')) {
488
487
  // Get the email from query, using the same logic as InviteItemWithEmailDomain
489
488
  var emailDomain = mentionProvider.userEmailDomain;
490
489
  var email = query || '';
@@ -493,13 +492,23 @@ export var createTypeAheadConfig = function createTypeAheadConfig(_ref8) {
493
492
  email = "".concat(email.toLowerCase(), "@").concat(emailDomain);
494
493
  }
495
494
  // If query already includes @, use it as is
496
- if (email && mentionProvider.showInlineInviteRecaptcha) {
497
- mentionProvider.showInlineInviteRecaptcha(email);
498
- var _tr = state.tr;
499
- _tr.setMeta(mentionPlaceholderPluginKey, {
500
- action: MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER,
501
- placeholder: "@".concat(query)
502
- });
495
+ if (email && mentionProvider.showInlineInvitePopup) {
496
+ // eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
497
+ var pendingLocalId = uuid();
498
+ var pendingName = email.split('@')[0] || email;
499
+ var _tr = insert(createSingleMentionFragment({
500
+ mentionProvider: mentionProvider,
501
+ mentionInsertDisplayName: mentionInsertDisplayName,
502
+ tr: state.tr,
503
+ sanitizePrivateContent: sanitizePrivateContent
504
+ })({
505
+ name: pendingName,
506
+ id: pendingLocalId,
507
+ userType: 'DEFAULT',
508
+ localId: pendingLocalId,
509
+ accessLevel: 'CONTAINER'
510
+ }));
511
+ mentionProvider.showInlineInvitePopup(email, pendingLocalId);
503
512
  return _tr;
504
513
  }
505
514
  } else if (mentionProvider.onInviteItemClick) {
@@ -0,0 +1,11 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { MentionProvider } from '@atlaskit/mention/resource';
4
+ import type { MentionsPlugin } from '../mentionsPluginType';
5
+ interface Props {
6
+ api: ExtractInjectionAPI<MentionsPlugin> | undefined;
7
+ editorView: EditorView;
8
+ mentionProvider: Promise<MentionProvider> | undefined;
9
+ }
10
+ export declare const InlineInvitePopupContainer: ({ mentionProvider, api, editorView, }: Props) => JSX.Element | null;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-mentions",
3
- "version": "15.1.0",
3
+ "version": "15.2.0",
4
4
  "description": "Mentions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,7 +34,7 @@
34
34
  "@atlaskit/insm": "^1.2.0",
35
35
  "@atlaskit/link": "^5.0.0",
36
36
  "@atlaskit/lozenge": "^15.0.0",
37
- "@atlaskit/mention": "^27.12.0",
37
+ "@atlaskit/mention": "^27.13.0",
38
38
  "@atlaskit/platform-feature-experiments": "^0.3.0",
39
39
  "@atlaskit/platform-feature-flags": "^2.1.0",
40
40
  "@atlaskit/popper": "^9.0.0",
@@ -43,8 +43,8 @@
43
43
  "@atlaskit/profilecard": "^26.15.0",
44
44
  "@atlaskit/teams-app-config": "^2.2.0",
45
45
  "@atlaskit/theme": "^27.0.0",
46
- "@atlaskit/tmp-editor-statsig": "^141.1.0",
47
- "@atlaskit/tokens": "^16.3.0",
46
+ "@atlaskit/tmp-editor-statsig": "^142.0.0",
47
+ "@atlaskit/tokens": "^16.4.0",
48
48
  "@atlaskit/tooltip": "^24.0.0",
49
49
  "@atlaskit/user-picker": "^13.8.0",
50
50
  "@babel/runtime": "^7.0.0",
@@ -55,12 +55,15 @@
55
55
  "uuid": "^3.1.0"
56
56
  },
57
57
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^117.3.0",
58
+ "@atlaskit/editor-common": "^117.5.0",
59
59
  "react": "^18.2.0 || ^19.2.0",
60
60
  "react-dom": "^18.2.0 || ^19.2.0",
61
61
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
62
62
  },
63
63
  "devDependencies": {
64
+ "@atlaskit/button": "^25.0.0",
65
+ "@atlaskit/editor-core": "^222.1.0",
66
+ "@atlaskit/popup": "^6.0.0",
64
67
  "@testing-library/react": "^16.3.0",
65
68
  "react": "^19.2.0",
66
69
  "react-dom": "^19.2.0",
@@ -117,6 +120,9 @@
117
120
  "jira_invites_auto_tag_new_user_in_mentions_fg": {
118
121
  "type": "boolean"
119
122
  },
123
+ "inline_invite_from_mentions_kill_switch": {
124
+ "type": "boolean"
125
+ },
120
126
  "people-teams_migrate-user-profile-card": {
121
127
  "type": "boolean"
122
128
  },
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MENTION_PLACEHOLDER_ACTIONS = void 0;
7
- exports.createMentionPlaceholderPlugin = createMentionPlaceholderPlugin;
8
- exports.mentionPlaceholderPluginKey = void 0;
9
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
- var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _view = require("@atlaskit/editor-prosemirror/view");
12
- var mentionPlaceholderPluginKey = exports.mentionPlaceholderPluginKey = new _state.PluginKey('mentionPlaceholderPlugin');
13
- var MENTION_PLACEHOLDER_ACTIONS = exports.MENTION_PLACEHOLDER_ACTIONS = {
14
- SHOW_PLACEHOLDER: 'SHOW_PLACEHOLDER',
15
- HIDE_PLACEHOLDER: 'HIDE_PLACEHOLDER'
16
- };
17
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
18
- function createMentionPlaceholderPlugin() {
19
- return new _safePlugin.SafePlugin({
20
- key: mentionPlaceholderPluginKey,
21
- state: {
22
- init: function init() {
23
- return {};
24
- },
25
- apply: function apply(tr, pluginState) {
26
- var meta = tr.getMeta(mentionPlaceholderPluginKey);
27
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER) {
28
- return {
29
- placeholder: meta.placeholder
30
- };
31
- }
32
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER) {
33
- return {};
34
- }
35
- return pluginState;
36
- }
37
- },
38
- props: {
39
- decorations: function decorations(state) {
40
- var pluginState = mentionPlaceholderPluginKey.getState(state);
41
- if (pluginState !== null && pluginState !== void 0 && pluginState.placeholder) {
42
- var selection = state.selection;
43
- var span = document.createElement('span');
44
- span.textContent = pluginState.placeholder;
45
- span.style.setProperty('color', "var(--ds-text-accent-blue, #1558BC)");
46
- return _view.DecorationSet.create(state.doc, [_view.Decoration.widget(selection.from, span)]);
47
- }
48
- return null;
49
- }
50
- }
51
- });
52
- }
@@ -1,100 +0,0 @@
1
- /* InlineInviteRecaptchaContainer.tsx generated by @compiled/babel-plugin v2.0.0 */
2
- "use strict";
3
-
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.InlineInviteRecaptchaContainer = void 0;
10
- var _runtime = require("@compiled/react/runtime");
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
- var _react = _interopRequireWildcard(require("react"));
13
- var _mentionPlaceholder = require("../pm-plugins/mentionPlaceholder");
14
- var _analytics = require("../ui/type-ahead/analytics");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
16
- /**
17
- * Container that renders the recaptcha component from the mention provider and manages handleSuccess.
18
- * Does NOT pass email - the provider's component uses useInlineInviteRecaptcha hook internally
19
- * and wires showRecaptcha to the provider. When user clicks invite item, type-ahead calls
20
- * mentionProvider.showInlineInviteRecaptcha(email) which passes email to the component.
21
- */
22
- var InlineInviteRecaptchaContainer = exports.InlineInviteRecaptchaContainer = function InlineInviteRecaptchaContainer(_ref) {
23
- var _api$mention2, _api$core3;
24
- var mentionProvider = _ref.mentionProvider,
25
- api = _ref.api;
26
- var _useState = (0, _react.useState)(null),
27
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
28
- provider = _useState2[0],
29
- setProvider = _useState2[1];
30
- (0, _react.useEffect)(function () {
31
- if (!mentionProvider) {
32
- return;
33
- }
34
- var isMounted = true;
35
- mentionProvider.then(function (resolvedProvider) {
36
- if (!isMounted) {
37
- return;
38
- }
39
- setProvider(resolvedProvider);
40
- }).catch(function () {
41
- // Silently handle promise rejection
42
- });
43
- return function () {
44
- isMounted = false;
45
- setProvider(null);
46
- };
47
- }, [mentionProvider]);
48
- var handleSuccess = (0, _react.useCallback)(function (userId, email) {
49
- var _api$mention, _api$core;
50
- if (!(api !== null && api !== void 0 && (_api$mention = api.mention) !== null && _api$mention !== void 0 && (_api$mention = _api$mention.commands) !== null && _api$mention !== void 0 && _api$mention.insertMention) || !(api !== null && api !== void 0 && (_api$core = api.core) !== null && _api$core !== void 0 && (_api$core = _api$core.actions) !== null && _api$core !== void 0 && _api$core.execute)) {
51
- return;
52
- }
53
- var name = email.split('@')[0] || email;
54
- api.core.actions.execute(api.mention.commands.insertMention({
55
- id: userId,
56
- name: name,
57
- userType: 'DEFAULT',
58
- accessLevel: 'CONTAINER'
59
- }));
60
- api.core.actions.execute(function (_ref2) {
61
- var tr = _ref2.tr;
62
- tr.setMeta(_mentionPlaceholder.mentionPlaceholderPluginKey, {
63
- action: _mentionPlaceholder.MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER
64
- });
65
- return tr;
66
- });
67
- }, [api]);
68
- var handleClose = (0, _react.useCallback)(function () {
69
- var _api$core2;
70
- if (!(api !== null && api !== void 0 && (_api$core2 = api.core) !== null && _api$core2 !== void 0 && (_api$core2 = _api$core2.actions) !== null && _api$core2 !== void 0 && _api$core2.execute)) {
71
- return;
72
- }
73
- api.core.actions.execute(function (_ref3) {
74
- var tr = _ref3.tr;
75
- tr.setMeta(_mentionPlaceholder.mentionPlaceholderPluginKey, {
76
- action: _mentionPlaceholder.MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER
77
- });
78
- return tr;
79
- });
80
- }, [api]);
81
- var handleReady = (0, _react.useCallback)(function (showRecaptcha) {
82
- if (provider) {
83
- if (showRecaptcha) {
84
- provider.showInlineInviteRecaptcha = showRecaptcha;
85
- } else {
86
- delete provider.showInlineInviteRecaptcha;
87
- }
88
- }
89
- }, [provider]);
90
- if (!(provider !== null && provider !== void 0 && provider.InlineInviteRecaptcha) || !(api !== null && api !== void 0 && (_api$mention2 = api.mention) !== null && _api$mention2 !== void 0 && (_api$mention2 = _api$mention2.commands) !== null && _api$mention2 !== void 0 && _api$mention2.insertMention) || !(api !== null && api !== void 0 && (_api$core3 = api.core) !== null && _api$core3 !== void 0 && (_api$core3 = _api$core3.actions) !== null && _api$core3 !== void 0 && _api$core3.execute)) {
91
- return null;
92
- }
93
- var RecaptchaComponent = provider.InlineInviteRecaptcha;
94
- return /*#__PURE__*/_react.default.createElement(RecaptchaComponent, {
95
- analyticsSource: _analytics.MENTION_SOURCE,
96
- onSuccess: handleSuccess,
97
- onClose: handleClose,
98
- onReady: handleReady
99
- });
100
- };
@@ -1,44 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- export const mentionPlaceholderPluginKey = new PluginKey('mentionPlaceholderPlugin');
5
- export const MENTION_PLACEHOLDER_ACTIONS = {
6
- SHOW_PLACEHOLDER: 'SHOW_PLACEHOLDER',
7
- HIDE_PLACEHOLDER: 'HIDE_PLACEHOLDER'
8
- };
9
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
10
- export function createMentionPlaceholderPlugin() {
11
- return new SafePlugin({
12
- key: mentionPlaceholderPluginKey,
13
- state: {
14
- init: () => ({}),
15
- apply(tr, pluginState) {
16
- const meta = tr.getMeta(mentionPlaceholderPluginKey);
17
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER) {
18
- return {
19
- placeholder: meta.placeholder
20
- };
21
- }
22
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER) {
23
- return {};
24
- }
25
- return pluginState;
26
- }
27
- },
28
- props: {
29
- decorations: state => {
30
- const pluginState = mentionPlaceholderPluginKey.getState(state);
31
- if (pluginState !== null && pluginState !== void 0 && pluginState.placeholder) {
32
- const {
33
- selection
34
- } = state;
35
- const span = document.createElement('span');
36
- span.textContent = pluginState.placeholder;
37
- span.style.setProperty('color', "var(--ds-text-accent-blue, #1558BC)");
38
- return DecorationSet.create(state.doc, [Decoration.widget(selection.from, span)]);
39
- }
40
- return null;
41
- }
42
- }
43
- });
44
- }
@@ -1,90 +0,0 @@
1
- /* InlineInviteRecaptchaContainer.tsx generated by @compiled/babel-plugin v2.0.0 */
2
- import { ax, ix } from "@compiled/react/runtime";
3
- import React, { useCallback, useEffect, useState } from 'react';
4
- import { mentionPlaceholderPluginKey, MENTION_PLACEHOLDER_ACTIONS } from '../pm-plugins/mentionPlaceholder';
5
- import { MENTION_SOURCE } from '../ui/type-ahead/analytics';
6
- /**
7
- * Container that renders the recaptcha component from the mention provider and manages handleSuccess.
8
- * Does NOT pass email - the provider's component uses useInlineInviteRecaptcha hook internally
9
- * and wires showRecaptcha to the provider. When user clicks invite item, type-ahead calls
10
- * mentionProvider.showInlineInviteRecaptcha(email) which passes email to the component.
11
- */
12
- export const InlineInviteRecaptchaContainer = ({
13
- mentionProvider,
14
- api
15
- }) => {
16
- var _api$mention2, _api$mention2$command, _api$core3, _api$core3$actions;
17
- const [provider, setProvider] = useState(null);
18
- useEffect(() => {
19
- if (!mentionProvider) {
20
- return;
21
- }
22
- let isMounted = true;
23
- mentionProvider.then(resolvedProvider => {
24
- if (!isMounted) {
25
- return;
26
- }
27
- setProvider(resolvedProvider);
28
- }).catch(() => {
29
- // Silently handle promise rejection
30
- });
31
- return () => {
32
- isMounted = false;
33
- setProvider(null);
34
- };
35
- }, [mentionProvider]);
36
- const handleSuccess = useCallback((userId, email) => {
37
- var _api$mention, _api$mention$commands, _api$core, _api$core$actions;
38
- if (!(api !== null && api !== void 0 && (_api$mention = api.mention) !== null && _api$mention !== void 0 && (_api$mention$commands = _api$mention.commands) !== null && _api$mention$commands !== void 0 && _api$mention$commands.insertMention) || !(api !== null && api !== void 0 && (_api$core = api.core) !== null && _api$core !== void 0 && (_api$core$actions = _api$core.actions) !== null && _api$core$actions !== void 0 && _api$core$actions.execute)) {
39
- return;
40
- }
41
- const name = email.split('@')[0] || email;
42
- api.core.actions.execute(api.mention.commands.insertMention({
43
- id: userId,
44
- name,
45
- userType: 'DEFAULT',
46
- accessLevel: 'CONTAINER'
47
- }));
48
- api.core.actions.execute(({
49
- tr
50
- }) => {
51
- tr.setMeta(mentionPlaceholderPluginKey, {
52
- action: MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER
53
- });
54
- return tr;
55
- });
56
- }, [api]);
57
- const handleClose = useCallback(() => {
58
- var _api$core2, _api$core2$actions;
59
- if (!(api !== null && api !== void 0 && (_api$core2 = api.core) !== null && _api$core2 !== void 0 && (_api$core2$actions = _api$core2.actions) !== null && _api$core2$actions !== void 0 && _api$core2$actions.execute)) {
60
- return;
61
- }
62
- api.core.actions.execute(({
63
- tr
64
- }) => {
65
- tr.setMeta(mentionPlaceholderPluginKey, {
66
- action: MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER
67
- });
68
- return tr;
69
- });
70
- }, [api]);
71
- const handleReady = useCallback(showRecaptcha => {
72
- if (provider) {
73
- if (showRecaptcha) {
74
- provider.showInlineInviteRecaptcha = showRecaptcha;
75
- } else {
76
- delete provider.showInlineInviteRecaptcha;
77
- }
78
- }
79
- }, [provider]);
80
- if (!(provider !== null && provider !== void 0 && provider.InlineInviteRecaptcha) || !(api !== null && api !== void 0 && (_api$mention2 = api.mention) !== null && _api$mention2 !== void 0 && (_api$mention2$command = _api$mention2.commands) !== null && _api$mention2$command !== void 0 && _api$mention2$command.insertMention) || !(api !== null && api !== void 0 && (_api$core3 = api.core) !== null && _api$core3 !== void 0 && (_api$core3$actions = _api$core3.actions) !== null && _api$core3$actions !== void 0 && _api$core3$actions.execute)) {
81
- return null;
82
- }
83
- const RecaptchaComponent = provider.InlineInviteRecaptcha;
84
- return /*#__PURE__*/React.createElement(RecaptchaComponent, {
85
- analyticsSource: MENTION_SOURCE,
86
- onSuccess: handleSuccess,
87
- onClose: handleClose,
88
- onReady: handleReady
89
- });
90
- };
@@ -1,44 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- export var mentionPlaceholderPluginKey = new PluginKey('mentionPlaceholderPlugin');
5
- export var MENTION_PLACEHOLDER_ACTIONS = {
6
- SHOW_PLACEHOLDER: 'SHOW_PLACEHOLDER',
7
- HIDE_PLACEHOLDER: 'HIDE_PLACEHOLDER'
8
- };
9
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
10
- export function createMentionPlaceholderPlugin() {
11
- return new SafePlugin({
12
- key: mentionPlaceholderPluginKey,
13
- state: {
14
- init: function init() {
15
- return {};
16
- },
17
- apply: function apply(tr, pluginState) {
18
- var meta = tr.getMeta(mentionPlaceholderPluginKey);
19
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER) {
20
- return {
21
- placeholder: meta.placeholder
22
- };
23
- }
24
- if ((meta === null || meta === void 0 ? void 0 : meta.action) === MENTION_PLACEHOLDER_ACTIONS.HIDE_PLACEHOLDER) {
25
- return {};
26
- }
27
- return pluginState;
28
- }
29
- },
30
- props: {
31
- decorations: function decorations(state) {
32
- var pluginState = mentionPlaceholderPluginKey.getState(state);
33
- if (pluginState !== null && pluginState !== void 0 && pluginState.placeholder) {
34
- var selection = state.selection;
35
- var span = document.createElement('span');
36
- span.textContent = pluginState.placeholder;
37
- span.style.setProperty('color', "var(--ds-text-accent-blue, #1558BC)");
38
- return DecorationSet.create(state.doc, [Decoration.widget(selection.from, span)]);
39
- }
40
- return null;
41
- }
42
- }
43
- });
44
- }