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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@manifesto-ai/projection-ui

v0.3.0

Published

UI Projection layer for Manifesto AI - converts domain policies to UI states

Readme

@manifesto-ai/projection-ui

npm License: MIT

Framework-agnostic UI state projection for Manifesto AI

Transform domain policies into UI states automatically. The domain decides what (relevant, editable, required), and your UI decides how (visible, enabled, styled).

Installation

pnpm add @manifesto-ai/projection-ui @manifesto-ai/core

Core Concept

Domain policies are projected to UI states through a simple mapping:

| Domain Policy | UI State | Description | |--------------|----------|-------------| | relevance | visible | Should this field be shown? | | editability | enabled | Can the user interact with it? | | requirement | required | Must the user provide a value? |

import { projectFieldPolicy } from '@manifesto-ai/projection-ui';

const uiState = projectFieldPolicy(policy, runtime);
// {
//   visible: true,
//   enabled: false,
//   required: true,
//   validation: { valid: true, issues: [] },
//   meta: { path: 'data.email', label: 'Email' }
// }

Quick Start

Single Field Projection

import { projectFieldPolicy } from '@manifesto-ai/projection-ui';
import { fieldPolicy, condition } from '@manifesto-ai/core';

const emailPolicy = fieldPolicy({
  relevance: true,
  editability: condition({ $not: { $get: 'state.isSubmitting' } }),
  requirement: true,
});

const state = projectFieldPolicy(emailPolicy, runtime, 'data.email');

if (state.visible) {
  renderField({
    disabled: !state.enabled,
    required: state.required,
    error: state.validation.issues[0]?.message,
  });
}

Multiple Fields with ProjectionManager

import { createProjectionManager } from '@manifesto-ai/projection-ui';

const manager = createProjectionManager({
  runtime,
  domain,
  fields: {
    paths: ['data.name', 'data.email', 'data.phone'],
  },
  actions: {
    actionIds: ['submit', 'save', 'cancel'],
  },
});

// Get current state
const emailState = manager.getFieldState('data.email');
const submitState = manager.getActionState('submit');

// Subscribe to changes
const unsubscribe = manager.subscribeFields((states, changedPaths) => {
  changedPaths.forEach(path => {
    updateFieldUI(path, states.get(path));
  });
});

// Cleanup
manager.dispose();

API Reference

Field Projection

projectFieldPolicy(policy, runtime, path?)

Projects a single field policy to UI state.

const state = projectFieldPolicy(policy, runtime, 'data.email');

projectFieldPolicies(policies, runtime)

Projects multiple field policies at once.

const states = projectFieldPolicies({
  'data.name': namePolicy,
  'data.email': emailPolicy,
}, runtime);
// Map<string, UIFieldState>

Filter Utilities

import {
  filterVisibleFields,
  filterEnabledFields,
  getRequiredFields,
} from '@manifesto-ai/projection-ui';

const visible = filterVisibleFields(states);   // Only visible fields
const enabled = filterEnabledFields(states);   // Only enabled fields
const required = getRequiredFields(states);    // Only required fields

Action Projection

projectActionState(actionId, runtime)

Projects an action's availability state.

const state = projectActionState('submit', runtime);
// {
//   actionId: 'submit',
//   available: true,
//   unavailableReason: null,
//   executing: false,
//   preconditions: [
//     { conditionId: 'hasItems', satisfied: true },
//     { conditionId: 'isValid', satisfied: true },
//   ]
// }

Action Utilities

import {
  getAvailableActions,
  getUnavailableActions,
  setExecuting,
} from '@manifesto-ai/projection-ui';

const available = getAvailableActions(states);     // ['save', 'cancel']
const unavailable = getUnavailableActions(states); // [{ actionId: 'submit', reason: '...' }]
const executing = setExecuting(state, true);       // Mark as executing

Event Projection

Create UI events (toasts, notifications) from domain events:

import {
  createSuccessToast,
  createErrorToast,
  projectEvent,
} from '@manifesto-ai/projection-ui';

// Quick toast creation
const toast = createSuccessToast('Saved', 'Your changes have been saved');

// Or project from domain events
const uiEvent = projectEvent(domainEvent, {
  transformer: (event) => ({
    title: 'Order Created',
    message: `Order #${event.payload.id} confirmed`,
    severity: 'success',
  }),
});

manager.emitEvent(toast);

ProjectionManager

Full-featured manager for coordinating field, action, and event projections:

interface ProjectionManager {
  // Fields
  getFieldState(path: string): UIFieldState | undefined;
  getAllFieldStates(): Map<string, UIFieldState>;
  subscribeFields(listener: FieldStateListener): () => void;

  // Actions
  getActionState(actionId: string): UIActionState | undefined;
  getAllActionStates(): Map<string, UIActionState>;
  subscribeActions(listener: ActionStateListener): () => void;
  setActionExecuting(actionId: string, executing: boolean): void;

  // Events
  emitEvent(event: UIEvent): void;
  getPendingEvents(): UIEvent[];
  dismissEvent(eventId: string): void;
  subscribeEvents(listener: UIEventListener): () => void;

  // Lifecycle
  dispose(): void;
}

Framework Integration

This package provides framework-agnostic projection logic. For framework-specific bindings, create thin wrappers in your application or use bridge packages:

React Example

function useFieldState(manager: ProjectionManager, path: string) {
  const [state, setState] = useState(() => manager.getFieldState(path));

  useEffect(() => {
    return manager.subscribeFields((states, changed) => {
      if (changed.includes(path)) {
        setState(states.get(path));
      }
    });
  }, [manager, path]);

  return state;
}

Vue Example

function useFieldState(manager: ProjectionManager, path: string) {
  const state = ref(manager.getFieldState(path));

  onMounted(() => {
    const unsubscribe = manager.subscribeFields((states, changed) => {
      if (changed.includes(path)) {
        state.value = states.get(path);
      }
    });
    onUnmounted(unsubscribe);
  });

  return state;
}

Types

interface UIFieldState {
  visible: boolean;
  enabled: boolean;
  required: boolean;
  validation: {
    valid: boolean;
    issues: ValidationIssue[];
  };
  meta: {
    path: string;
    label?: string;
  };
}

interface UIActionState {
  actionId: string;
  available: boolean;
  unavailableReason: string | null;
  executing: boolean;
  preconditions: UIPreconditionState[];
}

interface UIEvent {
  id: string;
  title: string;
  message?: string;
  severity: 'success' | 'error' | 'warning' | 'info';
  channel?: string;
  timestamp: number;
  dismissed: boolean;
}

License

MIT © Manifesto AI