Adding new JavaScript libraries to new JavaScript node

Hi all,

I am trying to create a new JavaScript node based in the Generic JavaScript View node from the package .org.knime.js.node.viz.generic. I am stuck at the the method getConfigurationFromWebResID from the model. That function tries to retrieve the libraries checked in the dialog from a bundle with id org.knime.js.core.webResources. I guess I should modify this bundle and add the new JavaScript libraries, but I am stuck and do not know how to advance.

I found this related topic https://tech.knime.org/forum/knime-general/external-javascript-libraries from last year but it is dead.

Thanks in advance,

Miguel de Alba

Hi Miguel,

if you want to load external libraries into the Generic JS View node, you can use requireJS to do so. RequireJS is already present at the time your code executes, because it is used to load the other dependencies during runtime. 

The following code snippet shows an example of this technique.

require.config({
	paths: {
        "lib1": "http://sample.com/lib1",
        "lib2": "http://foo.org/lib2"
	}	
});
require(["lib1", "lib2",], function(lib1, lib2) {
	lib1.callSomething();
});

You can find the full documentation to requireJS here. Please note, that if your libraries do not detect requireJS (and call define()) it might be necessary to define a shim config.

Hi Christian,

Thanks for the reply. I did not try requireJS yet. Instead I found the js libs at org.knime.js.core and copied that extension point into my project. I intend to load the javascript libraries from this location rather than the ones at org.knime.js.core. Once I get that working I will start adding other libs.

First I modified the ID_WEB_RES at the node model.

    private static final String ID_WEB_RES = "de.bund.bfr.knime.pmm.webResources";

Then I changed the extension point ids so they would not conflict with the original ones.

   <extension-point id="customWebResources" name="Web Resources" schema="schema/webResources.exsd"/>
   <extension-point id="customJavascriptComponents" name="Javascript Components" schema="schema/javascriptComponents.exsd"/>
   <extension
         point="de.bund.bfr.knime.pmm.webResources"

I think the schemas are correct too,

javascriptComponents.exsd

   <extension-point id="customWebResources" name="Web Resources" schema="schema/webResources.exsd"/>
   <extension-point id="customJavascriptComponents" name="Javascript Components" schema="schema/javascriptComponents.exsd"/>
   <extension
         point="de.bund.bfr.knime.pmm.webResources"

webResources.exsd

<schema targetNamespace="de.bund.bfr.knime.pmm.webResources" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
      <appinfo>
         <meta.schema plugin="de.bund.bfr.knime.pmm.webResources" id="customWebResources" name="Web Resources"/>
      </appinfo>
      <documentation>
         This extension point can be used to plug new Javascript implementations of web-enabled KNIME nodes or other web resources into the repository.
      </documentation>
   </annotation>

Nevertheless when I run the node it still fails to retrieve the JS libs.

BTW, the structure of the project is something like,

de.bund.bfr.knime.pmm

- editor

- webResources

- other nodes ...

The webResources extension point the js-core.jar. Only the resources.

Best,

I made it work! I just added the external libraries to a folder in the project and the extension points to the own plugin.xml file of the node. Still, it has severe issues, as most of the gui is not responsive.