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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@postnitro/embed

v1.0.7

Published

Add a full-fledged integrated postnitro editor to your website.

Downloads

112

Readme

Postnitro Embed

Add a full-fledged integrated Postnitro carousel maker to your website with ease.

Postnitro Embed is a small javascript library that allows you to seamlessly integrate a carousel maker into your web application. With its user-friendly API, you can enable your users to create and edit carousels directly from your website.

Installation

To install the Postnitro Embed package, run the following command:

pnpm add @postnitro/embed

Usage

Importing the Library

You can import the library in two ways:

  1. As a Module (Recommended for React, Next.js, and other modern frameworks)
import {createEditor} from "@postnitro/embed";
  1. As a Script (Traditional Way)

Add the following script tag to your HTML file:

<script src="https://cdn.jsdelivr.net/npm/@postnitro/embed/dist/index.umd.js"></script>

Obtaining an API Key

Before you can use the Postnitro Embed, you'll need to obtain an API key.

Follow these steps:

  1. Log in to your Postnitro account.
  2. Click on profile icon in the top right corner and select "Embed".
  3. Navigate to the "Embed" section.
  4. Add the domains where you'll be using the Postnitro Embed by clicking "Add Whitelist Domains". This ensures that the editor will only work on the whitelisted domains with the generated API key.
  5. Click "Generate API Key".
  6. Copy the generated API key.

Initialization

Before using the Postnitro Embed functionality, you need to initialize the editor instance.

Module Initialization

const editor = createEditor({
    apiKey: "your-api-key",
});

Script Initialization

When using the script, the editor is available as a global variable:

const editor = window.postnitroEmbed.createEditor({
    apiKey: "your-api-key",
});

Replace your-api-key with your actual API key provided by Postnitro.

Create a new carousel

To create a new carousel, call the createDesign method and provide a callback function to handle the export data:

editor?.createDesign((data: ExportData) => {
    console.log(data);
    // You can perform additional operations with the data, such as saving or displaying the carousel
});

Edit an existing carousel

To edit an existing carousel, call the editDesign method and provide the carousel ID and a callback function to handle the export data:

editor?.editDesign('your-carousel-id', (data: ExportData) => {
    console.log(data);
    // You can perform additional operations with the data, such as updating the existing carousel
});

Replace 'your-carousel-id' with the actual ID of the carousel you want to edit.

Understanding the ExportData type

The callback function receives an ExportData object, which contains the following properties:

interface ExportData {
    id: string; // Unique identifier for the carousel
    name: string; // Name of the carousel
    size: string; // Size of the carousel in aspect ratio (e.g., "16:9")
    pdf: Blob; // PDF file of the carousel
    images: Blob[]; // Array of image files for the carousel
}

You can use the provided data to save, display, or perform any other operations with the carousel.

Simple Example

Here's an example of how to integrate the Postnitro Embed library into your web application:

<!DOCTYPE html>
<html>
  <head>
    <title>Postnitro Embed Example</title>
  </head>
  <body>
    <button id="createCarouselBtn">Create Carousel</button>
    <button id="editCarouselBtn">Edit Carousel</button>

    <script src="https://cdn.jsdelivr.net/npm/@postnitro/embed/dist/index.umd.js"></script>
    <script>
      const editor = window.postnitroEmbed.createEditor({
        apiKey: "your-api-key",
      });

      const createCarouselBtn = document.getElementById("createCarouselBtn");
      const editCarouselBtn = document.getElementById("editCarouselBtn");

      createCarouselBtn.addEventListener("click", () => {
        editor.createDesign((data) => {
          console.log("New carousel created:", data);
          // Save or display the carousel data as needed
        });
      });

      editCarouselBtn.addEventListener("click", () => {
        const carouselId = "your-carousel-id";
        editor.editDesign(carouselId, (data) => {
          console.log("Carousel edited:", data);
          // Update the existing carousel with the new data
        });
      });
    </script>
  </body>
</html>

In this example, we're using the script import method and initializing the editor with an API key. We then attach click event listeners to two buttons: one for creating a new carousel and another for editing an existing carousel. When the buttons are clicked, the respective createDesign or editDesign method is called, and the export data is logged to the console.

Feel free to customize this example to fit your specific use case and integrate it into your application.