mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-02-10 18:15:19 +08:00
Add AI method to api
This commit is contained in:
@ -5511,6 +5511,44 @@
|
||||
baseEditorsApi.prototype.onChangeRTLInterface = function() {
|
||||
};
|
||||
|
||||
baseEditorsApi.prototype._AI = function()
|
||||
{
|
||||
let curItem = this.aiResolvers[0];
|
||||
if (!window.g_asc_plugins)
|
||||
{
|
||||
curItem.resolve({ "error" : "plugins manager does not initialized" });
|
||||
this.aiResolvers.shift();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: only one AI plugin must be presented!
|
||||
//let testGuids = ["asc.{9DC93CDB-B576-4F0C-B55E-FCC9C48DD007}"];
|
||||
let testGuids = undefined;
|
||||
let results = window.g_asc_plugins.onPluginEvent2("onAIRequest", curItem.data, testGuids, true);
|
||||
if (results.length === 0)
|
||||
{
|
||||
curItem.resolve({ "error" : "no registered AI plugins found" });
|
||||
this.aiResolvers.shift();
|
||||
}
|
||||
};
|
||||
|
||||
baseEditorsApi.prototype["AI"] = baseEditorsApi.prototype.AI = function(data, resolve)
|
||||
{
|
||||
this.aiResolvers = this.aiResolvers || [];
|
||||
this.aiResolvers.push({data : data, resolve: resolve});
|
||||
|
||||
if (this.aiResolvers.length > 1)
|
||||
return;
|
||||
|
||||
this._AI();
|
||||
};
|
||||
|
||||
baseEditorsApi.prototype["checkAI"] = baseEditorsApi.prototype.checkAI = function()
|
||||
{
|
||||
let results = window.g_asc_plugins.onPluginEvent2("onAIRequest", null, undefined, true, true);
|
||||
return (0 !== results.length) ? true : false;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------export----------------------------------------------------
|
||||
window['AscCommon'] = window['AscCommon'] || {};
|
||||
window['AscCommon'].baseEditorsApi = baseEditorsApi;
|
||||
|
||||
@ -2122,6 +2122,26 @@
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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_onAIRequest"] = function(data)
|
||||
{
|
||||
let curItem = this.aiResolvers[0];
|
||||
this.aiResolvers.shift();
|
||||
|
||||
if (this.aiResolvers.length > 0)
|
||||
this._AI();
|
||||
|
||||
curItem.resolve(data);
|
||||
};
|
||||
|
||||
})(window);
|
||||
|
||||
|
||||
|
||||
@ -642,15 +642,15 @@
|
||||
},
|
||||
|
||||
// plugin events
|
||||
onPluginEvent : function(name, data)
|
||||
onPluginEvent : function(name, data, isExclusive)
|
||||
{
|
||||
if (this.mainEventTypes[name])
|
||||
this.mainEvents[name] = data;
|
||||
|
||||
return this.onPluginEvent2(name, data, undefined);
|
||||
return this.onPluginEvent2(name, data, undefined, isExclusive);
|
||||
},
|
||||
|
||||
onPluginEvent2 : function(name, data, guids)
|
||||
onPluginEvent2 : function(name, data, guids, isExclusive, isOnlyCheck)
|
||||
{
|
||||
let needsGuids = [];
|
||||
for (let guid in this.runnedPluginsMap)
|
||||
@ -671,13 +671,20 @@
|
||||
runObject.waitEvents.push({ n : name, d : data });
|
||||
continue;
|
||||
}
|
||||
var pluginData = new CPluginData();
|
||||
pluginData.setAttribute("guid", plugin.guid);
|
||||
pluginData.setAttribute("type", "onEvent");
|
||||
pluginData.setAttribute("eventName", name);
|
||||
pluginData.setAttribute("eventData", data);
|
||||
|
||||
this.sendMessageToFrame(runObject.isConnector ? "" : runObject.frameId, pluginData);
|
||||
if (true !== isOnlyCheck)
|
||||
{
|
||||
var pluginData = new CPluginData();
|
||||
pluginData.setAttribute("guid", plugin.guid);
|
||||
pluginData.setAttribute("type", "onEvent");
|
||||
pluginData.setAttribute("eventName", name);
|
||||
pluginData.setAttribute("eventData", data);
|
||||
|
||||
this.sendMessageToFrame(runObject.isConnector ? "" : runObject.frameId, pluginData);
|
||||
}
|
||||
|
||||
if (isExclusive === true)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return needsGuids;
|
||||
|
||||
Reference in New Issue
Block a user