ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

InsertAndReplaceContentControls changes ContentControlType to BlockLevelSdt #143

Open teamoo opened 3 years ago

teamoo commented 3 years ago

Do you want to request a feature or report a bug? Bug What is the current behavior? The method InsertAndReplaceContentControls changes Inline content controls elements to Block content controls Elements. If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Create an inline content control like this:

           const ContentControlyType = {
                Block: 1,
                Inline: 2
            };
            const contentControl = {
                Id: kpiId,
                Lock: 0,
                Tag: kpiSlug,
                Alias: kpiName,
                Appearance: 1,
                Color: {
                    R: 24,
                    G: 193,
                    B: 197
                }
            };
            window.Asc.plugin.executeMethod("AddContentControl", [ContentControlyType.Inline, contentControl]);  

Replace the content of the inline content control:

    window.Asc.plugin.onMethodReturn = function (returnValue) {
        const _plugin = window.Asc.plugin;

        if (_plugin.info.methodName == "AddContentControl" && returnValue && returnValue.InternalId) {
            console.log(returnValue);

            const contentControls = [
                {
                    Props: {
                        InternalId: returnValue.InternalId,
                    },
                    Script: `var oDocument = Api.GetDocument();var oParagraph = Api.CreateParagraph();oParagraph.AddText('${kpiValue}');oDocument.InsertContent([oParagraph]);`
                }
            ];

            window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [contentControls]);
        } else if (_plugin.info.methodName == "InsertAndReplaceContentControls") {
            console.log(returnValue[0]);

            window.Asc.plugin.executeCommand("close", "");
        }
    };

The inline content control will become a block level content control. I think it is due to this line of code: https://github.com/ONLYOFFICE/sdkjs/blob/19a9abb25e28698f8074bac80bc518820997e0fb/word/api.js#L589 # What is the expected behavior? The method should consider the ContentControl Type. Which versions of sdkjs-plugins, and which browser / OS are affected by this issue? Did this work in previous versions of sdkjs-plugins? v1, browser-independent, I don't know if it worked before

ShockwaveNN commented 3 years ago

@askonev Please, take a look

fr3fou commented 1 year ago

any updates on this? been 2 years already :/