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

@stacc/camunda-web-modeler

v1.0.4

Published

A browser-native BPMN and DMN modeler based on bpmn.io.

Downloads

2

Readme

Camunda Web Modeler

Screenshot

This is a React component based on bpmn.io that allows you to use a fully functional modeler for BPMN and DMN in your browser application. It has lots of configuration options and offers these features:

  • Full support for BPMN and DMN
  • Embedded XML editor
  • Easily import element templates
  • Full support for using bpmn.io plugins
  • Access to all bpmn.io and additional events to integrate it more easily into your application
  • Exposes the complete bpmn.io API
  • Includes type definitions for many of the undocumented features and endpoints of bpmn.io
  • TypeScript support

Usage

Getting Started

  1. Add this dependency to your application:
npm install @stacc/camunda-web-modeler
  1. Include it in your application:
import {
   BpmnModeler,
   CustomBpmnJsModeler,
   Event,
   isContentSavedEvent
} from "@stacc/camunda-web-modeler";
import React, { useCallback, useMemo, useRef, useState } from 'react';
import './App.css';

const App: React.FC = () => {
   const modelerRef = useRef<CustomBpmnJsModeler>();

   const [xml, setXml] = useState<string>(BPMN);

   const onEvent = useCallback(async (event: Event<any>) => {
      if (isContentSavedEvent(event)) {
         setXml(event.data.xml);
         return;
      }
   }, []);

   /**
    * ====
    * CAUTION: Using useMemo() is important to prevent additional render cycles!
    * ====
    */

   const modelerTabOptions = useMemo(() => ({
      modelerOptions: {
         refs: [modelerRef]
      }
   }), []);

   return (
      <div style={{
         height: "100vh"
      }}>
         <BpmnModeler
            xml={xml}
            onEvent={onEvent}
            modelerTabOptions={modelerTabOptions} />
      </div>
   );
}

export default App;

const BPMN = /* ... */;
  1. Include your BPMN in the last line and run the application!

Full example

To see all options available, you can use this example. Remember that it's important to wrap all options and callbacks that are passed into the component using useMemo() and useCallback(). Else you will have lots of additional render cycles that can lead to bugs that are difficult to debug.

Using the bpmnJsOptions, you can pass any options that you would normally pass into bpmn.io. The component will merge these with its own options and use it to create the modeler instance.

import {
    BpmnModeler,
    ContentSavedReason,
    CustomBpmnJsModeler,
    Event,
    isBpmnIoEvent,
    isContentSavedEvent,
    isNotificationEvent,
    isPropertiesPanelResizedEvent,
    isUIUpdateRequiredEvent
} from "@stacc/camunda-web-modeler";
import React, { useCallback, useMemo, useRef, useState } from 'react';
import './App.css';

const App: React.FC = () => {
    const modelerRef = useRef<CustomBpmnJsModeler>();

    const [xml, setXml] = useState<string>(BPMN);

    const onXmlChanged = useCallback((
        newXml: string,
        newSvg: string | undefined,
        reason: ContentSavedReason
    ) => {
        console.log(`Model has been changed because of ${reason}`);
        // Do whatever you want here, save the XML and SVG in the backend etc.
        setXml(newXml);
    }, []);

    const onSaveClicked = useCallback(async () => {
        if (!modelerRef.current) {
            // Should actually never happen, but required for type safety
            return;
        }

        console.log("Saving model...");
        const result = await modelerRef.current.save();
        console.log("Saved model!", result.xml, result.svg);
    }, []);

    const onEvent = useCallback(async (event: Event<any>) => {
        if (isContentSavedEvent(event)) {
            // Content has been saved, e.g. because user edited the model or because he switched
            // from BPMN to XML.
            onXmlChanged(event.data.xml, event.data.svg, event.data.reason);
            return;
        }

        if (isNotificationEvent(event)) {
            // There's a notification the user is supposed to see, e.g. the model could not be
            // imported because it was invalid.
            return;
        }

        if (isUIUpdateRequiredEvent(event)) {
            // Something in the modeler has changed and the UI (e.g. menu) should be updated.
            // This happens when the user selects an element, for example.
            return;
        }

        if (isPropertiesPanelResizedEvent(event)) {
            // The user has resized the properties panel. You can save this value e.g. in local
            // storage to restore it on next load and pass it as initializing option.
            console.log(`Properties panel has been resized to ${event.data.width}`);
            return;
        }

        if (isBpmnIoEvent(event)) {
            // Just a regular bpmn-js event - actually lots of them
            return;
        }

        // eslint-disable-next-line no-console
        console.log("Unhandled event received", event);
    }, [onXmlChanged]);

    /**
     * ====
     * CAUTION: Using useMemo() is important to prevent additional render cycles!
     * ====
     */

    const xmlTabOptions = useMemo(() => ({
        className: undefined,
        disabled: undefined,
        monacoOptions: undefined
    }), []);

    const propertiesPanelOptions = useMemo(() => ({
        className: undefined,
        containerId: undefined,
        container: undefined,
        elementTemplates: undefined,
        hidden: undefined,
        size: {
            max: undefined,
            min: undefined,
            initial: undefined
        }
    }), []);

    const modelerOptions = useMemo(() => ({
        className: undefined,
        refs: [modelerRef],
        container: undefined,
        containerId: undefined,
        size: {
            max: undefined,
            min: undefined,
            initial: undefined
        }
    }), []);

    const bpmnJsOptions = useMemo(() => undefined, []);

    const modelerTabOptions = useMemo(() => ({
        className: undefined,
        disabled: undefined,
        bpmnJsOptions: bpmnJsOptions,
        modelerOptions: modelerOptions,
        propertiesPanelOptions: propertiesPanelOptions
    }), [bpmnJsOptions, modelerOptions, propertiesPanelOptions]);

    return (
        <div style={{
            height: "100vh"
        }}>

            <button
                onClick={onSaveClicked}
                style={{
                    position: "absolute",
                    zIndex: 100,
                    top: 25,
                    left: "calc(50% - 100px)",
                    textTransform: "none",
                    fontWeight: "bold",
                    minWidth: "200px",
                    minHeight: "40px",
                    backgroundColor: "yellow",
                    borderWidth: "1px",
                    borderRadius: "4px"
                }}>
                Save Diagram
            </button>

            <BpmnModeler
                xml={xml}
                onEvent={onEvent}
                xmlTabOptions={xmlTabOptions}
                modelerTabOptions={modelerTabOptions} />
        </div>
    );
}

export default App;

const BPMN = /* .... */;

Usage with DMN

Usage with DMN is essentially the same. You just have to use the <DmnModeler> component instead. The API is very consistent between the two components.

Contributing 🙌

Contributions are always welcome! If you have any ideas or suggestions, please feel free to open an issue or submit a pull request.