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

@zafuru/craftjs-liveblocks

v0.0.0-alpha

Published

Utilities for building a Liveblocks-backed collaboration layer on top of `@zafuru/craftjs-core`.

Readme

@zafuru/craftjs-liveblocks

Utilities for building a Liveblocks-backed collaboration layer on top of @zafuru/craftjs-core.

This package depends on Liveblocks, while @zafuru/craftjs-core itself remains unaware of Liveblocks and keeps its local-only mode unchanged.

What this package provides

  • Normalized document and lock types for a node-level collaboration model
  • A createCraftLiveblocksHooks(roomContext) factory for wiring your own Liveblocks createRoomContext(...) result into Craft
  • A createNodeLockingStore wrapper that enforces:
    • select-before-edit locking
    • guarded setProp / setCustom / setHidden / move / delete
    • local selection cleanup when remote locks are lost

What this package does not do

  • It does not add Liveblocks to @zafuru/craftjs-core
  • It does not create rooms or presence for you
  • It does not mutate Craft's core local mode

The intended usage is:

  1. Build a normal EditorStore with useEditorStore
  2. Create your own RoomContext with Liveblocks createRoomContext
  3. Call createCraftLiveblocksHooks(roomContext)
  4. Use the returned useCraftLiveblocksStore hook and pass its store into <Editor store={...} />

Hook factory

import { createRoomContext } from '@liveblocks/react';
import { createCraftLiveblocksHooks } from '@zafuru/craftjs-liveblocks';

const client = createClient({
  authEndpoint: '/api/liveblocks-auth',
});

const roomContext = createRoomContext(client);

const {
  RoomProvider,
  useMyPresence,
  useOthers,
  useSelf,
  useStorage,
  useMutation,
} = roomContext;

const { useCraftLiveblocksStore } = createCraftLiveblocksHooks(roomContext);

const { store, isReady, locksByNodeId } = useCraftLiveblocksStore({
  resolver,
  schemaVersion: 1,
  initialDocument,
});

This keeps local mode unchanged while allowing an external Liveblocks room to enforce exclusive node selection and editing.

Storage contract

createCraftLiveblocksHooks(roomContext) expects your room storage and presence to expose at least:

type Presence = {
  selectedNodeIds: string[];
  hoveredNodeId?: string | null;
  editingNodeId?: string | null;
  cursor?: { x: number; y: number } | null;
};

type Storage = {
  document: LiveblocksDocumentSnapshot | null;
  locks: Record<string, LiveblocksNodeLock>;
};

Complete example

import React from 'react';
import { createClient } from '@liveblocks/client';
import { createRoomContext } from '@liveblocks/react';
import { Editor, Frame, ROOT_NODE } from '@zafuru/craftjs-core';
import {
  createCraftLiveblocksHooks,
  LiveblocksDocumentSnapshot,
  LiveblocksNodeLock,
  LiveblocksPresence,
} from '@zafuru/craftjs-liveblocks';

const client = createClient({
  authEndpoint: '/api/liveblocks-auth',
});

type Presence = LiveblocksPresence;
type Storage = {
  document: LiveblocksDocumentSnapshot | null;
  locks: Record<string, LiveblocksNodeLock>;
};

const roomContext = createRoomContext<Presence, Storage>(client);
const { RoomProvider } = roomContext;
const { useCraftLiveblocksStore } = createCraftLiveblocksHooks(roomContext);

const resolver = {};

const initialDocument = {
  [ROOT_NODE]: {
    type: 'div',
    isCanvas: true,
    props: {},
    displayName: 'div',
    custom: {},
    parent: null,
    hidden: false,
    nodes: ['node-a'],
    linkedNodes: {},
  },
  'node-a': {
    type: 'div',
    isCanvas: false,
    props: {
      text: 'Hello Liveblocks',
    },
    displayName: 'div',
    custom: {},
    parent: ROOT_NODE,
    hidden: false,
    nodes: [],
    linkedNodes: {},
  },
};

function CollaborativeEditor() {
  const { store, isReady, isLockedByOther, getNodeLock } =
    useCraftLiveblocksStore({
      resolver,
      schemaVersion: 1,
      initialDocument,
      enabled: true,
      getUserId: (self) => self.id,
      getUserName: (self) => self.info?.name,
    });

  if (!isReady) {
    return <div>Loading...</div>;
  }

  return (
    <Editor store={store} resolver={resolver} enabled>
      <Frame />
    </Editor>
  );
}

export function App() {
  return (
    <RoomProvider
      id="craft-room:demo"
      initialPresence={{
        selectedNodeIds: [],
        hoveredNodeId: null,
        editingNodeId: null,
        cursor: null,
      }}
      initialStorage={{
        document: null,
        locks: {},
      }}
    >
      <CollaborativeEditor />
    </RoomProvider>
  );
}

In this setup:

  • local edits are translated into node-level document mutations
  • remote document changes are replayed back into the local Craft store incrementally
  • node locks live in shared storage and are enforced before selection or mutation