npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-chemdoodle

v0.0.7

Published

The React Chemdoodle Web Components (`react-chemdoodle`) is a UI library add-on for the [ChemDoodle Web Components](https://web.chemdoodle.com/) (CWC) library. CWC provides 18 unique component canvases from a simple 2D "ViewerCanvas" to 3D "EditorCanvas3D

Downloads

106

Readme

React Chemdoodle Web Components

The React Chemdoodle Web Components (react-chemdoodle) is a UI library add-on for the ChemDoodle Web Components (CWC) library. CWC provides 18 unique component canvases from a simple 2D "ViewerCanvas" to 3D "EditorCanvas3D" to a "PeriodicTableCanvas". At the moment, react-chemdoodle wraps just two canvases, the 2D "ViewerCanvas" and "SketcherCanvas". Contributions are welcome to provide bindings for additional canvases.

Installation

As it was originally written in 2007, CWC consists of a number of IIFE modules divided into two javascript files, one a "core" file and one an optional jQuery-based UI, that are loaded by a client browser. The react-chemdoodle library on the otherhand is a "require time" node module that can be compiled by JS bundlers more typical in modern web application development. While react-chemdoodleweb can be downloaded from NPM, CWC scripts need to be embedded into the HTML document. While this is a simple implementation that ensures CWC is available everywhere for the lifetime of the React application, the tradeoff is that CWC is not bundled with the rest of the React application code and will make an additional network request. As well, it will be loaded even if the current page does not use it (The size of the minified CWC script is 414 kB).

1. Download CWC

react-chemdoodleweb depends on the ChemDoodle global object, so CWC first needs to be installed in your project. Downloaded CWC from web.chemdoodle.com/installation/download.

2. Embed CWC as a client-side script

Place CWC in the public folder of a React project created with Create React App or equivalent. The environment variable PUBLIC_URL can be used in the React application to reference assets in the public folder, e.g.

<script
  type="text/javascript"
  src="%PUBLIC_URL%/ChemDoodleWeb-9.4.0/install/ChemDoodleWeb.js"
></script>

In it's entirety, your React app'sindex.html file may look something like:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <link
      rel="stylesheet"
      href="%PUBLIC_URL%/ChemDoodleWeb-9.5.0/install/ChemDoodleWeb.css"
      type="text/css"
    />
    <link
      rel="stylesheet"
      href="%PUBLIC_URL%/ChemDoodleWeb-9.5.0/install/uis/jquery-ui-1.11.4.css"
      type="text/css"
    />
    <script
      type="text/javascript"
      src="%PUBLIC_URL%/ChemDoodleWeb-9.5.0/install/ChemDoodleWeb.js"
    ></script>
    <script
      type="text/javascript"
      src="%PUBLIC_URL%/ChemDoodleWeb-9.5.0/install/uis/ChemDoodleWeb-uis.js"
    ></script>
    <title>My React Application</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
  </body>
</html>

Only embed the scripts and CSS that you need for you project, though. ChemDoodle can now be called on component mount. Verify that the ChemDoodle is available in the project:

useEffect(() => {
  console.log(ChemDoodle.getVersion())
}, [])

Congrats! The ChemDoodle Web Components are now installed in your project! Now we are ready to render a molecule to the page. (Did you see the version logged to console twice? That is React.StrictMode 😉.)

3. Add CWC to package.json (optional)

The CWC package can be also optionally be listed as a peer dependency for visibility in your project. For example,

"peerDependencies": {
    "chemdoodleweb": "file:ChemDoodleWeb-9.5.0"
},

4. Install react-chemdoodle

npm install react-chemdoodle

5. Import the react CWC components

Import the components in your react application, pass it molecular data (MOL file format) as a prop, and style the canvas and molecular structure as desired:

import { ViewerCanvas } from 'react-chemdoodle'

function Caffeine() {
    const caffeine = // fetch molecular data

    return (
        <ViewerCanvas
            id="caffeine"
            data={{ mol: caffeine }}
            canvasStyle={{
                bonds_width_2D: 0.6,
                bonds_saturationWidthAbs_2D: 2.6,
                bonds_hashSpacing_2D: 2.5,
                atoms_font_size_2D: 10,
                atoms_font_families_2D: ['Helvetica', 'Arial', 'sans-serif']
            }}
            moleculeStyle={{
                scaleToAverageBondLength: 14.4
            }}
        />
    )
}

See the react-example-app (npm run start) in the react-chemdoodle monorepo for a full, working example.

Happy (chem) doodling!