@atlaskit/editor-plugin-mentions 18.2.7 → 18.2.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 +14 -0
- package/dist/cjs/mentionsPlugin.js +2 -2
- package/dist/cjs/pm-plugins/main.js +10 -808
- package/dist/es2019/mentionsPlugin.js +2 -2
- package/dist/es2019/pm-plugins/main.js +3 -772
- package/dist/esm/mentionsPlugin.js +2 -2
- package/dist/esm/pm-plugins/main.js +11 -808
- package/dist/types/pm-plugins/main.d.ts +0 -15
- package/package.json +6 -6
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
4
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
6
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; }
|
|
7
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; }
|
|
8
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
9
5
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
10
|
-
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
11
6
|
import { insm } from '@atlaskit/insm';
|
|
12
|
-
import {
|
|
7
|
+
import { SLI_EVENT_TYPE, SMART_EVENT_TYPE } from '@atlaskit/mention/resource';
|
|
13
8
|
import { ComponentNames } from '@atlaskit/mention/types';
|
|
14
|
-
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
15
9
|
import { fg } from '@atlaskit/platform-feature-flags/fg';
|
|
16
|
-
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
|
|
17
10
|
import { MentionNodeView } from '../nodeviews/mentionNodeView';
|
|
18
11
|
import { MENTION_PROVIDER_REJECTED, MENTION_PROVIDER_UNDEFINED } from '../types';
|
|
19
|
-
import { getAgentMentionParentContext } from './agent-mention-context';
|
|
20
|
-
import { nextRunStateDecorations } from './agent-run-state';
|
|
21
12
|
import { mentionPluginKey } from './key';
|
|
22
13
|
import { canMentionBeCreatedInRange } from './utils';
|
|
23
14
|
export var ACTIONS = {
|
|
@@ -43,29 +34,8 @@ export var ACTIONS = {
|
|
|
43
34
|
*/
|
|
44
35
|
CLEAR_PENDING_PASTED_AGENT_MENTION: 'CLEAR_PENDING_PASTED_AGENT_MENTION'
|
|
45
36
|
};
|
|
46
|
-
|
|
47
|
-
// 'AGENT' is not in the ADF schema UserType enum but is used at runtime.
|
|
48
|
-
|
|
49
|
-
var AGENT_USER_TYPES = new Set(['APP', 'AGENT']);
|
|
50
|
-
var isAgentUserType = function isAgentUserType(userType) {
|
|
51
|
-
return typeof userType === 'string' && AGENT_USER_TYPES.has(userType);
|
|
52
|
-
};
|
|
53
|
-
var getAgentMentionName = function getAgentMentionName(text, fallbackName) {
|
|
54
|
-
var trimmedFallbackName = typeof fallbackName === 'string' ? fallbackName.trim() : '';
|
|
55
|
-
var normalizedFallbackName = (trimmedFallbackName.startsWith('@') ? trimmedFallbackName.slice(1).trim() : trimmedFallbackName) || null;
|
|
56
|
-
if (typeof text !== 'string') {
|
|
57
|
-
return normalizedFallbackName;
|
|
58
|
-
}
|
|
59
|
-
var trimmedText = text.trim();
|
|
60
|
-
var displayName = trimmedText.startsWith('@') ? trimmedText.slice(1).trim() : trimmedText;
|
|
61
|
-
var normalizedName = displayName || normalizedFallbackName;
|
|
62
|
-
return normalizedName;
|
|
63
|
-
};
|
|
64
|
-
var AI_STREAMING_TRANSFORMATION_META_KEY = 'isAIStreamingTransformation';
|
|
65
|
-
var AGENT_MENTION_INACTIVITY_MS = 3000;
|
|
66
|
-
var MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS = 20;
|
|
67
37
|
var PACKAGE_NAME = "@atlaskit/editor-plugin-mentions";
|
|
68
|
-
var PACKAGE_VERSION = "18.2.
|
|
38
|
+
var PACKAGE_VERSION = "18.2.8";
|
|
69
39
|
var setProvider = function setProvider(provider) {
|
|
70
40
|
return function (state, dispatch) {
|
|
71
41
|
if (dispatch) {
|
|
@@ -79,277 +49,11 @@ var setProvider = function setProvider(provider) {
|
|
|
79
49
|
return true;
|
|
80
50
|
};
|
|
81
51
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* Remote/collab updates, replace-document transactions, AI streaming transforms,
|
|
88
|
-
* selection-only movements, and metadata-only transactions are intentionally ignored.
|
|
89
|
-
*/
|
|
90
|
-
var isQualifyingLocalUserDocChange = function isQualifyingLocalUserDocChange(tr) {
|
|
91
|
-
var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
|
|
92
|
-
return tr.docChanged && !tr.getMeta('isRemote') && !tr.getMeta('replaceDocument') && !isAIStreaming;
|
|
93
|
-
};
|
|
94
|
-
var isLocalSelectionChange = function isLocalSelectionChange(tr, hasPositionChanged) {
|
|
95
|
-
var isAIStreaming = Boolean(tr.getMeta(AI_STREAMING_TRANSFORMATION_META_KEY));
|
|
96
|
-
|
|
97
|
-
// Pressing Enter can move selection through a doc split without setting tr.selectionSet
|
|
98
|
-
// or changing from/to numerically, so local doc changes are checked against the
|
|
99
|
-
// pending mention's current parent before publishing.
|
|
100
|
-
return (hasPositionChanged || tr.docChanged) && !tr.getMeta('isRemote') && !tr.getMeta('replaceDocument') && !isAIStreaming;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Reads agent-mention details from a known document position without traversing
|
|
105
|
-
* the document. Callers pass a matcher so mapped positions are only accepted
|
|
106
|
-
* when they still point at the same pending/tracked mention.
|
|
107
|
-
*/
|
|
108
|
-
var getAgentMentionDetailsAtPos = function getAgentMentionDetailsAtPos(state, pos, matchesMention, fallbackName) {
|
|
109
|
-
var _parentNode$type$name;
|
|
110
|
-
if (pos < 0 || pos > state.doc.content.size) {
|
|
111
|
-
return null;
|
|
112
|
-
}
|
|
113
|
-
var node = state.doc.nodeAt(pos);
|
|
114
|
-
var mentionSchema = state.schema.nodes.mention;
|
|
115
|
-
if ((node === null || node === void 0 ? void 0 : node.type) !== mentionSchema || !isAgentUserType(node.attrs.userType) || !matchesMention(node.attrs) || !node.attrs.id || !node.attrs.localId) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
var $mentionPos = state.doc.resolve(Math.min(pos + node.nodeSize, state.doc.content.size));
|
|
119
|
-
var parentNode = $mentionPos.node($mentionPos.depth);
|
|
120
|
-
var id = node.attrs.id;
|
|
121
|
-
var name = getAgentMentionName(node.attrs.text, fallbackName);
|
|
122
|
-
return {
|
|
123
|
-
id: id,
|
|
124
|
-
localId: node.attrs.localId,
|
|
125
|
-
context: getAgentMentionParentContext(parentNode, node.attrs.localId),
|
|
126
|
-
name: name,
|
|
127
|
-
prompt: parentNode.textContent.trim() || null,
|
|
128
|
-
nodeSize: node.nodeSize,
|
|
129
|
-
parentEnd: $mentionPos.end($mentionPos.depth),
|
|
130
|
-
parentNodeType: (_parentNode$type$name = parentNode.type.name) !== null && _parentNode$type$name !== void 0 ? _parentNode$type$name : null,
|
|
131
|
-
parentStart: $mentionPos.start($mentionPos.depth),
|
|
132
|
-
pos: pos
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Finds an agent mention that survived a document change when the changed-range
|
|
138
|
-
* scan did not find one. Uses the tracked localId as the mention instance identity
|
|
139
|
-
* so same-agent mentions elsewhere in the document cannot be selected as fallback.
|
|
140
|
-
*/
|
|
141
|
-
var getSurvivingAgentMentionDetails = function getSurvivingAgentMentionDetails(state, preferredLocalId, preferredName) {
|
|
142
|
-
var mentionSchema = state.schema.nodes.mention;
|
|
143
|
-
var result = null;
|
|
144
|
-
state.doc.descendants(function (node, pos) {
|
|
145
|
-
if (result) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
if (node.type !== mentionSchema || !isAgentUserType(node.attrs.userType) || node.attrs.localId !== preferredLocalId) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
result = getAgentMentionDetailsAtPos(state, pos, function (attrs) {
|
|
152
|
-
return attrs.localId === preferredLocalId;
|
|
153
|
-
}, preferredName);
|
|
154
|
-
return !result;
|
|
155
|
-
});
|
|
156
|
-
return result;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Maps a pending typed agent mention through a document-changing transaction and
|
|
161
|
-
* returns the updated pending state. If the mapped position was deleted or no
|
|
162
|
-
* longer points at the same local mention, the pending mention is cleared.
|
|
163
|
-
*/
|
|
164
|
-
var getPendingTypedAgentMentionAfterDocChange = function getPendingTypedAgentMentionAfterDocChange(state, tr, pendingTypedAgentMention, _ref) {
|
|
165
|
-
var resetTimer = _ref.resetTimer;
|
|
166
|
-
var mappedPos = tr.mapping.mapResult(pendingTypedAgentMention.pos, 1);
|
|
167
|
-
var resetCount = resetTimer ? pendingTypedAgentMention.resetCount + 1 : pendingTypedAgentMention.resetCount;
|
|
168
|
-
if (mappedPos.deleted) {
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
var pendingMentionDetails = getAgentMentionDetailsAtPos(state, mappedPos.pos, function (attrs) {
|
|
172
|
-
return attrs.localId === pendingTypedAgentMention.localId;
|
|
173
|
-
}, pendingTypedAgentMention.name);
|
|
174
|
-
return pendingMentionDetails ? {
|
|
175
|
-
id: pendingMentionDetails.id,
|
|
176
|
-
localId: pendingTypedAgentMention.localId,
|
|
177
|
-
name: pendingMentionDetails.name,
|
|
178
|
-
nodeSize: pendingMentionDetails.nodeSize,
|
|
179
|
-
parentNodeType: pendingMentionDetails.parentNodeType,
|
|
180
|
-
pos: pendingMentionDetails.pos,
|
|
181
|
-
resetCount: resetCount
|
|
182
|
-
} : null;
|
|
183
|
-
};
|
|
184
|
-
var hasPendingMentionMovedToNewParent = function hasPendingMentionMovedToNewParent(oldState, tr, previousPendingTypedAgentMention, pendingMentionDetails) {
|
|
185
|
-
if (!previousPendingTypedAgentMention) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
var previousMentionDetails = getAgentMentionDetailsAtPos(oldState, previousPendingTypedAgentMention.pos, function (attrs) {
|
|
189
|
-
return attrs.localId === previousPendingTypedAgentMention.localId;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
// Keep the previous parent boundary associated with the left side of an
|
|
193
|
-
// insertion at that boundary, so typing at the start of the parent does not
|
|
194
|
-
// look like the pending mention moved into a new parent.
|
|
195
|
-
var mappedPreviousParentStart = previousMentionDetails && tr.mapping.map(previousMentionDetails.parentStart, -1);
|
|
196
|
-
return Boolean(previousMentionDetails && mappedPreviousParentStart !== pendingMentionDetails.parentStart);
|
|
197
|
-
};
|
|
198
|
-
var isSelectionOutsideDirectParent = function isSelectionOutsideDirectParent(state, pendingMentionDetails) {
|
|
199
|
-
return state.selection.from < pendingMentionDetails.parentStart || state.selection.to > pendingMentionDetails.parentEnd;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Finalises a pending typed agent mention by copying its details into the
|
|
204
|
-
* public lastInserted* plugin state after the caller has already resolved the
|
|
205
|
-
* pending mention from the current document.
|
|
206
|
-
*/
|
|
207
|
-
var commitResolvedPendingTypedAgentMention = function commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails) {
|
|
208
|
-
var _pluginState$lastAgen;
|
|
209
|
-
return {
|
|
210
|
-
hasPublicPluginStateChanged: true,
|
|
211
|
-
pluginState: _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
212
|
-
pendingTypedAgentMention: null,
|
|
213
|
-
lastInsertedAgentMentionId: pendingMentionDetails.id,
|
|
214
|
-
lastInsertedAgentMentionLocalId: pendingMentionDetails.localId,
|
|
215
|
-
lastInsertedAgentMentionContext: pendingMentionDetails.context,
|
|
216
|
-
lastInsertedAgentMentionName: pendingMentionDetails.name,
|
|
217
|
-
lastInsertedAgentMentionPrompt: pendingMentionDetails.prompt,
|
|
218
|
-
lastInsertedAgentMentionParentNodeType: pendingMentionDetails.parentNodeType,
|
|
219
|
-
lastAgentMentionInsertionCount: ((_pluginState$lastAgen = pluginState.lastAgentMentionInsertionCount) !== null && _pluginState$lastAgen !== void 0 ? _pluginState$lastAgen : 0) + 1
|
|
220
|
-
})
|
|
221
|
-
};
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Resolves and finalises a pending typed agent mention. If the tracked mention
|
|
226
|
-
* no longer resolves, the stale pending state is cleared without dispatching a
|
|
227
|
-
* public update.
|
|
228
|
-
*/
|
|
229
|
-
var commitPendingTypedAgentMention = function commitPendingTypedAgentMention(state, pluginState, pendingTypedAgentMention) {
|
|
230
|
-
var pendingMentionDetails = getAgentMentionDetailsAtPos(state, pendingTypedAgentMention.pos, function (attrs) {
|
|
231
|
-
return attrs.localId === pendingTypedAgentMention.localId;
|
|
232
|
-
}, pendingTypedAgentMention.name);
|
|
233
|
-
if (!pendingMentionDetails) {
|
|
234
|
-
return {
|
|
235
|
-
hasPublicPluginStateChanged: false,
|
|
236
|
-
pluginState: _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
237
|
-
pendingTypedAgentMention: null
|
|
238
|
-
})
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
return commitResolvedPendingTypedAgentMention(pluginState, pendingMentionDetails);
|
|
242
|
-
};
|
|
243
|
-
var hasTrackedAgentMentionState = function hasTrackedAgentMentionState(pluginState) {
|
|
244
|
-
return Boolean(pluginState.pendingTypedAgentMention) || Boolean(pluginState.pendingPastedAgentMention) && fg('platform_editor_agent_mentions_drop_one_fixes') || pluginState.lastInsertedAgentMentionId != null || pluginState.lastInsertedAgentMentionLocalId != null || pluginState.lastInsertedAgentMentionContext != null || pluginState.lastInsertedAgentMentionName != null || pluginState.lastInsertedAgentMentionPrompt != null || pluginState.lastInsertedAgentMentionParentNodeType != null;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Clears agent mention state that points at a specific document snapshot.
|
|
249
|
-
* replaceDocument swaps content wholesale, so pending typed mentions and
|
|
250
|
-
* lastInserted* details from the previous document must be cleared together.
|
|
251
|
-
*/
|
|
252
|
-
var clearTrackedAgentMentionState = function clearTrackedAgentMentionState(pluginState) {
|
|
253
|
-
return _objectSpread(_objectSpread(_objectSpread({}, pluginState), {}, {
|
|
254
|
-
pendingTypedAgentMention: null
|
|
255
|
-
}, fg('platform_editor_agent_mentions_drop_one_fixes') ? {
|
|
256
|
-
pendingPastedAgentMention: null
|
|
257
|
-
} : {}), {}, {
|
|
258
|
-
lastInsertedAgentMentionId: null,
|
|
259
|
-
lastInsertedAgentMentionLocalId: null,
|
|
260
|
-
lastInsertedAgentMentionContext: null,
|
|
261
|
-
lastInsertedAgentMentionName: null,
|
|
262
|
-
lastInsertedAgentMentionPrompt: null,
|
|
263
|
-
lastInsertedAgentMentionParentNodeType: null
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Attempts to synchronously resolve an agent mention name from the mention
|
|
269
|
-
* provider's cache. Falls back to undefined if the provider doesn't support
|
|
270
|
-
* name resolution, the result is a Promise (async/cache miss), or the status
|
|
271
|
-
* is not OK.
|
|
272
|
-
*/
|
|
273
|
-
var resolveCachedAgentMentionName = function resolveCachedAgentMentionName(mentionProvider, params, id) {
|
|
274
|
-
if (params !== null && params !== void 0 && params.name || !isResolvingMentionProvider(mentionProvider)) {
|
|
275
|
-
var _params$name;
|
|
276
|
-
return (_params$name = params === null || params === void 0 ? void 0 : params.name) !== null && _params$name !== void 0 ? _params$name : undefined;
|
|
277
|
-
}
|
|
278
|
-
var result = mentionProvider.resolveMentionName(id);
|
|
279
|
-
if (!(result instanceof Promise) && result.status === MentionNameStatus.OK) {
|
|
280
|
-
return result.name || undefined;
|
|
281
|
-
}
|
|
282
|
-
return undefined;
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Resolves the name of a pasted agent mention via the mention provider and
|
|
287
|
-
* dispatches the appropriate action to update plugin state.
|
|
288
|
-
*
|
|
289
|
-
* Handles both async (Promise) and synchronous cache-hit results:
|
|
290
|
-
* - On OK resolution → dispatches RESOLVE_PASTED_AGENT_MENTION_NAME so the nudge
|
|
291
|
-
* shows the correct agent name.
|
|
292
|
-
* - On non-OK result → dispatches CLEAR_PENDING_PASTED_AGENT_MENTION to prevent
|
|
293
|
-
* an infinite retry loop on subsequent update() calls.
|
|
294
|
-
*
|
|
295
|
-
* Guards against duplicate in-flight requests via pendingResolveMentionIds.
|
|
296
|
-
*/
|
|
297
|
-
export var resolveAndDispatchPastedAgentMentionName = function resolveAndDispatchPastedAgentMentionName(agentId, mentionProvider, pendingResolveMentionIds, view) {
|
|
298
|
-
if (pendingResolveMentionIds.has(agentId)) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
pendingResolveMentionIds.add(agentId);
|
|
302
|
-
var result = mentionProvider.resolveMentionName(agentId);
|
|
303
|
-
if (result instanceof Promise) {
|
|
304
|
-
result.then(function (nameDetails) {
|
|
305
|
-
pendingResolveMentionIds.delete(agentId);
|
|
306
|
-
if (nameDetails.status === MentionNameStatus.OK && nameDetails.name) {
|
|
307
|
-
view.dispatch(view.state.tr.setMeta(mentionPluginKey, {
|
|
308
|
-
action: ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME,
|
|
309
|
-
params: {
|
|
310
|
-
id: agentId,
|
|
311
|
-
name: nameDetails.name
|
|
312
|
-
}
|
|
313
|
-
}));
|
|
314
|
-
} else {
|
|
315
|
-
// Non-OK status — clear pendingPastedAgentMention to prevent
|
|
316
|
-
// an infinite retry loop on subsequent update() calls.
|
|
317
|
-
view.dispatch(view.state.tr.setMeta(mentionPluginKey, {
|
|
318
|
-
action: ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION,
|
|
319
|
-
params: {
|
|
320
|
-
id: agentId
|
|
321
|
-
}
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
} else if (result.status === MentionNameStatus.OK && result.name) {
|
|
326
|
-
pendingResolveMentionIds.delete(agentId);
|
|
327
|
-
// Synchronous hit on a second update cycle (e.g. provider warmed up
|
|
328
|
-
// between the paste transaction and this view update).
|
|
329
|
-
view.dispatch(view.state.tr.setMeta(mentionPluginKey, {
|
|
330
|
-
action: ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME,
|
|
331
|
-
params: {
|
|
332
|
-
id: agentId,
|
|
333
|
-
name: result.name
|
|
334
|
-
}
|
|
335
|
-
}));
|
|
336
|
-
} else {
|
|
337
|
-
pendingResolveMentionIds.delete(agentId);
|
|
338
|
-
// Non-OK synchronous status — clear pendingPastedAgentMention to prevent
|
|
339
|
-
// an infinite retry loop on subsequent update() calls.
|
|
340
|
-
view.dispatch(view.state.tr.setMeta(mentionPluginKey, {
|
|
341
|
-
action: ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION,
|
|
342
|
-
params: {
|
|
343
|
-
id: agentId
|
|
344
|
-
}
|
|
345
|
-
}));
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
export function createMentionPlugin(_ref2) {
|
|
349
|
-
var pmPluginFactoryParams = _ref2.pmPluginFactoryParams,
|
|
350
|
-
fireEvent = _ref2.fireEvent,
|
|
351
|
-
options = _ref2.options,
|
|
352
|
-
api = _ref2.api;
|
|
52
|
+
export function createMentionPlugin(_ref) {
|
|
53
|
+
var pmPluginFactoryParams = _ref.pmPluginFactoryParams,
|
|
54
|
+
fireEvent = _ref.fireEvent,
|
|
55
|
+
options = _ref.options,
|
|
56
|
+
api = _ref.api;
|
|
353
57
|
var mentionProvider;
|
|
354
58
|
var sendAnalytics = function sendAnalytics(event, actionSubject, action, attributes) {
|
|
355
59
|
if (event === SLI_EVENT_TYPE || event === SMART_EVENT_TYPE) {
|
|
@@ -375,13 +79,12 @@ export function createMentionPlugin(_ref2) {
|
|
|
375
79
|
};
|
|
376
80
|
},
|
|
377
81
|
apply: function apply(tr, pluginState, oldState, newState) {
|
|
378
|
-
var
|
|
379
|
-
var _ref3 = tr.getMeta(mentionPluginKey) || {
|
|
82
|
+
var _ref2 = tr.getMeta(mentionPluginKey) || {
|
|
380
83
|
action: null,
|
|
381
84
|
params: null
|
|
382
85
|
},
|
|
383
|
-
action =
|
|
384
|
-
params =
|
|
86
|
+
action = _ref2.action,
|
|
87
|
+
params = _ref2.params;
|
|
385
88
|
var hasPublicPluginStateChanged = false;
|
|
386
89
|
var newPluginState = pluginState;
|
|
387
90
|
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
@@ -399,78 +102,7 @@ export function createMentionPlugin(_ref2) {
|
|
|
399
102
|
hasPublicPluginStateChanged = true;
|
|
400
103
|
break;
|
|
401
104
|
}
|
|
402
|
-
|
|
403
|
-
if (nextDecorations !== newPluginState.runStateDecorations) {
|
|
404
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
405
|
-
runStateDecorations: nextDecorations
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true)) {
|
|
409
|
-
switch (action) {
|
|
410
|
-
case ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION:
|
|
411
|
-
{
|
|
412
|
-
var pendingTypedAgentMention = newPluginState.pendingTypedAgentMention;
|
|
413
|
-
// Ignore stale timer callbacks. The localId and resetCount must still match the
|
|
414
|
-
// current pending mention so older timers cannot publish after later user edits.
|
|
415
|
-
if (!pendingTypedAgentMention || pendingTypedAgentMention.localId !== (params === null || params === void 0 ? void 0 : params.localId) || pendingTypedAgentMention.resetCount !== (params === null || params === void 0 ? void 0 : params.resetCount)) {
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
var commitResult = commitPendingTypedAgentMention(newState, newPluginState, pendingTypedAgentMention);
|
|
419
|
-
newPluginState = commitResult.pluginState;
|
|
420
|
-
hasPublicPluginStateChanged = hasPublicPluginStateChanged || commitResult.hasPublicPluginStateChanged;
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
423
|
-
case ACTIONS.DISCARD_PENDING_TYPED_AGENT_MENTION:
|
|
424
|
-
{
|
|
425
|
-
// Silently discard the pending typed agent mention without committing it.
|
|
426
|
-
var pendingTypedAgentMentionToDiscard = newPluginState.pendingTypedAgentMention;
|
|
427
|
-
if (!pendingTypedAgentMentionToDiscard || pendingTypedAgentMentionToDiscard.localId !== (params === null || params === void 0 ? void 0 : params.localId) || pendingTypedAgentMentionToDiscard.resetCount !== (params === null || params === void 0 ? void 0 : params.resetCount)) {
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
431
|
-
pendingTypedAgentMention: null
|
|
432
|
-
});
|
|
433
|
-
hasPublicPluginStateChanged = true;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
case ACTIONS.RESOLVE_PASTED_AGENT_MENTION_NAME:
|
|
437
|
-
{
|
|
438
|
-
var _newPluginState$pendi, _newPluginState$pendi2, _newPluginState$pendi3, _newPluginState$pendi4, _newPluginState$pendi5, _newPluginState$pendi6;
|
|
439
|
-
// Guard: only apply if there is a matching pending pasted mention (staleness check).
|
|
440
|
-
if (!(params !== null && params !== void 0 && params.id) || !(params !== null && params !== void 0 && params.name) || ((_newPluginState$pendi = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi === void 0 ? void 0 : _newPluginState$pendi.id) !== params.id || !fg('platform_editor_agent_mentions_drop_one_fixes')) {
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
444
|
-
pendingPastedAgentMention: null,
|
|
445
|
-
lastInsertedAgentMentionId: (_newPluginState$pendi2 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi2 === void 0 ? void 0 : _newPluginState$pendi2.id,
|
|
446
|
-
lastInsertedAgentMentionLocalId: (_newPluginState$pendi3 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi3 === void 0 ? void 0 : _newPluginState$pendi3.localId,
|
|
447
|
-
lastInsertedAgentMentionContext: (_newPluginState$pendi4 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi4 === void 0 ? void 0 : _newPluginState$pendi4.context,
|
|
448
|
-
lastInsertedAgentMentionName: params.name,
|
|
449
|
-
lastInsertedAgentMentionPrompt: (_newPluginState$pendi5 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi5 === void 0 ? void 0 : _newPluginState$pendi5.prompt,
|
|
450
|
-
lastInsertedAgentMentionParentNodeType: (_newPluginState$pendi6 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi6 === void 0 ? void 0 : _newPluginState$pendi6.parentNodeType
|
|
451
|
-
});
|
|
452
|
-
hasPublicPluginStateChanged = true;
|
|
453
|
-
break;
|
|
454
|
-
}
|
|
455
|
-
case ACTIONS.CLEAR_PENDING_PASTED_AGENT_MENTION:
|
|
456
|
-
{
|
|
457
|
-
var _newPluginState$pendi7;
|
|
458
|
-
if (!(params !== null && params !== void 0 && params.id) || ((_newPluginState$pendi7 = newPluginState.pendingPastedAgentMention) === null || _newPluginState$pendi7 === void 0 ? void 0 : _newPluginState$pendi7.id) !== params.id || !fg('platform_editor_agent_mentions_drop_one_fixes')) {
|
|
459
|
-
break;
|
|
460
|
-
}
|
|
461
|
-
// resolveMentionName() returned a non-OK status — clear the pending state.
|
|
462
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
463
|
-
pendingPastedAgentMention: null
|
|
464
|
-
});
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// When the agent mentions experiment is off, dispatch immediately (original behaviour).
|
|
471
|
-
// When it's on, defer dispatch to after the agent tracking block below so that
|
|
472
|
-
// agent-mention state changes are included in the notification.
|
|
473
|
-
if (hasPublicPluginStateChanged && (isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') || !editorExperiment('platform_editor_agent_mentions', true))) {
|
|
105
|
+
if (hasPublicPluginStateChanged) {
|
|
474
106
|
pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
|
|
475
107
|
}
|
|
476
108
|
if (options !== null && options !== void 0 && options.handleMentionsChanged && tr.docChanged) {
|
|
@@ -532,297 +164,6 @@ export function createMentionPlugin(_ref2) {
|
|
|
532
164
|
}
|
|
533
165
|
(_insm$session2 = insm.session) === null || _insm$session2 === void 0 || _insm$session2.endFeature('mentionDeletionDetection');
|
|
534
166
|
}
|
|
535
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true) && isQualifyingLocalUserDocChange(tr)) {
|
|
536
|
-
var _mentionSchema = newState.schema.nodes.mention;
|
|
537
|
-
var newDocRanges = [];
|
|
538
|
-
var oldDocRanges = [];
|
|
539
|
-
var stepsTouchMentions = false;
|
|
540
|
-
tr.steps.forEach(function (step) {
|
|
541
|
-
var found = false;
|
|
542
|
-
// Only merge a step's ranges if it actually touched an agent mention,
|
|
543
|
-
// so unrelated steps (e.g. mark-only changes) don't inflate the scan area.
|
|
544
|
-
var stepNewRanges = [];
|
|
545
|
-
var stepOldRanges = [];
|
|
546
|
-
step.getMap().forEach(function (oldFrom, oldTo, newFrom, newTo) {
|
|
547
|
-
stepOldRanges.push([oldFrom, oldTo]);
|
|
548
|
-
stepNewRanges.push([newFrom, newTo]);
|
|
549
|
-
if (!found) {
|
|
550
|
-
// Clamp positions: delete-only steps can produce newTo > doc.content.size.
|
|
551
|
-
var clampedNewFrom = Math.min(newFrom, newState.doc.content.size);
|
|
552
|
-
var clampedNewTo = Math.min(newTo, newState.doc.content.size);
|
|
553
|
-
if (clampedNewFrom < clampedNewTo) {
|
|
554
|
-
newState.doc.nodesBetween(clampedNewFrom, clampedNewTo, function (node) {
|
|
555
|
-
if (node.type === _mentionSchema && isAgentUserType(node.attrs.userType)) {
|
|
556
|
-
found = true;
|
|
557
|
-
}
|
|
558
|
-
return !found;
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
if (!found) {
|
|
562
|
-
var clampedOldFrom = Math.min(oldFrom, oldState.doc.content.size);
|
|
563
|
-
var clampedOldTo = Math.min(oldTo, oldState.doc.content.size);
|
|
564
|
-
if (clampedOldFrom < clampedOldTo) {
|
|
565
|
-
oldState.doc.nodesBetween(clampedOldFrom, clampedOldTo, function (node) {
|
|
566
|
-
if (node.type === _mentionSchema && AGENT_USER_TYPES.has(node.attrs.userType)) {
|
|
567
|
-
found = true;
|
|
568
|
-
}
|
|
569
|
-
return !found;
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
});
|
|
575
|
-
if (found) {
|
|
576
|
-
stepsTouchMentions = true;
|
|
577
|
-
newDocRanges.push.apply(newDocRanges, stepNewRanges);
|
|
578
|
-
oldDocRanges.push.apply(oldDocRanges, stepOldRanges);
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
var shouldResolveAgentMentionState = stepsTouchMentions || Boolean(newPluginState.lastInsertedAgentMentionLocalId);
|
|
582
|
-
if (shouldResolveAgentMentionState) {
|
|
583
|
-
var _newPluginState$lastI, _newPluginState$lastA, _newPluginState$lastI2, _newPluginState$lastI3, _newPluginState$lastI4, _newPluginState$lastI5, _newPluginState$lastI6;
|
|
584
|
-
var agentMentionId = null;
|
|
585
|
-
var agentMentionLocalId = null;
|
|
586
|
-
var agentMentionContext = null;
|
|
587
|
-
var agentMentionName = null;
|
|
588
|
-
var agentMentionPrompt = null;
|
|
589
|
-
var agentMentionParentNodeType = null;
|
|
590
|
-
var existingAgentMentionLocalIdsInChangedRanges = new Set();
|
|
591
|
-
var pendingTypedAgentMentionDetails = null;
|
|
592
|
-
if (stepsTouchMentions) {
|
|
593
|
-
var _iterator = _createForOfIteratorHelper(newDocRanges),
|
|
594
|
-
_step;
|
|
595
|
-
try {
|
|
596
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
597
|
-
var _step$value = _slicedToArray(_step.value, 2),
|
|
598
|
-
from = _step$value[0],
|
|
599
|
-
to = _step$value[1];
|
|
600
|
-
var clampedTo = Math.min(to, newState.doc.content.size);
|
|
601
|
-
if (from >= clampedTo) {
|
|
602
|
-
continue;
|
|
603
|
-
}
|
|
604
|
-
newState.doc.nodesBetween(from, clampedTo, function (node, pos) {
|
|
605
|
-
if (node.type !== _mentionSchema || !isAgentUserType(node.attrs.userType)) {
|
|
606
|
-
return true;
|
|
607
|
-
}
|
|
608
|
-
if (pendingTypedAgentMentionDetails === null && action === ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && node.attrs.localId === (params === null || params === void 0 ? void 0 : params.localId)) {
|
|
609
|
-
pendingTypedAgentMentionDetails = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
|
|
610
|
-
return attrs.localId === params.localId;
|
|
611
|
-
}, params.name);
|
|
612
|
-
}
|
|
613
|
-
if (agentMentionLocalId === null && node.attrs.localId) {
|
|
614
|
-
// Try to recover the name synchronously from the mention provider's
|
|
615
|
-
// name cache (populated by cacheMentionName on typed insert).
|
|
616
|
-
var cachedName = fg('platform_editor_agent_mentions_drop_one_fixes') ? resolveCachedAgentMentionName(mentionProvider, params, node.attrs.id) : params === null || params === void 0 ? void 0 : params.name;
|
|
617
|
-
var agentMentionDetails = getAgentMentionDetailsAtPos(newState, pos, function (attrs) {
|
|
618
|
-
return attrs.localId === node.attrs.localId;
|
|
619
|
-
}, cachedName);
|
|
620
|
-
if (agentMentionDetails) {
|
|
621
|
-
agentMentionId = agentMentionDetails.id;
|
|
622
|
-
agentMentionLocalId = agentMentionDetails.localId;
|
|
623
|
-
agentMentionContext = agentMentionDetails.context;
|
|
624
|
-
agentMentionName = agentMentionDetails.name;
|
|
625
|
-
agentMentionPrompt = agentMentionDetails.prompt;
|
|
626
|
-
agentMentionParentNodeType = agentMentionDetails.parentNodeType;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return true;
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
} catch (err) {
|
|
633
|
-
_iterator.e(err);
|
|
634
|
-
} finally {
|
|
635
|
-
_iterator.f();
|
|
636
|
-
}
|
|
637
|
-
var _iterator2 = _createForOfIteratorHelper(oldDocRanges),
|
|
638
|
-
_step2;
|
|
639
|
-
try {
|
|
640
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
641
|
-
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
642
|
-
_from = _step2$value[0],
|
|
643
|
-
_to = _step2$value[1];
|
|
644
|
-
var clampedOldTo = Math.min(_to, oldState.doc.content.size);
|
|
645
|
-
if (_from >= clampedOldTo) {
|
|
646
|
-
continue;
|
|
647
|
-
}
|
|
648
|
-
oldState.doc.nodesBetween(_from, clampedOldTo, function (node) {
|
|
649
|
-
if (node.type !== _mentionSchema || !isAgentUserType(node.attrs.userType)) {
|
|
650
|
-
return true;
|
|
651
|
-
}
|
|
652
|
-
if (node.attrs.localId) {
|
|
653
|
-
existingAgentMentionLocalIdsInChangedRanges.add(node.attrs.localId);
|
|
654
|
-
}
|
|
655
|
-
return true;
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
} catch (err) {
|
|
659
|
-
_iterator2.e(err);
|
|
660
|
-
} finally {
|
|
661
|
-
_iterator2.f();
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
// When a deletion collapses the new-doc range to a zero-width point, or when
|
|
666
|
-
// the doc changed but no step covered the tracked mention, the new-doc scan
|
|
667
|
-
// above finds nothing. Check whether any agent mention survived in the document.
|
|
668
|
-
var resolvedFromFullDocFallback = false;
|
|
669
|
-
if (agentMentionId === null && newPluginState.lastInsertedAgentMentionLocalId) {
|
|
670
|
-
var survivorDetails = getSurvivingAgentMentionDetails(newState, newPluginState.lastInsertedAgentMentionLocalId, newPluginState.lastInsertedAgentMentionName);
|
|
671
|
-
if (survivorDetails) {
|
|
672
|
-
agentMentionId = survivorDetails.id;
|
|
673
|
-
agentMentionLocalId = survivorDetails.localId;
|
|
674
|
-
agentMentionContext = survivorDetails.context;
|
|
675
|
-
agentMentionName = survivorDetails.name;
|
|
676
|
-
agentMentionPrompt = survivorDetails.prompt;
|
|
677
|
-
agentMentionParentNodeType = survivorDetails.parentNodeType;
|
|
678
|
-
resolvedFromFullDocFallback = true;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
var trackedAgentMentionLocalId = (_newPluginState$lastI = newPluginState.lastInsertedAgentMentionLocalId) !== null && _newPluginState$lastI !== void 0 ? _newPluginState$lastI : null;
|
|
682
|
-
var changedRangeMentionIsNew = agentMentionLocalId !== null && !existingAgentMentionLocalIdsInChangedRanges.has(agentMentionLocalId);
|
|
683
|
-
if (agentMentionLocalId !== null && !changedRangeMentionIsNew && agentMentionLocalId !== trackedAgentMentionLocalId) {
|
|
684
|
-
var _survivorDetails = trackedAgentMentionLocalId ? getSurvivingAgentMentionDetails(newState, trackedAgentMentionLocalId, newPluginState.lastInsertedAgentMentionName) : null;
|
|
685
|
-
if (_survivorDetails) {
|
|
686
|
-
agentMentionId = _survivorDetails.id;
|
|
687
|
-
agentMentionLocalId = _survivorDetails.localId;
|
|
688
|
-
agentMentionContext = _survivorDetails.context;
|
|
689
|
-
agentMentionName = _survivorDetails.name;
|
|
690
|
-
agentMentionParentNodeType = _survivorDetails.parentNodeType;
|
|
691
|
-
resolvedFromFullDocFallback = true;
|
|
692
|
-
} else {
|
|
693
|
-
agentMentionId = null;
|
|
694
|
-
agentMentionLocalId = null;
|
|
695
|
-
agentMentionContext = null;
|
|
696
|
-
agentMentionName = null;
|
|
697
|
-
agentMentionParentNodeType = null;
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
var isNewInsertion = agentMentionId !== null && !resolvedFromFullDocFallback && changedRangeMentionIsNew;
|
|
701
|
-
var isPendingTypedAgentMentionInsertion = isNewInsertion && action === ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && typeof (params === null || params === void 0 ? void 0 : params.localId) === 'string';
|
|
702
|
-
var newInsertionCount = isNewInsertion ? ((_newPluginState$lastA = newPluginState.lastAgentMentionInsertionCount) !== null && _newPluginState$lastA !== void 0 ? _newPluginState$lastA : 0) + 1 : undefined;
|
|
703
|
-
var pendingTypedAgentMentionDetailsForState = pendingTypedAgentMentionDetails;
|
|
704
|
-
if (isPendingTypedAgentMentionInsertion && pendingTypedAgentMentionDetailsForState) {
|
|
705
|
-
var pendingTypedAgentMentionLocalId = params === null || params === void 0 ? void 0 : params.localId;
|
|
706
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
707
|
-
pendingTypedAgentMention: {
|
|
708
|
-
id: pendingTypedAgentMentionDetailsForState.id,
|
|
709
|
-
localId: pendingTypedAgentMentionLocalId,
|
|
710
|
-
name: pendingTypedAgentMentionDetailsForState.name,
|
|
711
|
-
nodeSize: pendingTypedAgentMentionDetailsForState.nodeSize,
|
|
712
|
-
parentNodeType: pendingTypedAgentMentionDetailsForState.parentNodeType,
|
|
713
|
-
pos: pendingTypedAgentMentionDetailsForState.pos,
|
|
714
|
-
resetCount: 1
|
|
715
|
-
}
|
|
716
|
-
});
|
|
717
|
-
} else if (isPendingTypedAgentMentionInsertion) {
|
|
718
|
-
// Fallback: if the localId-specific scan missed the typed mention,
|
|
719
|
-
// publish immediately so the insertion is not dropped.
|
|
720
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
721
|
-
pendingTypedAgentMention: null,
|
|
722
|
-
lastInsertedAgentMentionId: agentMentionId,
|
|
723
|
-
lastInsertedAgentMentionLocalId: agentMentionLocalId,
|
|
724
|
-
lastInsertedAgentMentionContext: agentMentionContext,
|
|
725
|
-
lastInsertedAgentMentionName: agentMentionName,
|
|
726
|
-
lastInsertedAgentMentionPrompt: agentMentionPrompt,
|
|
727
|
-
lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
|
|
728
|
-
}, newInsertionCount !== undefined ? {
|
|
729
|
-
lastAgentMentionInsertionCount: newInsertionCount
|
|
730
|
-
} : {});
|
|
731
|
-
hasPublicPluginStateChanged = true;
|
|
732
|
-
} else if (agentMentionId !== ((_newPluginState$lastI2 = newPluginState.lastInsertedAgentMentionId) !== null && _newPluginState$lastI2 !== void 0 ? _newPluginState$lastI2 : null) || agentMentionLocalId !== ((_newPluginState$lastI3 = newPluginState.lastInsertedAgentMentionLocalId) !== null && _newPluginState$lastI3 !== void 0 ? _newPluginState$lastI3 : null) || agentMentionName !== ((_newPluginState$lastI4 = newPluginState.lastInsertedAgentMentionName) !== null && _newPluginState$lastI4 !== void 0 ? _newPluginState$lastI4 : null) || agentMentionPrompt !== ((_newPluginState$lastI5 = newPluginState.lastInsertedAgentMentionPrompt) !== null && _newPluginState$lastI5 !== void 0 ? _newPluginState$lastI5 : null) || agentMentionParentNodeType !== ((_newPluginState$lastI6 = newPluginState.lastInsertedAgentMentionParentNodeType) !== null && _newPluginState$lastI6 !== void 0 ? _newPluginState$lastI6 : null) || newInsertionCount !== undefined) {
|
|
733
|
-
var _options$getIsRovoPan;
|
|
734
|
-
// Suppress the nudge for pasted/non-typed agent mentions when Rovo is already
|
|
735
|
-
// open.
|
|
736
|
-
// Task items are exempt only while
|
|
737
|
-
// platform_editor_agent_mentions_no_task_autofire is off (they auto-fire
|
|
738
|
-
// instead). With it on they are suppressed like every other block.
|
|
739
|
-
var isTaskItemMentionForPaste = agentMentionParentNodeType === 'taskItem' && !fg('platform_editor_agent_mentions_no_task_autofire');
|
|
740
|
-
if (!isTaskItemMentionForPaste && isNewInsertion && options !== null && options !== void 0 && (_options$getIsRovoPan = options.getIsRovoPanelOpen) !== null && _options$getIsRovoPan !== void 0 && _options$getIsRovoPan.call(options)) {
|
|
741
|
-
// Rovo is already open — skip setting lastInsertedAgentMention* so the
|
|
742
|
-
// downstream nudge listener never fires.
|
|
743
|
-
} else if (agentMentionName === null && agentMentionId !== null && isResolvingMentionProvider(newPluginState.mentionProvider) && fg('platform_editor_agent_mentions_drop_one_fixes')) {
|
|
744
|
-
// Store details in pendingPastedAgentMention (private, not broadcast), preventing a double-nudge.
|
|
745
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
746
|
-
pendingPastedAgentMention: {
|
|
747
|
-
id: agentMentionId,
|
|
748
|
-
localId: agentMentionLocalId,
|
|
749
|
-
context: agentMentionContext,
|
|
750
|
-
prompt: agentMentionPrompt,
|
|
751
|
-
parentNodeType: agentMentionParentNodeType
|
|
752
|
-
}
|
|
753
|
-
}, newInsertionCount !== undefined ? {
|
|
754
|
-
lastAgentMentionInsertionCount: newInsertionCount
|
|
755
|
-
} : {});
|
|
756
|
-
// the nudge does not fire until the name is resolved.
|
|
757
|
-
} else {
|
|
758
|
-
// Not suppressed — update state so the nudge fires normally.
|
|
759
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
760
|
-
lastInsertedAgentMentionId: agentMentionId,
|
|
761
|
-
lastInsertedAgentMentionLocalId: agentMentionLocalId,
|
|
762
|
-
lastInsertedAgentMentionContext: agentMentionContext,
|
|
763
|
-
lastInsertedAgentMentionName: agentMentionName,
|
|
764
|
-
lastInsertedAgentMentionPrompt: agentMentionPrompt,
|
|
765
|
-
lastInsertedAgentMentionParentNodeType: agentMentionParentNodeType
|
|
766
|
-
}, newInsertionCount !== undefined ? {
|
|
767
|
-
lastAgentMentionInsertionCount: newInsertionCount
|
|
768
|
-
} : {});
|
|
769
|
-
hasPublicPluginStateChanged = true;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true) && tr.docChanged && tr.getMeta('replaceDocument') && hasTrackedAgentMentionState(newPluginState)) {
|
|
775
|
-
newPluginState = clearTrackedAgentMentionState(newPluginState);
|
|
776
|
-
hasPublicPluginStateChanged = true;
|
|
777
|
-
}
|
|
778
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true) && newPluginState.pendingTypedAgentMention && action !== ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && action !== ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION && tr.docChanged) {
|
|
779
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
780
|
-
pendingTypedAgentMention: getPendingTypedAgentMentionAfterDocChange(newState, tr, newPluginState.pendingTypedAgentMention, {
|
|
781
|
-
resetTimer: isQualifyingLocalUserDocChange(tr)
|
|
782
|
-
})
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true)) {
|
|
786
|
-
// Typed agent mentions stay pending while the user is still editing around them,
|
|
787
|
-
// but leaving the mention's direct parent means they have moved on from that
|
|
788
|
-
// paragraph/block. Publish immediately in that case instead of waiting for the
|
|
789
|
-
// inactivity timer.
|
|
790
|
-
var shouldCheckPendingTypedAgentMentionParent = isLocalSelectionChange(tr, hasPositionChanged);
|
|
791
|
-
if (newPluginState.pendingTypedAgentMention && action !== ACTIONS.SET_PENDING_TYPED_AGENT_MENTION && action !== ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION && shouldCheckPendingTypedAgentMentionParent) {
|
|
792
|
-
var _pendingTypedAgentMention = newPluginState.pendingTypedAgentMention;
|
|
793
|
-
var pendingMentionDetails = getAgentMentionDetailsAtPos(newState, _pendingTypedAgentMention.pos, function (attrs) {
|
|
794
|
-
return attrs.localId === _pendingTypedAgentMention.localId;
|
|
795
|
-
}, _pendingTypedAgentMention.name);
|
|
796
|
-
if (!pendingMentionDetails) {
|
|
797
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
798
|
-
pendingTypedAgentMention: null
|
|
799
|
-
});
|
|
800
|
-
} else if (hasPendingMentionMovedToNewParent(oldState, tr, pluginState.pendingTypedAgentMention, pendingMentionDetails) || isSelectionOutsideDirectParent(newState, pendingMentionDetails)) {
|
|
801
|
-
var _options$getIsRovoPan2;
|
|
802
|
-
// Suppress the nudge when Rovo chat is already open, mirroring the same
|
|
803
|
-
// guard used in the inactivity-timer path. Task-item mentions are
|
|
804
|
-
// exempt only while platform_editor_agent_mentions_no_task_autofire is off
|
|
805
|
-
// (they auto-fire the mini modal and never show a nudge). With it on they
|
|
806
|
-
// are suppressed like any block.
|
|
807
|
-
var isTaskItemMention = pendingMentionDetails.parentNodeType === 'taskItem' && !fg('platform_editor_agent_mentions_no_task_autofire');
|
|
808
|
-
if (!isTaskItemMention && options !== null && options !== void 0 && (_options$getIsRovoPan2 = options.getIsRovoPanelOpen) !== null && _options$getIsRovoPan2 !== void 0 && _options$getIsRovoPan2.call(options)) {
|
|
809
|
-
// Discard without committing so lastInsertedAgentMention* fields are
|
|
810
|
-
// never set and the downstream nudge listener never fires.
|
|
811
|
-
newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
|
|
812
|
-
pendingTypedAgentMention: null
|
|
813
|
-
});
|
|
814
|
-
hasPublicPluginStateChanged = true;
|
|
815
|
-
} else {
|
|
816
|
-
var _commitResult = commitResolvedPendingTypedAgentMention(newPluginState, pendingMentionDetails);
|
|
817
|
-
newPluginState = _commitResult.pluginState;
|
|
818
|
-
hasPublicPluginStateChanged = hasPublicPluginStateChanged || _commitResult.hasPublicPluginStateChanged;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (hasPublicPluginStateChanged && !isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') && editorExperiment('platform_editor_agent_mentions', true)) {
|
|
824
|
-
pmPluginFactoryParams.dispatch(mentionPluginKey, newPluginState);
|
|
825
|
-
}
|
|
826
167
|
return newPluginState;
|
|
827
168
|
}
|
|
828
169
|
},
|
|
@@ -836,129 +177,9 @@ export function createMentionPlugin(_ref2) {
|
|
|
836
177
|
portalProviderAPI: pmPluginFactoryParams.portalProviderAPI
|
|
837
178
|
});
|
|
838
179
|
}
|
|
839
|
-
},
|
|
840
|
-
// Duplicated in platform/packages/editor/editor-plugin-mentions/src/pm-plugins/agent.ts
|
|
841
|
-
// Can remove once platform_editor_agent_mentions_separate_pm_plugin has been cleaned up
|
|
842
|
-
decorations: function decorations(state) {
|
|
843
|
-
var _mentionPluginKey$get;
|
|
844
|
-
var runStateDecorations = (_mentionPluginKey$get = mentionPluginKey.getState(state)) === null || _mentionPluginKey$get === void 0 ? void 0 : _mentionPluginKey$get.runStateDecorations;
|
|
845
|
-
if (!runStateDecorations || runStateDecorations === DecorationSet.empty) {
|
|
846
|
-
return undefined;
|
|
847
|
-
}
|
|
848
|
-
if (isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') || !editorExperiment('platform_editor_agent_mentions', true) || !isExperimentEnabled('platform_editor_agent_mention_state_anim')) {
|
|
849
|
-
return undefined;
|
|
850
|
-
}
|
|
851
|
-
return runStateDecorations;
|
|
852
180
|
}
|
|
853
181
|
},
|
|
854
182
|
view: function view(editorView) {
|
|
855
|
-
var pendingTypedAgentMentionTimer;
|
|
856
|
-
var pendingTypedAgentMentionTimerKey = null;
|
|
857
|
-
var pendingTypedAgentMentionFocusDeferCount = 0;
|
|
858
|
-
// Tracks agent IDs for which resolveMentionName() is already in-flight,
|
|
859
|
-
// preventing duplicate concurrent Promises for the same ID across update() cycles.
|
|
860
|
-
var pendingResolveMentionIds = new Set();
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* Clears the currently scheduled pending typed-agent-mention timer.
|
|
864
|
-
*
|
|
865
|
-
* By default this also resets the focus defer count because a new pending mention,
|
|
866
|
-
* local edit reset, or cleanup should start a fresh escape-hatch window. Focus-based
|
|
867
|
-
* retries pass `preserveFocusDeferCount` so repeated defers for the same pending
|
|
868
|
-
* mention are counted toward the bounded retry cap.
|
|
869
|
-
*/
|
|
870
|
-
var clearPendingTypedAgentMentionTimer = function clearPendingTypedAgentMentionTimer() {
|
|
871
|
-
var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
872
|
-
_ref4$preserveFocusDe = _ref4.preserveFocusDeferCount,
|
|
873
|
-
preserveFocusDeferCount = _ref4$preserveFocusDe === void 0 ? false : _ref4$preserveFocusDe;
|
|
874
|
-
if (pendingTypedAgentMentionTimer) {
|
|
875
|
-
clearTimeout(pendingTypedAgentMentionTimer);
|
|
876
|
-
pendingTypedAgentMentionTimer = undefined;
|
|
877
|
-
}
|
|
878
|
-
pendingTypedAgentMentionTimerKey = null;
|
|
879
|
-
if (!preserveFocusDeferCount) {
|
|
880
|
-
pendingTypedAgentMentionFocusDeferCount = 0;
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
|
|
884
|
-
/**
|
|
885
|
-
* Typed agent mentions intentionally wait before invoking the agent so content the
|
|
886
|
-
* user adds next can become context. That context can be authored through
|
|
887
|
-
* editor-adjacent UI, such as mention typeahead, date picker, or status picker,
|
|
888
|
-
* where focus leaves the ProseMirror editor but remains in the active document.
|
|
889
|
-
* Treat that as continued authoring activity by restarting the inactivity window.
|
|
890
|
-
* This only defers the inactivity timer path: existing selection-change handling can
|
|
891
|
-
* still publish or clear the pending mention sooner. After 20 focus defers (~1 minute),
|
|
892
|
-
* publish anyway so pathological focus states cannot keep the mention pending indefinitely.
|
|
893
|
-
*/
|
|
894
|
-
var shouldDeferPendingTypedAgentMention = function shouldDeferPendingTypedAgentMention() {
|
|
895
|
-
return typeof document !== 'undefined' && document.hasFocus() && !editorView.hasFocus();
|
|
896
|
-
};
|
|
897
|
-
var _schedulePendingTypedAgentMentionTimer = function schedulePendingTypedAgentMentionTimer(mentionPluginState) {
|
|
898
|
-
var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
899
|
-
_ref5$preserveFocusDe = _ref5.preserveFocusDeferCount,
|
|
900
|
-
preserveFocusDeferCount = _ref5$preserveFocusDe === void 0 ? false : _ref5$preserveFocusDe;
|
|
901
|
-
if (isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin') || !editorExperiment('platform_editor_agent_mentions', true)) {
|
|
902
|
-
clearPendingTypedAgentMentionTimer();
|
|
903
|
-
return;
|
|
904
|
-
}
|
|
905
|
-
var pendingTypedAgentMention = mentionPluginState === null || mentionPluginState === void 0 ? void 0 : mentionPluginState.pendingTypedAgentMention;
|
|
906
|
-
if (!pendingTypedAgentMention) {
|
|
907
|
-
clearPendingTypedAgentMentionTimer();
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
var timerKey = "".concat(pendingTypedAgentMention.localId, ":").concat(pendingTypedAgentMention.resetCount);
|
|
911
|
-
if (timerKey === pendingTypedAgentMentionTimerKey) {
|
|
912
|
-
return;
|
|
913
|
-
}
|
|
914
|
-
clearPendingTypedAgentMentionTimer({
|
|
915
|
-
preserveFocusDeferCount: preserveFocusDeferCount
|
|
916
|
-
});
|
|
917
|
-
pendingTypedAgentMentionTimerKey = timerKey;
|
|
918
|
-
pendingTypedAgentMentionTimer = setTimeout(function () {
|
|
919
|
-
var _mentionPluginKey$get2;
|
|
920
|
-
{
|
|
921
|
-
var _options$getIsRovoPan3;
|
|
922
|
-
// Suppress the agent-mention nudge when the Rovo panel is already open. Task
|
|
923
|
-
// items are exempt only while platform_editor_agent_mentions_no_task_autofire
|
|
924
|
-
// is off (they auto-fire instead). With it on they are suppressed like every
|
|
925
|
-
// other block.
|
|
926
|
-
var isTaskItemMention = pendingTypedAgentMention.parentNodeType === 'taskItem' && !fg('platform_editor_agent_mentions_no_task_autofire');
|
|
927
|
-
if (!isTaskItemMention && options !== null && options !== void 0 && (_options$getIsRovoPan3 = options.getIsRovoPanelOpen) !== null && _options$getIsRovoPan3 !== void 0 && _options$getIsRovoPan3.call(options)) {
|
|
928
|
-
// Dispatch a discard so pendingTypedAgentMention is nulled out of plugin
|
|
929
|
-
// state.
|
|
930
|
-
editorView.dispatch(editorView.state.tr.setMeta(mentionPluginKey, {
|
|
931
|
-
action: ACTIONS.DISCARD_PENDING_TYPED_AGENT_MENTION,
|
|
932
|
-
params: {
|
|
933
|
-
localId: pendingTypedAgentMention.localId,
|
|
934
|
-
resetCount: pendingTypedAgentMention.resetCount
|
|
935
|
-
}
|
|
936
|
-
}));
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
var latestPendingTypedAgentMention = (_mentionPluginKey$get2 = mentionPluginKey.getState(editorView.state)) === null || _mentionPluginKey$get2 === void 0 ? void 0 : _mentionPluginKey$get2.pendingTypedAgentMention;
|
|
941
|
-
if (!latestPendingTypedAgentMention || latestPendingTypedAgentMention.localId !== pendingTypedAgentMention.localId || latestPendingTypedAgentMention.resetCount !== pendingTypedAgentMention.resetCount) {
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
if (shouldDeferPendingTypedAgentMention() && pendingTypedAgentMentionFocusDeferCount < MAX_PENDING_TYPED_AGENT_MENTION_FOCUS_DEFERS) {
|
|
945
|
-
pendingTypedAgentMentionFocusDeferCount++;
|
|
946
|
-
pendingTypedAgentMentionTimerKey = null;
|
|
947
|
-
_schedulePendingTypedAgentMentionTimer(mentionPluginKey.getState(editorView.state), {
|
|
948
|
-
preserveFocusDeferCount: true
|
|
949
|
-
});
|
|
950
|
-
return;
|
|
951
|
-
}
|
|
952
|
-
pendingTypedAgentMentionFocusDeferCount = 0;
|
|
953
|
-
editorView.dispatch(editorView.state.tr.setMeta(mentionPluginKey, {
|
|
954
|
-
action: ACTIONS.COMMIT_PENDING_TYPED_AGENT_MENTION,
|
|
955
|
-
params: {
|
|
956
|
-
localId: pendingTypedAgentMention.localId,
|
|
957
|
-
resetCount: pendingTypedAgentMention.resetCount
|
|
958
|
-
}
|
|
959
|
-
}));
|
|
960
|
-
}, AGENT_MENTION_INACTIVITY_MS);
|
|
961
|
-
};
|
|
962
183
|
var providerHandler = function providerHandler(name, providerPromise) {
|
|
963
184
|
switch (name) {
|
|
964
185
|
case 'mentionProvider':
|
|
@@ -1004,25 +225,7 @@ export function createMentionPlugin(_ref2) {
|
|
|
1004
225
|
pmPluginFactoryParams.providerFactory.subscribe('mentionProvider', providerHandler);
|
|
1005
226
|
}
|
|
1006
227
|
return {
|
|
1007
|
-
update: function update(view, prevState) {
|
|
1008
|
-
var mentionPluginState = mentionPluginKey.getState(view.state);
|
|
1009
|
-
if (mentionPluginState === mentionPluginKey.getState(prevState)) {
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
if (!isExperimentEnabled('platform_editor_agent_mentions_separate_pm_plugin')) {
|
|
1013
|
-
var _mentionPluginState$p;
|
|
1014
|
-
_schedulePendingTypedAgentMentionTimer(mentionPluginState);
|
|
1015
|
-
|
|
1016
|
-
// If a pasted agent mention has no name (cache miss), resolve it async
|
|
1017
|
-
// via the mention provider and dispatch RESOLVE_PASTED_AGENT_MENTION_NAME
|
|
1018
|
-
// so the nudge displays the correct name.
|
|
1019
|
-
if (editorExperiment('platform_editor_agent_mentions', true) && (mentionPluginState === null || mentionPluginState === void 0 || (_mentionPluginState$p = mentionPluginState.pendingPastedAgentMention) === null || _mentionPluginState$p === void 0 ? void 0 : _mentionPluginState$p.id) != null && mentionPluginState !== null && mentionPluginState !== void 0 && mentionPluginState.mentionProvider && isResolvingMentionProvider(mentionPluginState.mentionProvider) && fg('platform_editor_agent_mentions_drop_one_fixes')) {
|
|
1020
|
-
resolveAndDispatchPastedAgentMentionName(mentionPluginState.pendingPastedAgentMention.id, mentionPluginState.mentionProvider, pendingResolveMentionIds, view);
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
},
|
|
1024
228
|
destroy: function destroy() {
|
|
1025
|
-
clearPendingTypedAgentMentionTimer();
|
|
1026
229
|
if (pmPluginFactoryParams.providerFactory) {
|
|
1027
230
|
pmPluginFactoryParams.providerFactory.unsubscribe('mentionProvider', providerHandler);
|
|
1028
231
|
}
|