@atlaskit/editor-plugin-mentions 14.0.0 → 14.1.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.
- package/CHANGELOG.md +11 -0
- package/dist/cjs/pm-plugins/main.js +252 -47
- package/dist/cjs/ui/type-ahead/index.js +21 -10
- package/dist/es2019/pm-plugins/main.js +242 -39
- package/dist/es2019/ui/type-ahead/index.js +18 -7
- package/dist/esm/pm-plugins/main.js +252 -47
- package/dist/esm/ui/type-ahead/index.js +21 -10
- package/dist/types/pm-plugins/main.d.ts +2 -0
- package/dist/types/types/index.d.ts +24 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-mentions
|
|
2
2
|
|
|
3
|
+
## 14.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`7c0b3e54a4d81`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7c0b3e54a4d81) -
|
|
8
|
+
Delay typed agent mention trigger until editor inactivity
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
|
|
3
14
|
## 14.0.0
|
|
4
15
|
|
|
5
16
|
### Major Changes
|
|
@@ -25,14 +25,17 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
25
25
|
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; }
|
|
26
26
|
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; }
|
|
27
27
|
var ACTIONS = exports.ACTIONS = {
|
|
28
|
+
COMMIT_PENDING_TYPED_AGENT_MENTION: 'COMMIT_PENDING_TYPED_AGENT_MENTION',
|
|
29
|
+
SET_PENDING_TYPED_AGENT_MENTION: 'SET_PENDING_TYPED_AGENT_MENTION',
|
|
28
30
|
SET_PROVIDER: 'SET_PROVIDER'
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
// 'AGENT' is not in the ADF schema UserType enum but is used at runtime.
|
|
32
34
|
var AGENT_USER_TYPES = new Set(['APP', 'AGENT']);
|
|
33
35
|
var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
|
|
36
|
+
var AGENT_MENTION_INACTIVITY_MS = 3000;
|
|
34
37
|
var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
|
|
35
|
-
var PACKAGE_VERSION = "
|
|
38
|
+
var PACKAGE_VERSION = "14.0.0";
|
|
36
39
|
var setProvider = function setProvider(provider) {
|
|
37
40
|
return function (state, dispatch) {
|
|
38
41
|
if (dispatch) {
|
|
@@ -46,11 +49,97 @@ var setProvider = function setProvider(provider) {
|
|
|
46
49
|
return true;
|
|
47
50
|
};
|
|
48
51
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns true when a transaction represents a local user document edit that
|
|
55
|
+
* should restart pending agent-mention inactivity tracking.
|
|
56
|
+
*
|
|
57
|
+
* Remote/collab updates, replace-document transactions, AI streaming transforms,
|
|
58
|
+
* selection-only movements, and metadata-only transactions are intentionally ignored.
|
|
59
|
+
*/
|
|
60
|
+
var isQualifyingLocalUserDocChange = function isQualifyingLocalUserDocChange(tr) {
|
|
61
|
+
var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
|
|
62
|
+
return tr.docChanged && !tr.getMeta('isRemote') && !tr.getMeta('replaceDocument') && !isAIStreaming;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Reads agent-mention details from a known document position without traversing
|
|
67
|
+
* the document. Callers pass a matcher so mapped positions are only accepted
|
|
68
|
+
* when they still point at the same pending/tracked mention.
|
|
69
|
+
*/
|
|
70
|
+
var getAgentMentionDetailsAtPos = function getAgentMentionDetailsAtPos(state, pos, matchesMention) {
|
|
71
|
+
var _parentNode$type$name;
|
|
72
|
+
if (pos < 0 || pos > state.doc.content.size) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
var node = state.doc.nodeAt(pos);
|
|
76
|
+
var mentionSchema = state.schema.nodes.mention;
|
|
77
|
+
if ((node === null || node === void 0 ? void 0 : node.type) !== mentionSchema || !AGENT_USER_TYPES.has(node.attrs.userType) || !matchesMention(node.attrs) || !node.attrs.id) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
var $mentionPos = state.doc.resolve(pos);
|
|
81
|
+
var parentNode = $mentionPos.node($mentionPos.depth);
|
|
82
|
+
return {
|
|
83
|
+
id: node.attrs.id,
|
|
84
|
+
context: parentNode.textContent.trim() || null,
|
|
85
|
+
nodeSize: node.nodeSize,
|
|
86
|
+
parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
|
|
87
|
+
pos: pos
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Finds an agent mention that survived a document change when the changed-range
|
|
93
|
+
* scan did not find one. Prefers the previously tracked mention ID when present;
|
|
94
|
+
* otherwise returns a surviving agent mention using the existing traversal order.
|
|
95
|
+
*/
|
|
96
|
+
var getSurvivingAgentMentionDetails = function getSurvivingAgentMentionDetails(state, preferredId) {
|
|
97
|
+
var mentionSchema = state.schema.nodes.mention;
|
|
98
|
+
var result = null;
|
|
99
|
+
state.doc.descendants(function (node, pos) {
|
|
100
|
+
var _result, _result2;
|
|
101
|
+
if (((_result = result) === null || _result === void 0 ? void 0 : _result.id) === preferredId) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (node.type !== mentionSchema || !AGENT_USER_TYPES.has(node.attrs.userType) || !node.attrs.id) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
result = getAgentMentionDetailsAtPos(state, pos, function (attrs) {
|
|
108
|
+
return attrs.id === node.attrs.id;
|
|
109
|
+
});
|
|
110
|
+
return ((_result2 = result) === null || _result2 === void 0 ? void 0 : _result2.id) !== preferredId;
|
|
111
|
+
});
|
|
112
|
+
return result;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Maps a pending typed agent mention through a document-changing transaction and
|
|
117
|
+
* returns the updated pending state. If the mapped position was deleted or no
|
|
118
|
+
* longer points at the same local mention, the pending mention is cleared.
|
|
119
|
+
*/
|
|
120
|
+
var getPendingTypedAgentMentionAfterDocChange = function getPendingTypedAgentMentionAfterDocChange(state, tr, pendingTypedAgentMention, _ref) {
|
|
121
|
+
var resetTimer = _ref.resetTimer;
|
|
122
|
+
var mappedPos = tr.mapping.mapResult(pendingTypedAgentMention.pos, 1);
|
|
123
|
+
var resetCount = resetTimer ? pendingTypedAgentMention.resetCount + 1 : pendingTypedAgentMention.resetCount;
|
|
124
|
+
if (mappedPos.deleted) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
var pendingMentionDetails = getAgentMentionDetailsAtPos(state, mappedPos.pos, function (attrs) {
|
|
128
|
+
return attrs.localId === pendingTypedAgentMention.localId;
|
|
129
|
+
});
|
|
130
|
+
return pendingMentionDetails ? {
|
|
131
|
+
id: pendingMentionDetails.id,
|
|
132
|
+
localId: pendingTypedAgentMention.localId,
|
|
133
|
+
nodeSize: pendingMentionDetails.nodeSize,
|
|
134
|
+
pos: pendingMentionDetails.pos,
|
|
135
|
+
resetCount: resetCount
|
|
136
|
+
} : null;
|
|
137
|
+
};
|
|
138
|
+
function createMentionPlugin(_ref2) {
|
|
139
|
+
var pmPluginFactoryParams = _ref2.pmPluginFactoryParams,
|
|
140
|
+
fireEvent = _ref2.fireEvent,
|
|
141
|
+
options = _ref2.options,
|
|
142
|
+
api = _ref2.api;
|
|
54
143
|
var mentionProvider;
|
|
55
144
|
var sendAnalytics = function sendAnalytics(event, actionSubject, action, attributes) {
|
|
56
145
|
if (event === _resource.SLI_EVENT_TYPE || event === _resource.SMART_EVENT_TYPE) {
|
|
@@ -76,36 +165,74 @@ function createMentionPlugin(_ref) {
|
|
|
76
165
|
};
|
|
77
166
|
},
|
|
78
167
|
apply: function apply(tr, pluginState, oldState, newState) {
|
|
79
|
-
var
|
|
168
|
+
var _ref3 = tr.getMeta(_key.mentionPluginKey) || {
|
|
80
169
|
action: null,
|
|
81
170
|
params: null
|
|
82
171
|
},
|
|
83
|
-
action =
|
|
84
|
-
params =
|
|
85
|
-
var
|
|
172
|
+
action = _ref3.action,
|
|
173
|
+
params = _ref3.params;
|
|
174
|
+
var hasPublicPluginStateChanged = false;
|
|
86
175
|
var newPluginState = pluginState;
|
|
176
|
+
var isAgentMentionsExperimentEnabled = (0, _experiments.editorExperiment)('platform_editor_agent_mentions', true);
|
|
87
177
|
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
88
178
|
if (tr.docChanged || tr.selectionSet && hasPositionChanged) {
|
|
89
179
|
newPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
90
180
|
canInsertMention: (0, _utils.canMentionBeCreatedInRange)(newState.selection.from, newState.selection.to)(newState)
|
|
91
181
|
});
|
|
92
|
-
|
|
182
|
+
hasPublicPluginStateChanged = true;
|
|
93
183
|
}
|
|
94
184
|
switch (action) {
|
|
185
|
+
case ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION:
|
|
186
|
+
{
|
|
187
|
+
var _newPluginState$lastA;
|
|
188
|
+
var pendingTypedAgentMention = newPluginState.pendingTypedAgentMention;
|
|
189
|
+
// Ignore stale timer callbacks. The localId and resetCount must still match the
|
|
190
|
+
// current pending mention so older timers cannot publish after later user edits.
|
|
191
|
+
if (!isAgentMentionsExperimentEnabled || !pendingTypedAgentMention || pendingTypedAgentMention.localId !== (params === null || params === void 0 ? void 0 : params.localId) || pendingTypedAgentMention.resetCount !== (params === null || params === void 0 ? void 0 : params.resetCount)) {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
var pendingMentionDetails = getAgentMentionDetailsAtPos(newState, pendingTypedAgentMention.pos, function (attrs) {
|
|
195
|
+
return attrs.localId === pendingTypedAgentMention.localId;
|
|
196
|
+
});
|
|
197
|
+
if (!pendingMentionDetails) {
|
|
198
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
199
|
+
pendingTypedAgentMention: null
|
|
200
|
+
});
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
204
|
+
pendingTypedAgentMention: null,
|
|
205
|
+
lastInsertedAgentMentionId: pendingMentionDetails.id,
|
|
206
|
+
lastInsertedAgentMentionContext: pendingMentionDetails.context,
|
|
207
|
+
lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
|
|
208
|
+
lastAgentMentionInsertionCount: ((_newPluginState$lastA = newPluginState.lastAgentMentionInsertionCount) !== null && _newPluginState$lastA !== void 0 ? _newPluginState$lastA : 0) + 1
|
|
209
|
+
});
|
|
210
|
+
hasPublicPluginStateChanged = true;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
95
213
|
case ACTIONS.SET_PROVIDER:
|
|
96
214
|
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
97
215
|
mentionProvider: params.provider
|
|
98
216
|
});
|
|
99
|
-
|
|
217
|
+
hasPublicPluginStateChanged = true;
|
|
100
218
|
break;
|
|
101
219
|
}
|
|
102
220
|
|
|
103
221
|
// When the agent mentions experiment is off, dispatch immediately (original behaviour).
|
|
104
222
|
// When it's on, defer dispatch to after the agent tracking block below so that
|
|
105
223
|
// agent-mention state changes are included in the notification.
|
|
106
|
-
if (
|
|
224
|
+
if (hasPublicPluginStateChanged && !isAgentMentionsExperimentEnabled) {
|
|
107
225
|
pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
|
|
108
226
|
}
|
|
227
|
+
if (isAgentMentionsExperimentEnabled && tr.docChanged && tr.getMeta('replaceDocument')) {
|
|
228
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
229
|
+
pendingTypedAgentMention: null,
|
|
230
|
+
lastInsertedAgentMentionId: null,
|
|
231
|
+
lastInsertedAgentMentionContext: null,
|
|
232
|
+
lastInsertedAgentMentionParentNodeType: null
|
|
233
|
+
});
|
|
234
|
+
hasPublicPluginStateChanged = true;
|
|
235
|
+
}
|
|
109
236
|
if (options !== null && options !== void 0 && options.handleMentionsChanged && tr.docChanged) {
|
|
110
237
|
var _insm$session, _insm$session2;
|
|
111
238
|
(_insm$session = _insm.insm.session) === null || _insm$session === void 0 || _insm$session.startFeature('mentionDeletionDetection');
|
|
@@ -166,7 +293,7 @@ function createMentionPlugin(_ref) {
|
|
|
166
293
|
(_insm$session2 = _insm.insm.session) === null || _insm$session2 === void 0 || _insm$session2.endFeature('mentionDeletionDetection');
|
|
167
294
|
}
|
|
168
295
|
var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
|
|
169
|
-
if (tr.docChanged && !tr.getMeta('replaceDocument') && !isAIStreaming &&
|
|
296
|
+
if (tr.docChanged && !tr.getMeta('replaceDocument') && !isAIStreaming && isAgentMentionsExperimentEnabled) {
|
|
170
297
|
var _mentionSchema = newState.schema.nodes.mention;
|
|
171
298
|
var newDocRanges = [];
|
|
172
299
|
var oldDocRanges = [];
|
|
@@ -212,14 +339,16 @@ function createMentionPlugin(_ref) {
|
|
|
212
339
|
oldDocRanges.push.apply(oldDocRanges, stepOldRanges);
|
|
213
340
|
}
|
|
214
341
|
});
|
|
215
|
-
|
|
216
|
-
|
|
342
|
+
var shouldResolveAgentMentionState = stepsTouchMentions || Boolean(newPluginState.lastInsertedAgentMentionId);
|
|
343
|
+
if (shouldResolveAgentMentionState) {
|
|
344
|
+
var _newPluginState$lastA2, _newPluginState$lastI, _newPluginState$lastI2, _newPluginState$lastI3;
|
|
217
345
|
var agentMentionId = null;
|
|
218
346
|
var agentMentionContext = null;
|
|
219
347
|
var agentMentionParentNodeType = null;
|
|
220
348
|
var newCount = 0;
|
|
221
349
|
var oldAgentMentionId = null;
|
|
222
350
|
var oldCount = 0;
|
|
351
|
+
var pendingTypedAgentMentionDetails = {};
|
|
223
352
|
if (stepsTouchMentions) {
|
|
224
353
|
var _iterator = _createForOfIteratorHelper(newDocRanges),
|
|
225
354
|
_step;
|
|
@@ -230,16 +359,26 @@ function createMentionPlugin(_ref) {
|
|
|
230
359
|
to = _step$value[1];
|
|
231
360
|
var clampedTo = Math.min(to, newState.doc.content.size);
|
|
232
361
|
if (from >= clampedTo) continue;
|
|
233
|
-
newState.doc.nodesBetween(from, clampedTo, function (node,
|
|
362
|
+
newState.doc.nodesBetween(from, clampedTo, function (node, pos) {
|
|
234
363
|
if (node.type !== _mentionSchema || !AGENT_USER_TYPES.has(node.attrs.userType)) {
|
|
235
364
|
return true;
|
|
236
365
|
}
|
|
237
366
|
newCount++;
|
|
367
|
+
if (pendingTypedAgentMentionDetails.current === undefined && action === ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && node.attrs.localId === (params === null || params === void 0 ? void 0 : params.localId)) {
|
|
368
|
+
var _getAgentMentionDetai;
|
|
369
|
+
pendingTypedAgentMentionDetails.current = (_getAgentMentionDetai = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
|
|
370
|
+
return attrs.localId === params.localId;
|
|
371
|
+
})) !== null && _getAgentMentionDetai !== void 0 ? _getAgentMentionDetai : undefined;
|
|
372
|
+
}
|
|
238
373
|
if (agentMentionId === null && node.attrs.id) {
|
|
239
|
-
var
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
374
|
+
var agentMentionDetails = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
|
|
375
|
+
return attrs.id === node.attrs.id;
|
|
376
|
+
});
|
|
377
|
+
if (agentMentionDetails) {
|
|
378
|
+
agentMentionId = agentMentionDetails.id;
|
|
379
|
+
agentMentionContext = agentMentionDetails.context;
|
|
380
|
+
agentMentionParentNodeType = agentMentionDetails.parentNodeType;
|
|
381
|
+
}
|
|
243
382
|
}
|
|
244
383
|
return true;
|
|
245
384
|
});
|
|
@@ -279,33 +418,43 @@ function createMentionPlugin(_ref) {
|
|
|
279
418
|
// When a deletion collapses the new-doc range to a zero-width point, or when
|
|
280
419
|
// the doc changed but no step covered the tracked mention, the new-doc scan
|
|
281
420
|
// above finds nothing. Check whether any agent mention survived in the document.
|
|
282
|
-
var
|
|
421
|
+
var resolvedFromFullDocFallback = false;
|
|
283
422
|
if (agentMentionId === null && newPluginState.lastInsertedAgentMentionId) {
|
|
284
|
-
var
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (node.type === _mentionSchema && AGENT_USER_TYPES.has(node.attrs.userType)) {
|
|
291
|
-
var _parent$type$name2;
|
|
292
|
-
// Prefer the previously tracked ID; otherwise keep the first found.
|
|
293
|
-
survivorId = node.attrs.id;
|
|
294
|
-
survivorParentNodeType = (_parent$type$name2 = parent === null || parent === void 0 ? void 0 : parent.type.name) !== null && _parent$type$name2 !== void 0 ? _parent$type$name2 : null;
|
|
295
|
-
survivorContext = (parent === null || parent === void 0 ? void 0 : parent.textContent.trim()) || null;
|
|
296
|
-
}
|
|
297
|
-
return survivorId !== prevId;
|
|
298
|
-
});
|
|
299
|
-
if (survivorId !== null) {
|
|
300
|
-
agentMentionId = survivorId;
|
|
301
|
-
agentMentionContext = survivorContext;
|
|
302
|
-
agentMentionParentNodeType = survivorParentNodeType;
|
|
303
|
-
resolvedFromSurvivor = true;
|
|
423
|
+
var survivorDetails = getSurvivingAgentMentionDetails(newState, newPluginState.lastInsertedAgentMentionId);
|
|
424
|
+
if (survivorDetails) {
|
|
425
|
+
agentMentionId = survivorDetails.id;
|
|
426
|
+
agentMentionContext = survivorDetails.context;
|
|
427
|
+
agentMentionParentNodeType = survivorDetails.parentNodeType;
|
|
428
|
+
resolvedFromFullDocFallback = true;
|
|
304
429
|
}
|
|
305
430
|
}
|
|
306
|
-
var isNewInsertion = agentMentionId !== null && !
|
|
307
|
-
var
|
|
308
|
-
|
|
431
|
+
var isNewInsertion = agentMentionId !== null && !resolvedFromFullDocFallback && (oldAgentMentionId !== agentMentionId || newCount > oldCount);
|
|
432
|
+
var isPendingTypedAgentMentionInsertion = isNewInsertion && action === ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && typeof (params === null || params === void 0 ? void 0 : params.localId) === 'string';
|
|
433
|
+
var newInsertionCount = isNewInsertion ? ((_newPluginState$lastA2 = newPluginState.lastAgentMentionInsertionCount) !== null && _newPluginState$lastA2 !== void 0 ? _newPluginState$lastA2 : 0) + 1 : undefined;
|
|
434
|
+
if (isPendingTypedAgentMentionInsertion && pendingTypedAgentMentionDetails.current) {
|
|
435
|
+
var pendingTypedAgentMentionLocalId = params === null || params === void 0 ? void 0 : params.localId;
|
|
436
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
437
|
+
pendingTypedAgentMention: {
|
|
438
|
+
id: pendingTypedAgentMentionDetails.current.id,
|
|
439
|
+
localId: pendingTypedAgentMentionLocalId,
|
|
440
|
+
nodeSize: pendingTypedAgentMentionDetails.current.nodeSize,
|
|
441
|
+
pos: pendingTypedAgentMentionDetails.current.pos,
|
|
442
|
+
resetCount: 1
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
} else if (isPendingTypedAgentMentionInsertion) {
|
|
446
|
+
// Fallback: if the localId-specific scan missed the typed mention,
|
|
447
|
+
// publish immediately so the insertion is not dropped.
|
|
448
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
449
|
+
pendingTypedAgentMention: null,
|
|
450
|
+
lastInsertedAgentMentionId: agentMentionId,
|
|
451
|
+
lastInsertedAgentMentionContext: agentMentionContext,
|
|
452
|
+
lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
|
|
453
|
+
}, newInsertionCount !== undefined ? {
|
|
454
|
+
lastAgentMentionInsertionCount: newInsertionCount
|
|
455
|
+
} : {});
|
|
456
|
+
hasPublicPluginStateChanged = true;
|
|
457
|
+
} else if (agentMentionId !== ((_newPluginState$lastI = newPluginState.lastInsertedAgentMentionId) !== null && _newPluginState$lastI !== void 0 ? _newPluginState$lastI : null) || agentMentionContext !== ((_newPluginState$lastI2 = newPluginState.lastInsertedAgentMentionContext) !== null && _newPluginState$lastI2 !== void 0 ? _newPluginState$lastI2 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI3 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI3 !== void 0 ? _newPluginState$lastI3 : null) || newInsertionCount !== undefined) {
|
|
309
458
|
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
310
459
|
lastInsertedAgentMentionId: agentMentionId,
|
|
311
460
|
lastInsertedAgentMentionContext: agentMentionContext,
|
|
@@ -313,11 +462,18 @@ function createMentionPlugin(_ref) {
|
|
|
313
462
|
}, newInsertionCount !== undefined ? {
|
|
314
463
|
lastAgentMentionInsertionCount: newInsertionCount
|
|
315
464
|
} : {});
|
|
316
|
-
|
|
465
|
+
hasPublicPluginStateChanged = true;
|
|
317
466
|
}
|
|
318
467
|
}
|
|
319
468
|
}
|
|
320
|
-
if (
|
|
469
|
+
if (isAgentMentionsExperimentEnabled && newPluginState.pendingTypedAgentMention && action !== ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && action !== ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION && tr.docChanged) {
|
|
470
|
+
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
471
|
+
pendingTypedAgentMention: getPendingTypedAgentMentionAfterDocChange(newState, tr, newPluginState.pendingTypedAgentMention, {
|
|
472
|
+
resetTimer: isQualifyingLocalUserDocChange(tr)
|
|
473
|
+
})
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
if (hasPublicPluginStateChanged && isAgentMentionsExperimentEnabled) {
|
|
321
477
|
pmPluginFactoryParams.dispatch(_key.mentionPluginKey, newPluginState);
|
|
322
478
|
}
|
|
323
479
|
return newPluginState;
|
|
@@ -335,6 +491,47 @@ function createMentionPlugin(_ref) {
|
|
|
335
491
|
}
|
|
336
492
|
},
|
|
337
493
|
view: function view(editorView) {
|
|
494
|
+
var isAgentMentionsEnabled = (0, _experiments.editorExperiment)('platform_editor_agent_mentions', true);
|
|
495
|
+
var pendingTypedAgentMentionTimer;
|
|
496
|
+
var pendingTypedAgentMentionTimerKey = null;
|
|
497
|
+
var clearPendingTypedAgentMentionTimer = function clearPendingTypedAgentMentionTimer() {
|
|
498
|
+
if (pendingTypedAgentMentionTimer) {
|
|
499
|
+
clearTimeout(pendingTypedAgentMentionTimer);
|
|
500
|
+
pendingTypedAgentMentionTimer = undefined;
|
|
501
|
+
}
|
|
502
|
+
pendingTypedAgentMentionTimerKey = null;
|
|
503
|
+
};
|
|
504
|
+
var schedulePendingTypedAgentMentionTimer = function schedulePendingTypedAgentMentionTimer(mentionPluginState) {
|
|
505
|
+
if (!isAgentMentionsEnabled) {
|
|
506
|
+
clearPendingTypedAgentMentionTimer();
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
var pendingTypedAgentMention = mentionPluginState === null || mentionPluginState === void 0 ? void 0 : mentionPluginState.pendingTypedAgentMention;
|
|
510
|
+
if (!pendingTypedAgentMention) {
|
|
511
|
+
clearPendingTypedAgentMentionTimer();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
var timerKey = "".concat(pendingTypedAgentMention.localId, ":").concat(pendingTypedAgentMention.resetCount);
|
|
515
|
+
if (timerKey === pendingTypedAgentMentionTimerKey) {
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
clearPendingTypedAgentMentionTimer();
|
|
519
|
+
pendingTypedAgentMentionTimerKey = timerKey;
|
|
520
|
+
pendingTypedAgentMentionTimer = setTimeout(function () {
|
|
521
|
+
var _mentionPluginKey$get;
|
|
522
|
+
var latestPendingTypedAgentMention = (_mentionPluginKey$get = _key.mentionPluginKey.getState(editorView.state)) === null || _mentionPluginKey$get === void 0 ? void 0 : _mentionPluginKey$get.pendingTypedAgentMention;
|
|
523
|
+
if (!latestPendingTypedAgentMention || latestPendingTypedAgentMention.localId !== pendingTypedAgentMention.localId || latestPendingTypedAgentMention.resetCount !== pendingTypedAgentMention.resetCount) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
editorView.dispatch(editorView.state.tr.setMeta(_key.mentionPluginKey, {
|
|
527
|
+
action: ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION,
|
|
528
|
+
params: {
|
|
529
|
+
localId: pendingTypedAgentMention.localId,
|
|
530
|
+
resetCount: pendingTypedAgentMention.resetCount
|
|
531
|
+
}
|
|
532
|
+
}));
|
|
533
|
+
}, AGENT_MENTION_INACTIVITY_MS);
|
|
534
|
+
};
|
|
338
535
|
var providerHandler = function providerHandler(name, providerPromise) {
|
|
339
536
|
switch (name) {
|
|
340
537
|
case 'mentionProvider':
|
|
@@ -380,7 +577,15 @@ function createMentionPlugin(_ref) {
|
|
|
380
577
|
pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
|
|
381
578
|
}
|
|
382
579
|
return {
|
|
580
|
+
update: function update(view, prevState) {
|
|
581
|
+
var mentionPluginState = _key.mentionPluginKey.getState(view.state);
|
|
582
|
+
if (mentionPluginState === _key.mentionPluginKey.getState(prevState)) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
schedulePendingTypedAgentMentionTimer(mentionPluginState);
|
|
586
|
+
},
|
|
383
587
|
destroy: function destroy() {
|
|
588
|
+
clearPendingTypedAgentMentionTimer();
|
|
384
589
|
if (pmPluginFactoryParams.providerFactory) {
|
|
385
590
|
pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
|
|
386
591
|
}
|
|
@@ -22,6 +22,8 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
|
22
22
|
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
23
23
|
var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
|
|
24
24
|
var _editorCommands = require("../../editor-commands");
|
|
25
|
+
var _key = require("../../pm-plugins/key");
|
|
26
|
+
var _main = require("../../pm-plugins/main");
|
|
25
27
|
var _mentionPlaceholder = require("../../pm-plugins/mentionPlaceholder");
|
|
26
28
|
var _utils2 = require("../../pm-plugins/utils");
|
|
27
29
|
var _InviteItem = _interopRequireWildcard(require("../InviteItem"));
|
|
@@ -380,10 +382,10 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
380
382
|
sessionId: sessionId
|
|
381
383
|
});
|
|
382
384
|
var isAgentMentionsExperimentEnabled = (0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false);
|
|
383
|
-
var
|
|
385
|
+
var isAgentMentionInsertion = isAgentMentionsExperimentEnabled && isAgentMention(item.mention);
|
|
384
386
|
// userType can be missing for provider-only agent mentions. Copy/paste cannot
|
|
385
387
|
// see appType, so persist APP only when there is no explicit userType.
|
|
386
|
-
var persistedUserType =
|
|
388
|
+
var persistedUserType = isAgentMentionInsertion && userType == null ? 'APP' : userType;
|
|
387
389
|
if (mentionProvider && !(0, _utils3.isInviteItem)(item.mention)) {
|
|
388
390
|
mentionProvider.recordMentionSelection(item.mention, mentionContext);
|
|
389
391
|
}
|
|
@@ -408,12 +410,12 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
408
410
|
// If query already includes @, use it as is
|
|
409
411
|
if (email && mentionProvider.showInlineInviteRecaptcha) {
|
|
410
412
|
mentionProvider.showInlineInviteRecaptcha(email);
|
|
411
|
-
var
|
|
412
|
-
|
|
413
|
+
var _tr = state.tr;
|
|
414
|
+
_tr.setMeta(_mentionPlaceholder.mentionPlaceholderPluginKey, {
|
|
413
415
|
action: _mentionPlaceholder.MENTION_PLACEHOLDER_ACTIONS.SHOW_PLACEHOLDER,
|
|
414
416
|
placeholder: "@".concat(query)
|
|
415
417
|
});
|
|
416
|
-
return
|
|
418
|
+
return _tr;
|
|
417
419
|
}
|
|
418
420
|
} else if (mentionProvider.onInviteItemClick) {
|
|
419
421
|
// Fallback to old behavior for backward compatibility
|
|
@@ -440,7 +442,7 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
440
442
|
localId: mentionLocalId,
|
|
441
443
|
method: 'typed',
|
|
442
444
|
type: 'added'
|
|
443
|
-
},
|
|
445
|
+
}, isAgentMentionInsertion ? {
|
|
444
446
|
shouldSuppressMentionNotification: true
|
|
445
447
|
} : {});
|
|
446
448
|
if (taskItemId) {
|
|
@@ -453,22 +455,22 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
453
455
|
}
|
|
454
456
|
fireEvent((0, _analytics.buildTypeAheadInsertedPayload)(pickerElapsedTime, stats.keyCount.arrowUp, stats.keyCount.arrowDown, sessionId, mode, item.mention, mentionLocalId, sourceListItem.map(function (x) {
|
|
455
457
|
return x.mention;
|
|
456
|
-
}), query, contextIdentifierProvider, taskListId, taskItemId,
|
|
458
|
+
}), query, contextIdentifierProvider, taskListId, taskItemId, isAgentMentionInsertion));
|
|
457
459
|
|
|
458
460
|
// eslint-disable-next-line @atlaskit/platform/prefer-crypto-random-uuid -- Use crypto.randomUUID instead
|
|
459
461
|
sessionId = (0, _uuid.default)();
|
|
460
462
|
if (mentionProvider && (0, _utils3.isTeamType)(userType)) {
|
|
461
463
|
return insert(buildNodesForTeamMention(schema, item.mention, mentionProvider, sanitizePrivateContent));
|
|
462
464
|
}
|
|
463
|
-
if (!
|
|
465
|
+
if (!isAgentMentionInsertion && isXProductUser && mentionProvider && mentionProvider.inviteXProductUser) {
|
|
464
466
|
mentionProvider.inviteXProductUser(id, name);
|
|
465
467
|
}
|
|
466
|
-
|
|
468
|
+
var tr = insert((0, _editorCommands.createSingleMentionFragment)({
|
|
467
469
|
mentionProvider: mentionProvider,
|
|
468
470
|
mentionInsertDisplayName: mentionInsertDisplayName,
|
|
469
471
|
tr: state.tr,
|
|
470
472
|
sanitizePrivateContent: sanitizePrivateContent,
|
|
471
|
-
suppressInviteXProductUser:
|
|
473
|
+
suppressInviteXProductUser: isAgentMentionInsertion
|
|
472
474
|
})({
|
|
473
475
|
name: name,
|
|
474
476
|
id: id,
|
|
@@ -478,6 +480,15 @@ var createTypeAheadConfig = exports.createTypeAheadConfig = function createTypeA
|
|
|
478
480
|
accessLevel: accessLevel,
|
|
479
481
|
isXProductUser: isXProductUser
|
|
480
482
|
}));
|
|
483
|
+
if (isAgentMentionInsertion) {
|
|
484
|
+
tr.setMeta(_key.mentionPluginKey, {
|
|
485
|
+
action: _main.ACTIONS.SET_PENDING_TYPED_AGENT_MENTION,
|
|
486
|
+
params: {
|
|
487
|
+
localId: mentionLocalId
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
return tr;
|
|
481
492
|
},
|
|
482
493
|
dismiss: function dismiss(_ref10) {
|
|
483
494
|
var editorState = _ref10.editorState,
|