Add support plugin events to editor/another plugin

This commit is contained in:
Oleg Korshul
2025-09-25 22:54:02 +03:00
parent d9446c8536
commit 4c6dd776fa
4 changed files with 100 additions and 2 deletions

View File

@ -5893,6 +5893,21 @@
return (0 !== results.length) ? true : false;
};
baseEditorsApi.prototype["checkAIActions"] = baseEditorsApi.prototype.checkAIActions = function(resolve)
{
if (this.checkAI())
{
resolve({
"error" : true
});
return;
}
this.AI({
"type" : "Actions"
}, resolve);
};
baseEditorsApi.prototype.onAttachPluginEvent = function(guid, name)
{
};

View File

@ -2371,6 +2371,49 @@
}
};
/**
* Catch AI event from plugin.
* @memberof Api
* @undocumented
* @typeofeditors ["CDE", "CSE", "CPE", "PDF"]
* @alias onAIRequest
* @param {object} data - Data.
* @since 9.0.0
*/
Api.prototype["pluginMethod_AI"] = function(data)
{
if (!window.g_asc_plugins)
return;
window.g_asc_plugins._internalEvents["ai_onStartAction"] = function(data) {
window.g_asc_plugins.api.sync_StartAction((data.type === "Block") ? Asc.c_oAscAsyncActionType.BlockInteraction : Asc.c_oAscAsyncActionType.Information, data.description);
};
window.g_asc_plugins._internalEvents["ai_onEndAction"] = function(data) {
window.g_asc_plugins.api.sync_EndAction((data.type === "Block") ? Asc.c_oAscAsyncActionType.BlockInteraction : Asc.c_oAscAsyncActionType.Information, data.description);
};
window.g_asc_plugins._internalEvents["ai_onRequest"] = function(data) {
let api = window.g_asc_plugins.api;
let curItem = api.aiResolvers[0];
api.aiResolvers.shift();
curItem.resolve(data);
if (api.aiResolvers.length > 0)
api._AI();
};
window.g_asc_plugins.setPluginMethodReturnAsync();
data["isFromMethod"] = true;
this.AI(data, function(data) {
delete window.g_asc_plugins._internalEvents["ai_onStartAction"];
delete window.g_asc_plugins._internalEvents["ai_onEndAction"];
delete window.g_asc_plugins._internalEvents["ai_onRequest"];
window.g_asc_plugins.onPluginMethodReturn(data);
});
};
/**
* Catch AI event from plugin.
* @memberof Api

File diff suppressed because one or more lines are too long

View File

@ -783,6 +783,16 @@ window.startPluginApi = function() {
return true;
};
Plugin.sendEvent = function(name, data)
{
window.Asc.plugin.executeMethod("SendEvent", [name, data]);
};
Plugin.sendEventInternal = function(name, data)
{
window.Asc.plugin.executeMethod("SendEventInternal", [name, data]);
};
};