Sequential Workflow Designer

repository·main·Indexed 23 days ago

https://github.com/nocode-js/sequential-workflow-designer

A visual tool for designing sequential workflows. It provides a core TypeScript/JavaScript library and dedicated wrappers for Angular, React, and Svelte. The designer allows for the creation of workflow definitions with customizable toolboxes, step configurations, and custom editor interfaces for root and individual step properties.

Tokens
13.2K
Snippets
29
Records
59
Agent score
59%

What's inside sequential-workflow-designer

  1. How to initialize and wrap a workflow definition

    main

    Before passing a workflow definition to the designer, it must be wrapped using the wrapDefinition function. This ensures the definition is in the format expected by the designer's internal state management. It is recommended to use useState to manage the wrapped definition and useMemo for configuration objects to prevent unnecessary re-renders.

    import { Definition, ToolboxConfiguration, StepsConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer';
    import { SequentialWorkflowDesigner, wrapDefinition, useRootEditor, useStepEditor } from 'sequential-workflow-designer-react';
    
    // 1. Define the raw definition
    const startDefinition: Definition = { /* ... */ };
    
    // 2. Wrap it and store in state
    const [definition, setDefinition] = useState(() => wrapDefinition(startDefinition));
    
    // 3. Memoize configurations
    const toolboxConfiguration: ToolboxConfiguration = useMemo(() => ({ /* ... */ }), []);
    const stepsConfiguration: StepsConfiguration = useMemo(() => ({ /* ... */ }), []);
    const validatorConfiguration: ValidatorConfiguration = useMemo(() => ({ /* ... */ }), []);
  2. Basic Usage of SequentialWorkflowDesigner in Svelte

    main

    To implement the designer, import the SequentialWorkflowDesigner component and provide a definition, configuration objects (steps, toolbox, validator), and a handler for definition changes. The on:definitionChanged event provides both the updated definition and its isValid status.

    <script lang="ts">
      import { SequentialWorkflowDesigner } from 'sequential-workflow-designer-svelte';
      import type { Definition, StepsConfiguration, ToolboxConfiguration, ValidatorConfiguration } from 'sequential-workflow-designer';
    
      let definition: Definition = { ... };
      let isValid: boolean | null = null;
    
      const steps: StepsConfiguration = { /* ... */ };
      const toolbox: ToolboxConfiguration = { /* ... */ };
      const validator: ValidatorConfiguration = { /* ... */ };
    
      function onDefinitionChanged({ detail }: { detail: { definition: Definition, isValid: boolean } }) {
        definition = detail.definition;
        isValid = detail.isValid;
      }
    </script>
    
    <SequentialWorkflowDesigner
      theme="light"
      definition={definition}
      on:definitionChanged={onDefinitionChanged}
      steps={steps}
      toolbox={toolbox}
      validator={validator} />
  3. Run Sequential Workflow Designer examples locally

    main

    To run the provided examples on your local machine, you must first install dependencies and build the project packages. Follow these steps from the root of the repository:

    1. Install dependencies: yarn install
    2. Build all packages: yarn build
    3. Start the local HTTP server: yarn serve
    4. Access the examples at http://127.0.0.1:8080/examples/ in your browser.
    yarn install
    yarn build
    yarn serve
  4. Install Sequential Workflow Designer for Svelte

    main

    To use the Svelte wrapper, install both the core designer package and the Svelte wrapper via npm:

    npm i sequential-workflow-designer sequential-workflow-designer-svelte

    Additionally, you must import the required CSS files into your global CSS file to ensure the designer renders correctly:

    @import 'sequential-workflow-designer/css/designer.css';
    @import 'sequential-workflow-designer/css/designer-light.css';
    @import 'sequential-workflow-designer/css/designer-dark.css';
  5. Configure local development dependencies for the Angular Demo

    main

    If you are developing the core packages and want the Angular demo to use your local changes instead of published versions, update the dependencies in the demo's package.json to point to your local build directories:

    "dependencies": {
      "sequential-workflow-designer": "file:../../designer",
      "sequential-workflow-designer-angular": "file:../../angular/designer-dist"
    }

    After updating the file, run the following command to force the installation of the local files:

    yarn install:force

    "dependencies": {
      "sequential-workflow-designer": "file:../../designer",
      "sequential-workflow-designer-angular": "file:../../angular/designer-dist"
    }
    yarn install:force
  6. Install Sequential Workflow Designer via NPM

    main

    To use the designer in a TypeScript or JavaScript project, install the package using npm:

    npm i sequential-workflow-designer

    After installation, import the Designer class:

    import { Designer } from 'sequential-workflow-designer';

    If you are using a bundler like Webpack with css-loader, you should also import the required CSS files to ensure the designer renders correctly:

    import 'sequential-workflow-designer/css/designer.css';
    import 'sequential-workflow-designer/css/designer-light.css';
    import 'sequential-workflow-designer/css/designer-soft.css';
    import 'sequential-workflow-designer/css/designer-dark.css';
  7. Register Custom Editors in SequentialWorkflowDesigner

    main

    To use your custom Root and Step editors, pass them as props to the SequentialWorkflowDesigner component using the rootEditor and stepEditor keys.

    <script lang="ts">
      import StepEditor from './step-editor.svelte';
      import RootEditor from './root-editor.svelte';
    </script>
    
    <SequentialWorkflowDesigner
      ...
      stepEditor={StepEditor}
      rootEditor={RootEditor} />
  8. Install Sequential Workflow Designer for Angular

    main

    To use the Angular wrapper, you must install both the core designer package and the Angular wrapper package via NPM. Additionally, you must include the required CSS files in your angular.json configuration to ensure the designer renders correctly.

    npm i sequential-workflow-designer sequential-workflow-designer-angular

    In angular.json:

    {
      "projects": {
        "YOUR_APP": {
          "architect": {
            "build": {
              "styles": [
                "./node_modules/sequential-workflow-designer/css/designer.css",
                "./node_modules/sequential-workflow-designer/css/designer-light.css",
                "./node_modules/sequential-workflow-designer/css/designer-dark.css"
              ]
            }
          }
        }
      }
    }
  9. Implement Root and Step Editors using ng-template

    main

    The designer uses Angular templates to render custom editor interfaces for the workflow root and individual steps. These templates receive a context object that allows you to bind data and notify the designer of changes.

    Root Editor

    The root editor template receives a variable implementing the RootEditorWrapper interface. Use editor.context (of type RootEditorContext) to notify the designer when properties change.

    Step Editor

    The step editor template receives a variable implementing the StepEditorWrapper interface. Use editor.context (of type StepEditorContext) to notify the designer when step properties or names change.

    To ensure the designer stays in sync with your UI, you must call context.notifyPropertiesChanged() or context.notifyNameChanged() after updating the underlying data model.

    <!-- Root Editor Template -->
    <ng-template #rootEditor let-editor>
      <h2>Root Editor</h2>
      <h3>Velocity</h3>
      <input type="number"
        [value="editor.definition.properties.velocity"
        (input)="updateProperty(editor.definition.properties, 'velocity', $event, editor.context)" />
    </ng-template>
    
    <!-- Step Editor Template -->
    <ng-template #stepEditor let-editor>
      <h2>Step Editor</h2>
      <h3>Name</h3>
      <input type="text"
        [value="editor.step.name"
        (input)="updateName(editor.step, $event, editor.context)" />
    
      <h3>Velocity</h3>
      <input type="number"
        [value="editor.step.properties.velocity"
        (input)="updateProperty(editor.step.properties, 'velocity', $event, editor.context)" />
    </ng-template>