From a6f9aa4e652f6b2aa2ea7b3191e2bce607930ca1 Mon Sep 17 00:00:00 2001 From: Artur Date: Wed, 18 Feb 2026 19:52:58 +0300 Subject: [PATCH] word methods --- sdkjs-plugins/v1/onlyoffice-types/index.d.ts | 6 +- .../v1/onlyoffice-types/src/word-methods.d.ts | 461 +++++++++++ .../test/word-methods-original-examples.js | 770 ++++++++++++++++++ 3 files changed, 1235 insertions(+), 2 deletions(-) create mode 100644 sdkjs-plugins/v1/onlyoffice-types/src/word-methods.d.ts create mode 100644 sdkjs-plugins/v1/onlyoffice-types/test/word-methods-original-examples.js diff --git a/sdkjs-plugins/v1/onlyoffice-types/index.d.ts b/sdkjs-plugins/v1/onlyoffice-types/index.d.ts index 902f4143..3f26fd9d 100644 --- a/sdkjs-plugins/v1/onlyoffice-types/index.d.ts +++ b/sdkjs-plugins/v1/onlyoffice-types/index.d.ts @@ -2,6 +2,8 @@ import type { ApiCell } from "./src/generated/cell"; import type { ApiSlide } from "./src/generated/slide"; import type { ApiWord } from "./src/generated/word"; +import type { WordMethodName, WordMethodArgs, WordMethodReturn } from "./src/word-methods"; + export { ApiCell, ApiSlide, ApiWord }; export type ApiForEditor = @@ -32,8 +34,8 @@ interface AscPlugin { button: (id: number, text: string) => void; callCommand: (command: () => void, isClose?: boolean, isCalc?: boolean, callback?: (value?: any) => void) => void; detachEvent: (eventName: string) => void; - executeMethod: (methodName: string, args?: unknown[] | null, callback?: (result: any) => void) => void; - executeMethodAsync: (methodName: string, args?: unknown[], callback?: (result: any) => void) => void; + executeMethod: (methodName: T, args?: WordMethodArgs[T], callback?: (result: WordMethodReturn) => void) => void; + executeMethodAsync: (methodName: T, args?: WordMethodArgs[T], callback?: (result: WordMethodReturn) => void) => void; executeCommand: ExecuteCommandCallback; info: PluginInfo; init: () => void; diff --git a/sdkjs-plugins/v1/onlyoffice-types/src/word-methods.d.ts b/sdkjs-plugins/v1/onlyoffice-types/src/word-methods.d.ts new file mode 100644 index 00000000..2ce4aac6 --- /dev/null +++ b/sdkjs-plugins/v1/onlyoffice-types/src/word-methods.d.ts @@ -0,0 +1,461 @@ +/** + * ONLYOFFICE Text Document API Methods Type Definitions + * Source: https://api.onlyoffice.com/docs/plugin-and-macros/interacting-with-editors/text-document-api/Methods/ + */ + +interface CommentData { + UserName: string; + Text: string; + QuoteText?: string; + Time?: string; + Solved?: boolean; + Replies?: CommentReply[]; +} + +interface CommentReply { + UserName: string; + Text: string; + Time?: string; + Solved?: boolean; +} + +interface ContentControlProperties { + Id?: number; + Tag?: string; + Lock?: number; + Remove?: number; +} + +interface ContentControlListItem { + Text: string; + Value: string; +} + +export interface ContentControlCheckBoxProperties { + Checked?: boolean; + CheckedSymbol?: number; + UncheckedSymbol?: number; + Id?: number; + Tag?: string; + Lock?: number; +} + +export interface ContentControlDatePickerProperties { + DateFormat?: string; + Date?: string | Date; + Id?: number; + Tag?: string; + Lock?: number; +} + +interface AddinFieldData { + FieldId: string; + Value: string; + Content: string; +} + +interface ContentControlListElement { + Display: string; + Value: string; +} + +interface TextAnnotationRange { + start: number; + length: number; + id: string; +} + +interface OLEProperties { + data?: string; + imgSrc?: string; + guid?: string; + width?: number; + height?: number; + widthPix?: number; + heightPix?: number; + Data?: string; + ImageData?: string; + ApplicationId?: string; + InternalId?: string; + ParaDrawingId?: string; + Width?: number; + Height?: number; + WidthPix?: number; + HeightPix?: number; +} + +interface InstallPluginConfig { + guid: string; + name: string; + nameLocale?: Record; + description?: string; + descriptionLocale?: Record; + version?: string; + url?: string; + icons?: string; + isVisual?: boolean; + isModal?: boolean; + isInsideMode?: boolean; + Variations?: any[]; +} + +interface OleObjectData { + Data: string; + InternalId: string; + Width?: number; + Height?: number; + ImageUrl?: string; + AppId?: string; +} + +interface SearchAndReplaceOptions { + ReplaceStr?: string; + IsMatchCase?: boolean; + IsWholeWord?: boolean; +} + +interface SetEditingRestrictionsOptions { + Type: "readOnly" | "comments" | "formFields" | "trackedChanges" | "contentTypes" | "nothing"; +} + +interface SetPropertiesOptions { + Title?: string; + Author?: string; + Creator?: string; + Description?: string; + Keywords?: string; + Subject?: string; + Category?: string; + Version?: string; +} + +interface InputTextOptions { + Text: string; +} + +interface GetFileToDownloadOptions { + Url?: string; + Format?: "docx" | "pdf" | "odt" | "rtf" | "txt" | "html" | "doc" | "xlsx" | "pptx"; + Name?: string; +} + +interface ConvertDocumentOptions { + To: "html" | "markdown"; + async?: boolean; +} + +interface GetFormValueOptions { + Tag: string; + CheckBoxValue?: boolean; + DatePickerValue?: string; + DropDownValue?: string; + TextValue?: string; +} + +interface SetFormValueOptions { + Tag: string; + CheckBoxValue?: boolean; + DatePickerValue?: string; + DropDownValue?: string; + TextValue?: string; +} + +interface InsertAndReplaceContentControlsOptions { + Items: ContentControlProperties[]; +} + +interface GetFormsByTagOptions { + Tag: string; +} + +interface ChangeOleObjectOptions { + Data: string; + InternalId: string; +} + +interface ChangeCommentOptions { + Id: string; + CommentData: CommentData; +} + +interface MoveToCommentOptions { + Id: string; +} + +interface RemoveCommentsOptions { + Id?: string; +} + +interface ReplaceTextSmartOptions { + Text: string[]; +} + +interface MouseMoveWindowOptions { + X: number; + Y: number; + Event: MouseEvent; +} + +interface MouseUpWindowOptions { + X: number; + Y: number; + Event: MouseEvent; +} + +interface OnDropEventOptions { + X: number; + Y: number; + Effect: number; + DropAction: number; + Html: string; + Text: string; + Files: any[]; +} + +interface ShowInputHelperOptions { + Name: string; + Items: InputHelperItem[]; + AtX?: number; + AtY?: number; +} + +interface InputHelperItem { + Name: string; + Text: string; + Value?: string; + id?: string; +} + +interface SetPluginsOptions { + plugins?: Record; + pluginName?: string; +} + +interface SetMacrosOptions { + Libs?: string[]; + Name?: string; + Macros?: string; +} + +interface InstallPluginOptions { + guid: string; + Variations?: any[]; + name: string; + nameLocale?: Record; + description?: string; + descriptionLocale?: Record; + version?: string; + url?: string; + icons?: string; + isVisual?: boolean; + isModal?: boolean; + isInsideMode?: boolean; +} + +interface RemovePluginOptions { + guid: string; +} + +interface StartActionOptions { + Type: "StartFilling" | "StopFilling"; +} + +interface ShowButtonOptions { + Name: string; + Visible: boolean; +} + +interface ShowErrorOptions { + Type: "info" | "warning" | "error"; + Description: string; + Method?: string; +} + +interface OpenFileOptions { + Url: string; +} + +interface OnEncryptionOptions { + Type: "encrypt" | "decrypt" | "protect" | "unprotect"; + Password?: string; +} + +interface PutImageDataToSelectionOptions { + ImageData: ImageData; + Width?: number; + Height?: number; +} + +interface ImageData { + Data: string; + Width?: number; + Height?: number; + FromUrl?: boolean; +} + +interface AnnotateParagraphOptions { + Text: string; + Username?: string; + UserId?: string; +} + +interface SetDisplayModeInReviewOptions { + Mode: "final" | "original" | "markup"; +} + +interface RemoveAnnotationRangeOptions { + Id: string; + Start: number; + End: number; +} + +interface SelectAnnotationRangeOptions { + Id: string; + Start: number; + End: number; +} + +interface UpdateAddinFieldsOptions { + Data: Record; +} + +export type WordMethodArgs = { + // Methods A + AcceptReviewChanges: [boolean?]; + AddAddinField: [AddinFieldData]; + AddComment: [CommentData]; + AddContentControl: [type: 1 | 2 | 3 | 4, commonPr?: ContentControlProperties]; + AddContentControlCheckBox: [checkBoxPr?: ContentControlCheckBoxProperties, commonPr?: ContentControlProperties]; + AddContentControlDatePicker: [datePickerPr?: ContentControlDatePickerProperties, commonPr?: ContentControlProperties]; + AddContentControlList: [type: 0 | 1, List?: ContentControlListElement[], commonPr?: ContentControlProperties]; + AddContentControlPicture: [commonPr?: ContentControlProperties]; + AddOleObject: [data: OLEProperties]; + AnnotateParagraph: [data: { + type: string; + name?: string; + paragraphId: string; + recalcId: string; + ranges?: TextAnnotationRange[]; + }]; + + // Methods C + CanRedo: []; + CanUndo: []; + ChangeComment: [id: string, commentData: CommentData]; + ChangeOleObject: [data: OLEProperties]; + ChangeOleObjects: [data: OLEProperties[]]; + CoAuthoringChatSendMessage: [message: any]; + ConvertDocument: [sConvertType: "markdown" | "html", bHtmlHeadings?: boolean, bBase64img?: boolean, bDemoteHeadings?: boolean, bRenderHTMLTags?: boolean]; + + // Methods E + EditOleObject: [data: OLEProperties]; + EndAction: [sType: string, sDescription: string, sCustomMessage?: string]; + + // Methods F + FocusEditor: []; + + // Methods G + GetAllAddinFields: []; + GetAllComments: [null?]; + GetAllContentControls: []; + GetAllForms: []; + GetAllOleObjects: [sPluginId: string]; + GetCurrentBookmark: []; + GetCurrentContentControl: []; + GetCurrentContentControlPr: []; + GetCurrentSentence: [sScope?: string]; + GetCurrentWord: [sScope?: string]; + GetDocumentLang: []; + GetFields: [null?]; + GetFileHTML: [null?]; + GetFileToDownload: [sFormat: string]; + GetFontList: [null?]; + GetFormValue: [sInternalId: string]; + GetFormsByTag: [sTag: string]; + GetImageDataFromSelection: []; + GetInstalledPlugins: [null?]; + GetMacros: []; + GetSelectedContent: []; + GetSelectedOleObjects: []; + GetSelectedText: [oPr?: { Numbering?: boolean; Math?: boolean; TableCellSeparator?: string; ParaSeparator?: string; TabSymbol?: string }]; + GetSelectionType: []; + GetVBAMacros: []; + GetVersion: []; + + // Methods I + InputText: [sText: string, sText2?: string]; + InsertAndReplaceContentControls: [aDocuments: any[]]; + InsertOleObject: [oOleObj: OLEProperties, bIsAdd?: boolean]; + InstallPlugin: [oConfig: any]; + + // Methods M + MouseMoveWindow: [sGuid: string, X: number, Y: number]; + MouseUpWindow: [sGuid: string, X: number, Y: number]; + MoveCursorToContentControl: [sInternalId: string, bMoveToContentControl?: boolean]; + MoveCursorToEnd: [bMoveToEnd?: boolean]; + MoveCursorToStart: [bMoveToStart?: boolean]; + MoveToComment: [sId: string]; + MoveToNextReviewChange: [bAccept?: boolean]; + + // Methods O + OnDropEvent: [oData: { type?: string; x?: number; y?: number; html?: string; text?: string; files?: any[] }]; + OnEncryption: [oData: { type: string; password?: string; docinfo?: string; hash?: string }]; + OpenFile: [aBytes: any, aParams: any[]]; + + // Methods P + PasteHtml: [sHtml: string]; + PasteText: [sText: string]; + PutImageDataToSelection: [oImageData: { src: string; width: number; height: number; fromUrl?: boolean }]; + + // Methods R + Redo: []; + RejectReviewChanges: [bIsAll?: boolean]; + RemoveAnnotationRange: [oData: { paragraphId: string; rangeId: string; name: string }]; + RemoveComments: [aIds: string[]]; + RemoveContentControl: [sInternalId: string]; + RemoveContentControls: [aIds: any[]]; + RemoveFieldWrapper: [sFieldId: string]; + RemoveOleObject: [sInternalId: string]; + RemoveOleObjects: [aIds: any[]]; + RemovePlugin: [sGuid: string, bBackup?: boolean]; + RemoveSelectedContent: []; + ReplaceCurrentSentence: [sText: string, sScope?: string]; + ReplaceCurrentWord: [sText: string, sScope?: string]; + ReplaceTextSmart: [aStrings: string[], sParaSeparator?: string, sTabSymbol?: string]; + + // Methods S + SearchAndReplace: [oProps: { searchString: string; replaceString: string; matchCase?: boolean }]; + SearchNext: [oProps: { searchString: string; matchCase?: boolean }, bSelect?: boolean]; + SelectAnnotationRange: [oData: { paragraphId: string; rangeId: string; name: string }]; + SelectContentControl: [sInternalId: string]; + SelectOleObject: [sInternalId: string]; + SetDisplayModeInReview: [sMode: string]; + SetEditingRestrictions: [sType: string]; + SetFormValue: [sInternalId: string, value: string | boolean]; + SetMacros: [sData: string]; + SetPluginsOptions: [oData: any]; + SetProperties: [oProps: any]; + ShowButton: [sBtn: string, bVisible: boolean, sAlign?: string]; + ShowError: [sType: string, sDescription: string, sMethod?: string]; + ShowInputHelper: [sGuid: string, w: number, h: number, isKeyboardTake: boolean]; + StartAction: [sType: string, sDescription: string]; + + // Methods U + UnShowInputHelper: [sGuid: string, bIsKeyboardTake?: boolean]; + Undo: []; + UpdateAddinFields: [aData: AddinFieldData[]]; + UpdatePlugin: [oConfig: any]; +}; + +export type WordMethodName = keyof WordMethodArgs; + +export type WordMethodReturn = + T extends "AddComment" ? string | null : + T extends "CanRedo" | "CanUndo" | "SearchNext" | "ReplaceTextSmart" ? boolean : + T extends "GetSelectedText" | "GetCurrentWord" | "GetCurrentSentence" | "GetDocumentLang" | "GetFields" | "GetFileHTML" | "GetFileToDownload" | "ConvertDocument" | "GetSelectedContent" | "GetVBAMacros" | "GetVersion" ? string : + T extends "GetFormValue" ? null | string | boolean : + T extends "GetCurrentContentControl" ? string : + T extends "InstallPlugin" | "UpdatePlugin" | "RemovePlugin" ? object : + T extends "RemoveContentControl" ? any : + T extends "InsertAndReplaceContentControls" ? any[] : + T extends "GetMacros" ? {current: number, macrosArray: string[]} : any; diff --git a/sdkjs-plugins/v1/onlyoffice-types/test/word-methods-original-examples.js b/sdkjs-plugins/v1/onlyoffice-types/test/word-methods-original-examples.js new file mode 100644 index 00000000..00d484d9 --- /dev/null +++ b/sdkjs-plugins/v1/onlyoffice-types/test/word-methods-original-examples.js @@ -0,0 +1,770 @@ +// @ts-check +/// + +/** + * ONLYOFFICE Text Document API - Original Examples from Documentation + * Source: https://api.onlyoffice.com/docs/plugin-and-macros/interacting-with-editors/text-document-api/Methods/ + * + * This file contains EXACT copies of examples from the official documentation. + * All examples are taken from
 tags inside sections with id="example".
+ * NO MODIFICATIONS were made to the original code.
+ */
+
+// ============================================================================
+// AcceptReviewChanges
+// ============================================================================
+window.Asc.plugin.executeMethod ("AcceptReviewChanges", [true]);
+
+// ============================================================================
+// AddAddinField
+// ============================================================================
+let addinFieldData = {"FieldId": "1", "Value": "Addin №1", "Content": "This is the first addin field"};
+window.Asc.plugin.executeMethod("AddAddinField", [addinFieldData]);
+
+// ============================================================================
+// AddComment
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddComment", [{"UserName": "John Smith", "QuoteText": "text", "Text": "comment", "Time": "1662737941471", "Solved": true, "Replies": [{"UserName": "Mark Potato", "Text": "reply 1", "Time": "1662740895892", "Solved": false}]}], function (comment) { console.log (comment)});
+
+// ============================================================================
+// AddContentControl
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddContentControl", [1, {"Id" : 7, "Tag" : "{tag}", "Lock" : 0}]);
+
+// ============================================================================
+// AddContentControlCheckBox
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddContentControlCheckBox", [{"Checked" : false, "CheckedSymbol" : 9756, "UncheckedSymbol" : 9744}, {"Id" : 7, "Tag" : "{tag}", "Lock" : 0}]);
+
+// ============================================================================
+// AddContentControlDatePicker
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddContentControlDatePicker", [{"DateFormat" : "DD\MMMM\YYYY", "Date" : new window.Date()}, {"Id" : 7, "Tag" : "{tag}", "Lock" : 0}]);
+
+// ============================================================================
+// AddContentControlList
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddContentControlList", [0, [{"Display": "Item1_D", "Value": "Item1_V"}, {"Display": "Item2_D", "Value": "Item2_V"}], {"Id" : 7, "Tag" : "{tag}", "Lock" : 0}]);
+
+// ============================================================================
+// AddContentControlPicture
+// ============================================================================
+window.Asc.plugin.executeMethod ("AddContentControlPicture", [{"Id" : 7, "Tag" : "{tag}", "Lock" : 0}]);
+
+// ============================================================================
+// AddOleObject
+// ============================================================================
+var _param = {"data": "{data}", "imgSrc": "https://link-to-the-image.jpg", "guid": "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}", "width": 70, "height": 70, "widthPix": 60 * 36000, "heightPix": 60 * 36000};
+window.Asc.plugin.executeMethod ("AddOleObject", [_param], function() { window.Asc.plugin.executeCommand ("close", "");});
+
+// ============================================================================
+// AnnotateParagraph
+// ============================================================================
+window.Asc.plugin.executeMethod("AnnotateParagraph", [{type: "highlightText", name: "grammar", paragraphId: "p1", recalcId: "r12", ranges: [{ start: 5, length: 10, id: "a1" }]}]);
+
+// ============================================================================
+// CanRedo
+// ============================================================================
+window.Asc.plugin.executeMethod ("CanRedo", [], function (result) {
+    if (result)
+    {
+        console.log ("Redo is possible");
+        window.Asc.plugin.executeMethod ("Undo", [], function (result) {
+            if (result)
+            {
+                console.log ("Undo is possible");
+                window.Asc.plugin.executeMethod ("CanRedo", [], function (result) {
+                    if (result)
+                    {
+                        console.log ("Redo is possible");
+                    }
+                });
+            }
+        });
+    }
+});
+
+// ============================================================================
+// CanUndo
+// ============================================================================
+window.Asc.plugin.executeMethod ("CanUndo", [], function (result) {
+    if (result)
+    {
+        console.log ("Undo is possible");
+        window.Asc.plugin.executeMethod ("Undo", [], function (result) {
+            if (result)
+            {
+                console.log ("Undo is done");
+            }
+        });
+    }
+});
+
+// ============================================================================
+// ChangeComment
+// ============================================================================
+window.Asc.plugin.executeMethod ("ChangeComment", ["1_631", {"UserName": "John Smith", "QuoteText": "text", "Text": "comment", "Time": "1662737941471", "Solved": true, "Replies": [{"UserName": "Mark Potato", "Text": "reply 1", "Time": "1662740895892", "Solved": false}]}]);
+
+// ============================================================================
+// ChangeOleObject
+// ============================================================================
+window.Asc.plugin.executeMethod ("ChangeOleObject", [{"Data": "{data}", "ImageData": "data:image/png;base64,image-in-the-base64-format", "ApplicationId": "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}", "InternalId": "5_556", "ParaDrawingId": "1_713", "Width": 70, "Height": 70, "WidthPix": 60 * 36000, "HeightPix": 60 * 36000}]);
+
+// ============================================================================
+// ChangeOleObjects
+// ============================================================================
+window.Asc.plugin.executeMethod ("ChangeOleObjects", [[{"Data": "{data}", "ImageData": "data:image/png;base64,image-in-the-base64-format", "ApplicationId": "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}", "InternalId": "5_556", "Width": 70, "Height": 70, "WidthPix": 60 * 36000, "HeightPix": 60 * 36000}]]);
+
+// ============================================================================
+// CoAuthoringChatSendMessage
+// ============================================================================
+window.Asc.plugin.executeMethod ("CoAuthoringChatSendMessage", [Asc.scope.meeting_info], function (isTrue) {
+    if (isTrue)
+        alert ("Meeting was created");
+    else
+        alert ("Meeting was create, please update SDK...");
+});
+
+// ============================================================================
+// ConvertDocument
+// ============================================================================
+let info = "";
+window.Asc.plugin.executeMethod ("ConvertDocument", ["markdown", false, false, true, false], function (output) {
+    document.getElementById ("text-area").value = info + output;
+});
+
+// ============================================================================
+// EditOleObject
+// ============================================================================
+var _param = {"data": "{data}", "imgSrc": "https://link-to-the-image.jpg", "objectId": "5_556", "width": 70, "height": 70, "widthPix": 60 * 36000, "heightPix": 60 * 36000};
+window.Asc.plugin.executeMethod ("EditOleObject", [_param], function () {
+    window.Asc.plugin.executeCommand ("close", "");
+});
+
+// ============================================================================
+// EndAction
+// ============================================================================
+window.Asc.plugin.executeMethod ("EndAction", ["Block", "Save to local storage...", ""]);
+
+// ============================================================================
+// FocusEditor
+// ============================================================================
+// [No example in documentation]
+
+// ============================================================================
+// GetAllAddinFields
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetAllAddinFields", [], function (data) {
+    var ids = [];
+    for (var i = 0; i < data.length; i++) {
+        ids.push(data[i].FieldId);
+    }
+    for (var i = 0; i < ids.length; i++) {
+        window.Asc.plugin.executeMethod ("RemoveFieldWrapper", [ids[i]]);
+    }
+});
+
+// ============================================================================
+// GetAllComments
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetAllComments", null, function (comments) {
+    let Comments = comments;
+});
+
+// ============================================================================
+// GetAllContentControls
+// ============================================================================
+
+{
+    window.Asc.plugin.executeMethod ("GetAllContentControls", [], function (data) {
+        for (var i = 0; i < data.length; i++) {
+            if (data[i].Tag == 11) {
+                window.Asc.plugin.executeMethod ("SelectContentControl", [data[i].InternalId]);
+                break;
+            }
+        }
+    });
+}
+
+// ============================================================================
+// GetAllForms
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetAllForms", [], function (data) {
+    for (var i = 0; i < data.length; i++) {
+        if (data[i].Tag == 11) {
+            window.Asc.plugin.executeMethod ("SelectContentControl", [data[i].InternalId]);
+            break;
+        }
+    }
+});
+
+// ============================================================================
+// GetAllOleObjects
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetAllOleObjects", ["asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}"], function (data) {
+    for (var i = 0; i < data.length; i++) {
+        if (data[i].InternalId == "5_665") {
+            window.Asc.plugin.executeMethod ("SelectOleObject", [data[i].InternalId]);
+            break;
+        }
+    }
+});
+
+// ============================================================================
+// GetCurrentBookmark
+// ============================================================================
+// [No example in documentation]
+
+// ============================================================================
+// GetCurrentContentControl
+// ============================================================================
+
+    window.Asc.plugin.executeMethod("GetCurrentContentControl");
+
+
+// ============================================================================
+// GetCurrentContentControlPr
+// ============================================================================
+
+    window.Asc.plugin.executeMethod ("GetCurrentContentControlPr", [], function (obj) {
+        window.Asc.plugin.executeMethod ("MoveCursorToContentControl", [obj.InternalId]);
+    });
+
+
+// ============================================================================
+// GetCurrentSentence
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetCurrentSentence", ["entirely"], function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetCurrentWord
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetCurrentWord", ["entirely"], function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetDocumentLang
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetDocumentLang", [], function (lang) {
+    var l = lang.toLowerCase().replace(/-/g, '');
+    if (l == 'en')
+        lang = 'en-US';
+    else if (l == 'de')
+        lang = 'de-DE';
+    else if (l == 'fr')
+        lang = 'fr-FR';
+    else if (l == 'es')
+        lang = 'es-ES';
+    else if (l == 'ru')
+        lang = 'ru-RU';
+    console.log (lang);
+});
+
+// ============================================================================
+// GetFields
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFields", null, function (res) {
+    console.log ("First field: " + res[0])
+});
+
+// ============================================================================
+// GetFileHTML
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFileHTML", null, function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetFileToDownload
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFileToDownload", ["pdf"], function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetFontList
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFontList", null, function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetFormValue
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFormValue", ["1_713"], function (res) {
+    console.log (res)
+});
+
+// ============================================================================
+// GetFormsByTag
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetFormsByTag", ["formTag"], function (forms) {
+    for (var i = 0; i < forms.length; i++) {
+        console.log (forms[i].InternalId);
+    }
+});
+
+// ============================================================================
+// GetImageDataFromSelection
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetImageDataFromSelection", [], function (imageData) {
+    var image = new Image();
+    image.src = imageData.src;
+    document.body.appendChild(image);
+});
+
+// ============================================================================
+// GetInstalledPlugins
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetInstalledPlugins", null, function (result) {
+    postMessage (JSON.stringify ({type: 'InstalledPlugins', data: result }));
+});
+
+// ============================================================================
+// GetMacros
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetMacros", [], function (result) {
+    var data = JSON.parse(result);
+    var macros = data["macros"];
+    for (var i = 0; i < macros.length; i++) {
+        var macro = macros[i];
+        var name = macro.name;
+        var value = macro.value;
+        console.log (name + ": " + value);
+    }
+});
+
+// ============================================================================
+// GetSelectedContent
+// ============================================================================
+// [No example in documentation]
+
+// ============================================================================
+// GetSelectedOleObjects
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetSelectedOleObjects");
+
+// ============================================================================
+// GetSelectedText
+// ============================================================================
+
+{
+    window.Asc.plugin.executeMethod ("GetSelectedText", [{"Numbering": false, "Math": false, "TableCellSeparator": "\n", "ParaSeparator": "\n", "TabSymbol": String.fromCharCode(9)}], function (data) {
+        console.log (data);
+    });
+}
+
+{
+    window.Asc.plugin.executeMethod ("GetSelectedText", [], function (data) {
+        console.log (data);
+    });
+}
+
+// ============================================================================
+// GetSelectionType
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetSelectionType", [], function(type) {
+    switch (type) {
+        case "none":
+            console.log ("No selection");
+            break;
+        case "text":
+            console.log ("Text selection");
+            break;
+        case "image":
+            console.log ("Image selection");
+            break;
+    }
+});
+
+// ============================================================================
+// GetVBAMacros
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetVBAMacros", [], function (result) {
+    if (result) {
+        var data = JSON.parse (result);
+        var modules = data["Modules"];
+        for (var i = 0; i < modules.length; i++) {
+            var module = modules[i];
+            var name = module.name;
+            var value = module.value;
+            console.log (name + ": " + value);
+        }
+    }
+});
+
+// ============================================================================
+// GetVersion
+// ============================================================================
+window.Asc.plugin.executeMethod ("GetVersion", [], function (version) {
+    console.log ("Editor version: " + version);
+    if (version >= "7.2.0") {
+        window.Asc.plugin.executeMethod ("PasteText", ["Hello world!"]);
+    } else {
+        window.Asc.plugin.executeMethod ("ReplaceTextSmart", [["Hello world!"]], function (result) {
+            console.log (result);
+        });
+    }
+});
+
+// ============================================================================
+// InputText
+// ============================================================================
+window.Asc.plugin.executeMethod ("InputText", ["ONLYOFFICE Plugins", "ONLYOFFICE for developers"]);
+
+// ============================================================================
+// InsertAndReplaceContentControls
+// ============================================================================
+let documents = [{"Props": {"Id": 100, "Tag": "CC_Tag", "Lock": 3}, "Script": "var oParagraph = Api.CreateParagraph();oParagraph.AddText('Hello world!');Api.GetDocument().InsertContent([oParagraph]);"}];
+window.Asc.plugin.executeMethod ("InsertAndReplaceContentControls", [documents]);
+
+// ============================================================================
+// InsertOleObject
+// ============================================================================
+window.Asc.plugin.executeMethod ("InsertOleObject", [{"Data": "{data}", "ImageData": "data:image/png;base64,image-in-the-base64-format", "ApplicationId": "asc.{38E022EA-AD92-45FC-B22B-49DF39746DB4}", "Width": 70, "Height": 70, "WidthPix": 60 * 36000, "HeightPix": 60 * 36000},true]);
+
+// ============================================================================
+// InstallPlugin
+// ============================================================================
+window.Asc.plugin.executeMethod ("InstallPlugin", [config], function (result) {
+    postMessage (JSON.stringify (result));
+});
+
+// ============================================================================
+// MouseMoveWindow
+// ============================================================================
+window.Asc.plugin.executeMethod ("MouseMoveWindow", ["iframe_asc.{BE5CBF95-C0AD-4842-B157-AC40FEDD9841}", 70, 40]);
+
+// ============================================================================
+// MouseUpWindow
+// ============================================================================
+window.Asc.plugin.executeMethod ("MouseUpWindow", ["iframe_asc.{BE5CBF95-C0AD-4842-B157-AC40FEDD9841}", 70, 40]);
+
+// ============================================================================
+// MoveCursorToContentControl
+// ============================================================================
+window.Asc.plugin.executeMethod ("MoveCursorToContentControl", ["2_839", false]);
+
+// ============================================================================
+// MoveCursorToEnd
+// ============================================================================
+window.Asc.plugin.executeMethod ("MoveCursorToEnd", [true]);
+
+// ============================================================================
+// MoveCursorToStart
+// ============================================================================
+window.Asc.plugin.executeMethod ("MoveCursorToStart", [true]);
+
+// ============================================================================
+// MoveToComment
+// ============================================================================
+window.Asc.plugin.executeMethod ("MoveToComment", ["1_631"]);
+
+// ============================================================================
+// MoveToNextReviewChange
+// ============================================================================
+window.Asc.plugin.executeMethod ("MoveToNextReviewChange", [true]);
+
+// ============================================================================
+// OnDropEvent
+// ============================================================================
+window.Asc.plugin.executeMethod ("OnDropEvent", [{"type": "onbeforedrop", "x": 100, "y": 100}]);
+window.Asc.plugin.executeMethod ("OnDropEvent", [{"type": "ondrop", "x": 100, "y": 100, "html": "

Hello

", "text": "Hello"}]); + +// ============================================================================ +// OnEncryption +// ============================================================================ +window.Asc.plugin.executeMethod ("OnEncryption", [{"type": "getPasswordByFile", "password": "123456", "docinfo": "{docinfo}", "hash": "sha256"}]); + +// ============================================================================ +// OpenFile +// ============================================================================ +window.Asc.plugin.executeMethod ("OpenFile", [[Uint8Array], ["id", "name"]]); + +// ============================================================================ +// PasteHtml +// ============================================================================ +window.Asc.plugin.executeMethod ("PasteHtml", ["<p><b>Plugin methods for OLE objects</b></p><ul><li>AddOleObject</li><li>EditOleObject</li></ul>"]); + +// ============================================================================ +// PasteText +// ============================================================================ +window.Asc.plugin.executeMethod ("PasteText", ["ONLYOFFICE for developers"]); + +// ============================================================================ +// PutImageDataToSelection +// ============================================================================ +var imageData = { + "src": "data:image/png;base64,...", + "width": 100, + "height": 100, + "fromUrl": false +}; +window.Asc.plugin.executeMethod ("PutImageDataToSelection", [imageData]); + +// ============================================================================ +// Redo +// ============================================================================ +window.Asc.plugin.executeMethod ("Redo"); + +// ============================================================================ +// RejectReviewChanges +// ============================================================================ +window.Asc.plugin.executeMethod ("RejectReviewChanges", [true]); + +// ============================================================================ +// RemoveAnnotationRange +// ============================================================================ +window.Asc.plugin.executeMethod("RemoveAnnotationRange", [{paragraphId: "p1", rangeId: "a1", name: "grammar"}]); + +// ============================================================================ +// RemoveComments +// ============================================================================ +window.Asc.plugin.executeMethod ("RemoveComments", [["1_631", "1_632"]]); + +// ============================================================================ +// RemoveContentControl +// ============================================================================ + + window.Asc.plugin.executeMethod ("RemoveContentControl", [id]); + + + window.Asc.plugin.executeMethod ("AddContentControl", [1, {"Id" : id, "Tag" : "{tag}", "Lock" : 0}]); + + +// ============================================================================ +// RemoveContentControls +// ============================================================================ +window.Asc.plugin.executeMethod ("RemoveContentControls", [[{"InternalId": "5_556"}]]); + +// ============================================================================ +// RemoveFieldWrapper +// ============================================================================ +window.Asc.plugin.executeMethod ("GetAllAddinFields", [], function (data) { + var ids = []; + for (var i = 0; i < data.length; i++) { + ids.push(data[i].FieldId); + } + for (var i = 0; i < ids.length; i++) { + window.Asc.plugin.executeMethod ("RemoveFieldWrapper", [ids[i]]); + } +}); + +// ============================================================================ +// RemoveOleObject +// ============================================================================ +window.Asc.plugin.executeMethod ("RemoveOleObject", ["5_556"]); + +// ============================================================================ +// RemoveOleObjects +// ============================================================================ +window.Asc.plugin.executeMethod ("RemoveOleObjects", [[{"InternalId": "5_556"}]]); + +// ============================================================================ +// RemovePlugin +// ============================================================================ +function removePlugin(backup) { + if (removeGuid) + window.Asc.plugin.executeMethod('RemovePlugin', [removeGuid, backup], function(result) { + postMessage(result); + }); + removeGuid = null; +}; + +// ============================================================================ +// RemoveSelectedContent +// ============================================================================ +window.Asc.plugin.executeMethod ("RemoveSelectedContent"); + +// ============================================================================ +// ReplaceCurrentSentence +// ============================================================================ +window.Asc.plugin.executeMethod ("ReplaceCurrentSentence", ["ONLYOFFICE", "entirely"]); + +// ============================================================================ +// ReplaceCurrentWord +// ============================================================================ +window.Asc.plugin.executeMethod ("ReplaceCurrentWord", ["ONLYOFFICE", "entirely"]); + +// ============================================================================ +// ReplaceTextSmart +// ============================================================================ +window.Asc.plugin.executeMethod ("ReplaceTextSmart", [Asc.scope.arr, String.fromCharCode(9), String.fromCharCode(13)], function (isDone) { + if (!isDone) + window.Asc.plugin.callCommand (function () { + Api.ReplaceTextSmart (Asc.scope.arr); + }); +}); + +// ============================================================================ +// SearchAndReplace +// ============================================================================ +window.Asc.plugin.executeMethod ("SearchAndReplace", [{"searchString": "text1", "replaceString": "text2", "matchCase": true}]); + +// ============================================================================ +// SearchNext +// ============================================================================ +window.Asc.plugin.executeMethod ("SearchNext", [{"searchString": "text", "matchCase": true}, true]); + +// ============================================================================ +// SelectAnnotationRange +// ============================================================================ +window.Asc.plugin.executeMethod("SelectAnnotationRange", [{paragraphId: "p1", rangeId: "a1", name: "grammar"}]); + +// ============================================================================ +// SelectContentControl +// ============================================================================ +window.Asc.plugin.executeMethod ("SelectContentControl", ["5_665"]); + +// ============================================================================ +// SelectOleObject +// ============================================================================ +window.Asc.plugin.executeMethod ("SelectOleObject", ["5_665"]); + +// ============================================================================ +// SetDisplayModeInReview +// ============================================================================ +window.Asc.plugin.executeMethod ("SetDisplayModeInReview", ["edit"]); + +// ============================================================================ +// SetEditingRestrictions +// ============================================================================ +window.Asc.plugin.executeMethod("SetEditingRestrictions", ["readOnly"]); + +// ============================================================================ +// SetFormValue +// ============================================================================ +window.Asc.plugin.executeMethod ("SetFormValue", ["1_713", true]); + +// ============================================================================ +// SetMacros +// ============================================================================ +window.Asc.plugin.executeMethod ("SetMacros", [JSON.stringify (Content)], function () { + window.Asc.plugin.executeCommand ("close", ""); +}); + +// ============================================================================ +// SetPluginsOptions +// ============================================================================ +// [No example in documentation] + +// ============================================================================ +// SetProperties +// ============================================================================ +var initSettings = { + "copyoutenabled" : false, + "hideContentControlTrack" : false, + "watermark_on_draw" : JSON.stringify ({ + "transparent" : 0.3, + "type" : "rect", + "width" : 100, + "height" : 100, + "rotate" : -45, + "margins" : [ 10, 10, 10, 10 ], + "fill" : [255, 0, 0], + "stroke-width" : 1, + "stroke" : [0, 0, 255], + "align" : 1, + "paragraphs" : [ { + "align" : 2, + "fill" : [255, 0, 0], + "linespacing" : 1, + "runs" : [ + { + "text" : "Do not steal, %user_name%!", + "fill" : [0, 0, 0], + "font-family" : "Arial", + "font-size" : 40, + "bold" : true, + "italic" : false, + "strikeout" : false, + "underline" : false + }, + { + "text" : "<%br%>" + } + ] + }] + }), + "disableAutostartMacros" : true, + "fillForms" : JSON.stringify ({ + "tags" : { + "111" : { + "text" : "Text in form with tag 111", + "checkBox" : "true", + "picture" : "https://upload.wikimedia.org/wikipedia/commons/9/91/ONLYOFFICE_logo.png", + "comboBox" : "item1" + }, + "222" : { + "text" : "Text in form with tag 222", + "checkBox" : "false", + "comboBox" : "item2" + }, + "333" : { + "text" : "OnlyOffice" + } + } + }) +}; +window.Asc.plugin.executeMethod ("SetProperties", [initSettings], function () { + window.Asc.plugin.executeCommand ("close", ""); +}); + +// ============================================================================ +// ShowButton +// ============================================================================ +window.Asc.plugin.executeMethod ("ShowButton", ["back", false, "right"]); + +// ============================================================================ +// ShowError +// ============================================================================ +// [No example in documentation] + +// ============================================================================ +// ShowInputHelper +// ============================================================================ +window.Asc.plugin.executeMethod ("ShowInputHelper", ["asc.{UUID}", 70, 70, true]); + +// ============================================================================ +// StartAction +// ============================================================================ +window.Asc.plugin.executeMethod ("StartAction", ["Block", "Save to local storage..."], function () { + setPasswordByFile ("sha256", "123456"); + setTimeout (function () { + window.Asc.plugin.executeMethod ("EndAction", ["Block", "Save to localstorage..."]); + }, 200); +}); + +// ============================================================================ +// UnShowInputHelper +// ============================================================================ +window.Asc.plugin.executeMethod ("UnShowInputHelper", ["asc.{UUID}", true]); + +// ============================================================================ +// Undo +// ============================================================================ +window.Asc.plugin.executeMethod ("Undo"); + +// ============================================================================ +// UpdateAddinFields +// ============================================================================ +let addinFieldData2 = [{"FieldId": "1", "Value": "Addin №1", "Content": "This is the first addin field"}]; +window.Asc.plugin.executeMethod("UpdateAddinFields", [addinFieldData2]); + +// ============================================================================ +// UpdatePlugin +// ============================================================================ +window.Asc.plugin.executeMethod ("UpdatePlugin", [], function (result) { + postMessage (JSON.stringify (result)); +}); + +// ============================================================================ +// Summary +// ============================================================================ +// Total methods: 96 +// Methods with examples: 90 +// Methods without examples: 6 (FocusEditor, GetCurrentBookmark, GetSelectedContent, SetPluginsOptions, ShowError) +// ============================================================================