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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ai-digital-factory/state-flow

v0.2.0

Published

React library for flow-style state (states, transitions, and related UI).

Readme

@ai-digital-factory/state-flow

React library for flow-style state (states, transitions, and related UI). See repository CONTEXT.md for domain vocabulary.

Flow authoring (TSX, no React app)

Flow-only projects declare flows as .tsx modules using Flow, State, FinalState, Transition and To, plus ParallelState, Region and FlowList for composition. They do not install react or @types/react.

A Flow is a static graph (ADR 0087). Each Transition lists its allowed destinations as <To> children, each describing when that destination is selected:

import {
  FinalState,
  Flow,
  State,
  To,
  Transition,
} from "@ai-digital-factory/state-flow";

export default function PlaceOrder() {
  return (
    <Flow name="place-order" description="One broker order." default="idle">
      <State name="idle" description="Not yet submitted.">
        <Transition name="submit-order" description="Send the order.">
          <To state="placed" description="The broker accepted it." />
          <To state="rejected" description="The broker rejected it." />
        </Transition>
      </State>
      <State name="placed" description="Open at the broker.">
        <Transition name="record-fill" description="The order filled.">
          <To state="filled" description="Always." />
        </Transition>
      </State>
      <FinalState name="rejected" description="Refused by the broker." />
      <FinalState name="filled" description="Filled." />
    </Flow>
  );
}
  • One <To> makes a fixed destination; its onTransition handler is optional. Several make the Transition branch; its handler module must export onTransition returning one of the destination names.
  • <FinalState> has no outgoing Transitions and no handlers. Reaching it completes the instance.
  • Flow check and the state-flow/flow-module ESLint rule reject Transitions without a <To>, unknown or repeated destinations, empty To descriptions, Transitions on a FinalState, and graphs that are not static JSX (conditional children, .map(...), computed props or elements built outside the Flow).
  • The diagram draws a branching Transition as one named segment into a split, with one branch per <To> labelled by its description. Final states use a distinct colour and a FINAL tag.

Composition: compound, parallel and FlowList (ADR 0095, 0096)

Larger lifecycles compose Flows declaratively. Nested States, regions and placed Flows are all part of the static graph; handlers never start child Flows.

<State name="signed-in" description="A user is signed in." default="dashboard">
  <State name="dashboard" description="Overview.">
    <Transition name="start-upload-batch" description="Upload files.">
      <To state="uploading" description="Always." />
    </Transition>
  </State>
  <State name="uploading" description="Each file uploads independently.">
    <FlowList name="uploads" flow="file-upload" description="One per file." />
    <Transition name="batch-finished" description="All done." trigger="done">
      <To state="dashboard" description="Always." />
    </Transition>
  </State>
  <ParallelState name="order-desk" description="Order and watchlist together.">
    <Region name="order" description="One order." flow="place-order" />
    <Region name="watchlist" description="Prices." default="watching">
      <State name="watching" description="Live prices." />
    </Region>
  </ParallelState>
  <Transition name="sign-out" description="Busy while work runs.">
    <To state="signed-out" description="Always." />
  </Transition>
  <Transition
    name="force-sign-out"
    description="Interrupt work."
    childWork="interrupt"
  >
    <To state="signed-out" description="Always." />
  </Transition>
</State>
  • A <State> with nested States and a default is compound; <State flow="x"> places one execution of Flow x from the same flows package. A <ParallelState> activates every <Region> and <FlowList> it contains.
  • Transitions reach only siblings in their own region. Declare a Transition that leaves a containing State on that State; it is available from every nested configuration.
  • childWork="block" (default) answers busy while descendant work is running or unresolved; childWork="interrupt" cancels it and proceeds. Neither undoes an external effect.
  • trigger="done" fires once every region completes, with each region's FinalState (and each FlowList member's) as payload. Completing a child never completes the root.
  • State and Transition names are unique across the whole flow file. The diagram tags composite States COMPOUND or PARALLEL, lists placed Flows and FlowList templates, and brackets nested States under their parent.

In the handlers package, a Flow declares its invocation input in src/<flow-id>/input.ts (export const inputSchema = z.strictObject({...})), read as context.input. A placing parent supplies it for a child, and the application passes it to ensureInstance({ instanceId, input }) for a root instance (ADR 0102). A composite State's handler exports children: { run, recovery }, which receives the entering Transition's payload and returns child inputs and FlowList members ({ uploads: [{ key, input }] }). Generated ChildInputs_<state> and Completion_<state> types describe both.

Migrating from the to prop

The to prop on Transition has been removed. Move the target into a <To> child and describe when it applies:

-<Transition to="present" name="unlock-succeeds" description="Correct credentials." />
+<Transition name="unlock-succeeds" description="Correct credentials.">
+  <To state="present" description="Always." />
+</Transition>

Recompile the flows package and its handlers package together: compiled flow artifacts move to schema version 2, generated TransitionContext types expose destinations instead of toState, and callback contexts expose dependencies instead of config. In each handlers package, rename src/<flow-id>/config.ts to dependencies.ts and its Config type to Dependencies; services import Dependencies instead of FlowConfig from the compiled module. Runtime types also lose their Durable prefix (ADR 0089), for example TransitionCallback instead of DurableTransitionCallback. Durable definition identities of flows without branching or final states are unchanged, so existing instances reopen.

The same release (ADRs 0089 and 0090) also renames and removes, without aliases:

  • @ai-digital-factory/state-flow-chart is now @ai-digital-factory/state-flow-definition; update dependencies and imports.
  • Presets: extend @ai-digital-factory/state-flow/tsconfig.flows.json and import eslint.flows.config.js (formerly tsconfig.charts.json, eslint.charts.config.js). The ESLint rule is state-flow/flow-module.
  • Rule IDs in state-flow.rules.json: state-chart.* is flow.*, application-hook.* is handler.*, and transition.name-unique-across-chart is transition.name-unique-across-flow.
  • Identifiers drop Application and use Flow/Handler, for example FlowDefinition, defineFlow, HandlerContext; data fields chartName/chartId are flowName/flowId, and compile output is under dist/flows/.
  • Services: await runtime.createFlow(compiled, dependencies), await flow.ensureInstance({ instanceId }), then when(state).transition(name).payload(value).run(handlers) (ADR 0107). The builder .handleFailure(...).run(), runtime.flow, handleCreate/handleOpen/handleEnsure, direct when(state).dispatch and DispatchError/OperationError are gone.

Extend the flow preset (TypeScript requires jsx for .tsx; the preset supplies it):

{
  "extends": "@ai-digital-factory/state-flow/tsconfig.flows.json",
  "include": ["src/**/*.tsx"]
}

Or set the same options yourself, including "types": ["@ai-digital-factory/state-flow/types"] and "jsx": "react-jsx".

Preview and in-app rendering supply React at runtime via the State Flow CLI or your React consumer.

License

Proprietary software. All third-party use requires prior written permission from [email protected]. See LICENSE.