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

@gumingcn/jsme-react

v1.0.1

Published

JSME React wrapper - use the JSME molecule editor as a React component

Downloads

1

Readme

@loschmidt/jsme-react

npm version npm downloads

This project wraps the BSD licensed JSME molecule editor (by B. Bienfait and P. Ertl) in a React component for easy use in React apps.

Please note that JSME was originally developed in Java and transpiled to Javascript. By modern Javascript standards it uses a few unconventional techniques to load. To accomodate this, this library will perform a side effect when the component is being loaded in the browser of appending the script tag that loads the JSME Javascript entrypoint (which will then trigger a few more loads). This works with lazy loading of Javascript modules.

If for some reason you want this loading to happen at a specific (early) point in time you can call the jsmeSetup function of this module which will perform the steps described above.

Prerequisites

  • React 17 or 18

Installation

npm install @loschmidt/jsme-react
# or
yarn add @loschmidt/jsme-react

Props

Required props

  • height: number or string, e.g. 300 or "300px"
  • width: number or string, e.g. 400 or "400px"

Optional props

  • options: string or array of strings. The available JSME options are described on the JSME documentation page
  • onChange: event handler that is passed the smiles whenever it is changed in the editor
  • smiles: the smiles to display (if not set, an empty canvas will be shown)
  • src: url of the jsme source code. Default value is "https://jsme-editor.github.io/dist/jsme/jsme.nocache.js"
  • setup: boolean telling whether JSME script should be loaded by the Jsme component, true - JSME script will be loaded once, false - JSME script will never be loaded, undefined (default) - JSME script will be loaded once, if was not previously loaded using a script element (included by you as library user).
  • disabled: boolean. When true, user is not able to interact and opacity is decreased

How to use

There are several ways how to load the underlying JSME library.

  1. Fully automatic (recommended).
  2. Use the jsmeSetup function.
  3. Add <script> tag into your HTML template.

1. Fully automatic (recommended)

import { Jsme } from '@loschmidt/jsme-react'

export default function App() {
  const logSmiles = (smiles) => {
    console.log(smiles)
  }
  return (
    <Jsme height={300} width={400} options="oldlook,star" onChange={logSmiles}/>
  )
}

JSME library will be loaded during rendering of the Jsme component.

You can use setup={true} but it's not necessary.

2. Use jsmeSetup

Before rendering a Jsme component, run the jsmeSetup function.

import { Jsme, jsmeSetup } from '@loschmidt/jsme-react'

// Load JSME library
jsmeSetup();

export default function App() {
  const logSmiles = (smiles) => {
    console.log(smiles)
  }
  return (
    <Jsme height={300} width={400} options="oldlook,star" onChange={logSmiles}/>
  )
}

You can use setup={false} but it's not necessary.

3. Add <script> into HTML

To avoid dynamic creation of script elements, you can include it into your HTML template.

<head>
  <!-- ... -->
  <script src="https://jsme-editor.github.io/dist/jsme/jsme.nocache.js" type="text/javascript"></script>
</head>
import { Jsme } from '@loschmidt/jsme-react'

export default function App() {
  const logSmiles = (smiles) => {
    console.log(smiles)
  }
  return (
    <Jsme height={300} width={400} options="oldlook,star" onChange={logSmiles}/>
  )
}

You can use setup={false} but it's not necessary.

Self-hosted JSME library

By default, JSME library is downloaded from https://jsme-editor.github.io/. If you want, you can use your copy by installing the jsme-editor package and serve it yourself.

npm install jsme-editor

Example for the Create React App framework:

// File: src/setupProxy.js

const express = require('express');
const path = require('path');

const jsmeEditorDir = path.dirname(require.resolve('jsme-editor'));

module.exports = function(app) {
  app.use(
    '/jsme',
    express.static(jsmeEditorDir)
  );
};

You can find a working example in the example directory.

Development

First terminal

# In the repository root

npm install
npm link
npm start

Second terminal

# In the "example" directory

npm install
npm link @loschmidt/jsme-react
npm start

License

BSD-3