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

merchi_product_editor

v0.1.9

Published

A React component for editing product images using Fabric.js

Readme

Merchi Product Editor

A React-based product editor component that allows users to edit product templates using Fabric.js. This library enables customization of product designs through variations, template switching, and canvas manipulation.

Features

  • Multiple Template Support: Select and switch between different draft templates
  • Variation Management: Update canvas objects based on product variations
  • Responsive Design: Works on both desktop and mobile devices
  • Canvas Customization: Grid toggle, image upload
  • Context-based Architecture: Uses React Context API for state management
  • Type-safe: Written in TypeScript with proper type definitions

Installation

npm install merchi_product_editor

Usage

Basic Example

import { ProductEditor } from 'merchi_product_editor';

function App() {
  const product = {
    id: 1,
    name: "Sample Product",
    draftTemplates: [
      {
        id: 1,
        name: "Template 1",
        file: {
          viewUrl: "https://example.com/template1.jpg"
        },
        width: 800,
        height: 600
      }
    ]
  };

  const variations = [
    {
      variationField: {
        id: 1,
        fieldType: "TEXT_INPUT"
      },
      value: "Sample Text"
    }
  ];

  const handleSave = () => {
    // Handle save action
    console.log('Saved product design');
  };

  const handleCancel = () => {
    // Handle cancel action
    console.log('Editing cancelled');
  };

  return (
    <ProductEditor
      product={product}
      job={{id: 1}}
      width={800}
      height={600}
      onSave={handleSave}
      onCancel={handleCancel}
      variations={variations}
      groupVariations={[]}
    />
  );
}

Using the Context API

You can access the editor's context in child components:

import { useProductEditor } from 'merchi_product_editor';

function CustomButton() {
  const { handleSave, updateCanvasFromVariations } = useProductEditor();
  
  const handleUpdate = () => {
    const newVariations = [/* updated variations */];
    updateCanvasFromVariations(newVariations);
  };

  return (
    <button onClick={handleUpdate}>Update Design</button>
  );
}

Props

| Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | product | Product | Yes | - | Merchi Product entity containing draft templates | | job | Job | Yes | - | Job information | | width | number | No | 800 | Width of the editor canvas | | height | number | No | 600 | Height of the editor canvas | | onSave | () => void | Yes | - | Callback function when saving the edited image | | onCancel | () => void | Yes | - | Callback function when canceling the edit | | variations | Variation[] | Yes | [] | Array of variations to apply to the templates | | groupVariations | Variation[] | Yes | [] | Array of group variations to apply | | fontOptions | FontOption[] | No | Default list | Custom fonts for text toolbar | | colorPalette | (string | null)[][] | No | Default palette | Custom color palette for text toolbar |

Context API

The useProductEditor hook provides access to the following properties and methods:

| Property/Method | Type | Description | |----------------|------|-------------| | canvas | fabric.Canvas | The Fabric.js canvas instance | | draftTemplates | Array | Available draft templates with associated variation objects | | selectedTemplate | number | ID of the currently selected template | | handleTemplateChange | Function | Method to switch between templates | | showGrid | boolean | Whether the grid is currently displayed | | setShowGrid | Function | Toggle grid visibility | | showPreview | boolean | Whether the preview area is displayed | | togglePreview | Function | Toggle preview area visibility | | canvasObjects | Map | Map of canvas objects indexed by variation field ID | | updateCanvasFromVariations | Function | Update canvas objects based on changed variations |

ImageGallery Component

The ImageGallery component provides a simple way to display images in your product editor when other images fail to load.

import { ImageGallery } from 'merchi_product_editor';

function Example() {
  return (
    <ImageGallery 
      fallbackImageUrl="https://example.com/default-image.jpg"
    />
  );
}

Props for ImageGallery

| Prop | Type | Required | Default | Description | |------|------|----------|---------|-------------| | fallbackImageUrl | string | No | null | URL to an image that will be displayed when the primary image fails to load |

The ImageGallery component is designed to be simple and focused on providing fallback functionality for image loading errors.

Development

# Install dependencies
npm install

# Start development server
npm start

# Build the library
npm run build

# Run tests
npm test

License

MIT