@atlaskit/editor-plugin-collab-edit
Version:
Collab Edit plugin for @atlaskit/editor-core
36 lines • 2.17 kB
JavaScript
import _typeof from "@babel/runtime/helpers/typeof";
import { pluginKey } from './plugin-key';
var isAgentRemoteStep = function isAgentRemoteStep(step) {
return _typeof(step) === 'object' && step !== null && typeof step.agentType === 'string';
};
var asString = function asString(value) {
return typeof value === 'string' ? value : undefined;
};
export var isStepFromAgentEdit = function isStepFromAgentEdit(step, requester) {
if (!isAgentRemoteStep(step)) {
return false;
}
return step.agentType === requester.agentType && asString(step.agentId) === requester.agentId && asString(step.agentSourceId) === requester.agentSourceId && asString(step.agentNamedId) === requester.agentNamedId && asString(step.userId) === requester.actorUserId && asString(step.invocationId) === requester.invocationId;
};
export var getAgentEditRequester = function getAgentEditRequester(json, view) {
var _collabPluginState$ac;
var agentStep = json.find(isAgentRemoteStep);
if (!agentStep) {
return null;
}
var actorUserId = asString(agentStep.userId);
var collabPluginState = pluginKey.getState(view.state);
var localSessionId = collabPluginState === null || collabPluginState === void 0 ? void 0 : collabPluginState.sessionId;
var localUserId = localSessionId ? collabPluginState === null || collabPluginState === void 0 || (_collabPluginState$ac = collabPluginState.activeParticipants) === null || _collabPluginState$ac === void 0 || (_collabPluginState$ac = _collabPluginState$ac.get(localSessionId)) === null || _collabPluginState$ac === void 0 ? void 0 : _collabPluginState$ac.userId : undefined;
return {
agentId: asString(agentStep.agentId),
agentName: asString(agentStep.agentName),
agentNamedId: asString(agentStep.agentNamedId),
agentSourceId: asString(agentStep.agentSourceId),
agentType: agentStep.agentType,
actorUserId: actorUserId,
invocationId: asString(agentStep.invocationId),
isThirdPartyAgent: typeof agentStep.isThirdPartyAgent === 'boolean' ? agentStep.isThirdPartyAgent : undefined,
isLocalUserRequester: actorUserId !== undefined && localUserId !== undefined && actorUserId === localUserId
};
};