RequireJS relative paths breaks some libraries submodules

Update. The view is now working with CodeMirror modes!! I am just updating in case it helps someone. The library was already loaded properly but the require/knimeService call was invoked after the page was loaded and thus the library was not available then.

The require configuration was fine. Only the main js needs to be configured.

let require_config = {
    packages: [{
    name: "codemirror",
    location: "codemirror/",
    main: "lib/codemirror"
    }]
};

Then the code mirrors are created when the UI is already created.

let res = knimeService.loadConditionally(
    ["codemirror", "codemirror/mode/r/r", "codemirror/mode/python/python",
    "codemirror/mode/markdown/markdown"],
    (arg) => {
        let CodeMirror = arg[0];
        _modelCodeMirror = CodeMirror.fromTextArea(document.getElementById("modelScriptArea"), {
            lineNumbers: true,
            lineWrapping: true,
            extraKeys: { 'Ctrl-Space': 'autocomplete' },
            mode: { 'name': "text/x-rsrc" }
        });
        _visualizationCodeMirror = CodeMirror.fromTextArea(document.getElementById("visualizationScriptArea"), {
        lineNumbers: true,
        lineWrapping: true,
        extraKeys: { 'Ctrl-Space': 'autocomplete' },
        mode: { 'name': "text/x-python" }
        });
        _readmeCodeMirror = CodeMirror.fromTextArea(document.getElementById("readmeArea"), {
        lineNumbers: true,
        lineWrapping: true,
        extraKeys: { 'Ctrl-Space': 'autocomplete' },
        mode: { 'name': "text/x-markdown" }
        });

        _modelCodeMirror.on("blur", () => { _modelCodeMirror.focus(); });
        _visualizationCodeMirror.on("blur", () => { _visualizationCodeMirror.focus(); });
        _readmeCodeMirror.on("blur", () =>{ _readmeCodeMirror.focus(); });
    },
    (err) => console.log("knimeService failed to install " + err),
    require_config);

Here the modes and addons can be added as long as they main CodeMirror JS is configured. And the CSS file needs to be configured in the plugin.xml as RequireJS does not load it.

Thanks a lot Christian.
Miguel

3 Likes