@atlaskit/editor-plugin-mentions 15.2.0 → 16.0.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.
@@ -1,139 +0,0 @@
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
- };
@@ -1,11 +0,0 @@
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 {};