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

@typed-mxgraph/typed-mxgraph

v1.0.8

Published

mxGraph typescript declarations

Downloads

5,347

Readme

Typed mxGraph

Build npm version GitHub license

mxGraph Typescript Declarations For Official mxGraph NPM Package.

Usage

  1. Add mxgraph and @typed-mxgraph/typed-mxgraph dependencies to your project:

    npm:

     npm install --save mxgraph
     npm install --save-dev @typed-mxgraph/typed-mxgraph

    yarn:

    yarn add mxgraph
    yarn add --dev @typed-mxgraph/typed-mxgraph
  2. Update tsconfig.json append node_modules/@typed-mxgraph to typeRoots:

    {
      "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "esModuleInterop": true,
        "typeRoots": [
          "node_modules/@types",
          "node_modules/@typed-mxgraph"
        ]
      }
    }
  3. Import mxGraph factory:

    import factory from 'mxgraph';
    
    const mx = factory({
      mxBasePath: '',
    });
    console.log(mx.mxClient.VERSION);
  4. (optional) Create a helper to import mxgraph

    // src/mxgraph.ts
    import factory from 'mxgraph';
       
    declare global {
      interface Window {
        mxBasePath: string;
        mxLoadResources: boolean;
        mxForceIncludes: boolean;
        mxLoadStylesheets: boolean;
        mxResourceExtension: string;
      }
    }
    
    window.mxBasePath = 'assets/mxgraph';
    window.mxLoadResources = true;
    window.mxForceIncludes = false;
    window.mxLoadStylesheets = true;
    window.mxResourceExtension = '.txt';
    
    export default factory({
      // not working see https://github.com/jgraph/mxgraph/issues/479
      mxBasePath: 'assets/mxgraph',
    });
    // src/application.ts
    import mx from './mxgraph';                       // <- import values from factory()
    import type { mxGraph, mxGraphModel } from 'mxgraph';  // <- import types only, "import type" is a TypeScript 3.8+ syntax
    
    export class Application {
    
      constructor(container: HTMLElement) {
        if(mx.mxClient.isBrowserSupported()) {
          console.log('Yes! Yes!');
        }
    
        const graph: mxGraph = new mx.mxGraph(container);
        const model: mxGraphModel = graph.getModel();
        model.beginUpdate();
        try {
          graph.insertVertex(graph.getDefaultParent(), '', 'TEST', 0, 0, 100, 100);
        } finally {
          model.endUpdate();
        }
      }
    
    }

There a known issues is https://github.com/typed-mxgraph/typed-mxgraph/issues/50 the error message may look similar to

Uncaught TypeError: Cannot set properties of undefined (setting 'mxBasePath')

For detailed reasons, please refer to:

  • https://github.com/typed-mxgraph/typed-mxgraph/issues/50#issuecomment-1114008885
  • and https://github.com/typed-mxgraph/typed-mxgraph/issues/50#issuecomment-1120176914

Demos:

  • https://github.com/typed-mxgraph/typed-mxgraph-example-bundled-with-rollup
  • https://github.com/typed-mxgraph/typed-mxgraph-example-bundled-with-webpack

Implementation

Types have been initially created from mxGraph 4.1.0 by hand (1st hosting repository was mxgraph-type-definitions) and progressively updated when new mxgraph versions have been released.

The mxgraph lib is almost fully covered by types in this project. The issues you may encounter are

  • API changes in recent mxgraph have not been reported. We haven't decided how we will manage this in the future, so for now, they are updated when user detect issues
  • Function arguments types or 'mandatoriness' may not be accurate: even by reading the JS code, it is sometimes hard to figure out what is the correct type.
  • Historically, we try to avoid any and use optional when we don't know.
  • We expect user to provide feedbacks by creating GitHub issues and/or Pull Requests when they notice issue with the types.

Implementation Progress

The definitions target mxGraph 4.2.2. See the implementation status in the following table.

  • progress: initial support
    • not yet: no support at all
    • partial: implementation started, but some classes/fields/methods are missing
    • completed: all classes/fields/methods should exist (fill an issue and/or provide a Pull Request if you detect an issue) but
      • TSDoc is not fully accurate
      • some type declaration may be wrong
  • checked: a finest review has been conducted about TSDoc, mxGraph types used by functions/methods, fields, ...

| Module | Progress | Checked | |:---------------|:---------:|:-------:| | editor | partial | no | | handler | completed | no | | io | completed | no | | layout | completed | no | | model | completed | no | | shape | completed | no | | util | partial | no | | view | partial | no | | mxClient.d.ts | completed | no |

Development

Also See

We are actively developing, if you want to be a contributor, please refer to the following links