mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-02-10 18:05:06 +08:00
re-checking paragraphs after updating the assistant
This commit is contained in:
@ -33,7 +33,11 @@
|
||||
/// <reference path="./custom-annotator.js" />
|
||||
/// <reference path="./types.js" />
|
||||
|
||||
/** @param {localStorageCustomAssistantItem} assistantData */
|
||||
/**
|
||||
* @param {localStorageCustomAssistantItem} assistantData
|
||||
* @constructor
|
||||
* @extends CustomAnnotator
|
||||
*/
|
||||
function AssistantHint(annotationPopup, assistantData)
|
||||
{
|
||||
CustomAnnotator.call(this, annotationPopup, assistantData);
|
||||
|
||||
@ -33,7 +33,11 @@
|
||||
/// <reference path="./custom-annotator.js" />
|
||||
/// <reference path="./types.js" />
|
||||
|
||||
/** @param {localStorageCustomAssistantItem} assistantData */
|
||||
/**
|
||||
* @param {localStorageCustomAssistantItem} assistantData
|
||||
* @constructor
|
||||
* @extends CustomAnnotator
|
||||
*/
|
||||
function AssistantReplaceHint(annotationPopup, assistantData)
|
||||
{
|
||||
CustomAnnotator.call(this, annotationPopup, assistantData);
|
||||
|
||||
@ -33,7 +33,11 @@
|
||||
/// <reference path="./custom-annotator.js" />
|
||||
/// <reference path="./types.js" />
|
||||
|
||||
/** @param {localStorageCustomAssistantItem} assistantData */
|
||||
/**
|
||||
* @param {localStorageCustomAssistantItem} assistantData
|
||||
* @constructor
|
||||
* @extends CustomAnnotator
|
||||
*/
|
||||
function AssistantReplace(annotationPopup, assistantData)
|
||||
{
|
||||
CustomAnnotator.call(this, annotationPopup, assistantData);
|
||||
|
||||
@ -31,7 +31,12 @@
|
||||
*/
|
||||
|
||||
/// <reference path="./types.js" />
|
||||
/// <reference path="../text-annotations/text-annotator.js" />
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @extends TextAnnotator
|
||||
*/
|
||||
function CustomAnnotator(annotationPopup, assistantData)
|
||||
{
|
||||
TextAnnotator.call(this, annotationPopup);
|
||||
|
||||
@ -42,7 +42,7 @@
|
||||
class CustomAssistantManager {
|
||||
constructor() {
|
||||
/**
|
||||
* @type {Map<string, TextAnnotator>}
|
||||
* @type {Map<string, Assistant>}
|
||||
*/
|
||||
this._customAssistants = new Map();
|
||||
this._isCustomAssistantInit = new Map();
|
||||
@ -53,15 +53,13 @@ class CustomAssistantManager {
|
||||
|
||||
/**
|
||||
* @param {localStorageCustomAssistantItem} assistantData
|
||||
* @returns
|
||||
*/
|
||||
createAssistant(assistantData) {
|
||||
let assistant = this._customAssistants.get(assistantData.id);
|
||||
if (assistant) {
|
||||
assistant.assistantData = assistantData;
|
||||
assistant.type = assistantData.type;
|
||||
return assistant;
|
||||
if (this._customAssistants.has(assistantData.id)) {
|
||||
return this._updateAssistant(assistantData);
|
||||
}
|
||||
/** @type {Assistant | null} */
|
||||
let assistant = null;
|
||||
switch (assistantData.type) {
|
||||
case 0:
|
||||
assistant = new AssistantHint(customAnnotationPopup, assistantData);
|
||||
@ -72,10 +70,9 @@ class CustomAssistantManager {
|
||||
case 2:
|
||||
assistant = new AssistantReplace(customAnnotationPopup, assistantData);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown assistant type: ${assistantData.type}`
|
||||
);
|
||||
}
|
||||
if (!assistant) {
|
||||
throw new Error("Unknown custom assistant type: " + assistantData.type);
|
||||
}
|
||||
|
||||
this._isCustomAssistantInit.set(assistantData.id, false);
|
||||
@ -84,6 +81,34 @@ class CustomAssistantManager {
|
||||
|
||||
return assistant;
|
||||
}
|
||||
/**
|
||||
* @param {localStorageCustomAssistantItem} assistantData
|
||||
*/
|
||||
_updateAssistant(assistantData) {
|
||||
let assistant = this._customAssistants.get(assistantData.id);
|
||||
if (!assistant) {
|
||||
throw new Error("Custom assistant not found: " + assistantData.id);
|
||||
}
|
||||
assistant.assistantData = assistantData;
|
||||
assistant.type = assistantData.type;
|
||||
|
||||
const isRunning = this._isCustomAssistantRunning.get(assistantData.id);
|
||||
|
||||
this._paragraphsStack.forEach((value, paraId) => {
|
||||
assistant.onChangeParagraph(
|
||||
paraId,
|
||||
value.recalcId,
|
||||
value.text,
|
||||
value.annotations
|
||||
);
|
||||
});
|
||||
const paragraphIdsToUpdate = [...assistant.checked];
|
||||
if (isRunning) {
|
||||
assistant.checkParagraphs(paragraphIdsToUpdate);
|
||||
}
|
||||
|
||||
return assistant;
|
||||
}
|
||||
|
||||
/** @param {string} assistantId */
|
||||
deleteAssistant(assistantId) {
|
||||
|
||||
@ -62,3 +62,6 @@
|
||||
* @typedef {ReplaceHintInfoForPopup | HintInfoForPopup | ReplaceInfoForPopup} InfoForPopup
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {CustomAnnotator & TextAnnotator & AssistantHint & AssistantReplaceHint & AssistantReplace} Assistant
|
||||
*/
|
||||
@ -40,6 +40,7 @@ function TextAnnotator(annotatorPopup)
|
||||
/** @type {Object.<string, {recalcId: number, text: string}>} */
|
||||
this.waitParagraphs = {};
|
||||
this.paraToCheck = new Set();
|
||||
/** @type {Set<string>} */
|
||||
this.checked = new Set(); // was checked on the previous request
|
||||
|
||||
this.type = -1;
|
||||
|
||||
Reference in New Issue
Block a user