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

useblocks

v1.0.37

Published

> It is a Dev version of the Blocks email builder plugin.<br>The Prod version that will be released in the nearest future will have minor differences: it will not contain experimental features and the whole already existing feature set will be tested way

Downloads

1,307

Readme

It is a Dev version of the Blocks email builder plugin.The Prod version that will be released in the nearest future will have minor differences: it will not contain experimental features and the whole already existing feature set will be tested way more thoroughly before the releases.

Installation

Run this code in the command prompt:

$ npm i [email protected] -save

Add the Blocks plugin to your App config.

For the Webpack module bundler

Package import:

const useblocksPlugin = require('useblocks/webpack')

Defining the package in the app:

module.exports = {
	plugins: [
		new UseblocksWebpackPlugin(),
	]
}

For the Vite module bundler

Package import:

import useblocksPlugin from 'useblocks/vite'

Defining the package in the app:

export default defineConfig({
	plugins: [useblocksPlugin()],
})

Initialization

Import the Blocks plugin into your component:

import * as useblocks from "useblocks"

The Plugin configuration contains a parameter named getAuthToken. For authorization, you must pass the application's OAuth token to its value. For debugging purposes, the dev version of the plugin supports a mechanism for obtaining a token from the front of the application. To use this mechanism you need first to define auth-proxy in AppConfig:

Fetching the OAuth token on the backend

curl --location 'https://api.useblocks.io/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=*******' \
--data-urlencode 'client_secret=*******' \
--data-urlencode 'grant_type=client_credentials'

Creating the Blocks plugin entity

useblocks.init({
	getAuthToken: getAuthToken,
	element: "#test",
	content: {
		title: "Email subject",
		html: "EMAIL_CODE",
	},
	config: { }
}).then(instance => {  })

You can get the EMAIL_CODE from our example or paste the HTML code of your own email

Configuration

Plugin configuration is JSON with several nesting levels. In the config you can set the appearance, content, and the logic the plugin will work with.

Element

You can send the element line into the plugin configuration. It is a DOM element selector and you need to initiate the plugin inside of it. If the element is not defined, the app will run in the background mode.

Content

The content section contains parameters of an email that must be displayed in the editor. This is what can be sent to this parameter:

{string}

HTML code of an email.

{object} email options

{
	id?: string; // A unique ID of a project in your system.
	html?: string; // HTML code of an email.
	subject?: string; // Email subject line.
	preheader?: string; // Email preheader.
}

{object} full description

{
	temlateId?: string; // Email template ID in Blocks.
	email?: object; // email options.
	blocks?: []; // Additional blocks.
	comments?: []; // Comments in an email.
}

You can change the content at any moment after the initialization with the help of the instance.show(content) method.

Config

This section is dedicated to setting the appearance and settings of the editor. You can change the configuration of this section after the initialization with the help of useblocks.setConfig or useblocks.updateConfig.

The list of parameters of the config section

| Parameter | Description | Default | | ---------------------- | --------------------------------- | ------- | | theme | Plugin theme: light, dark. | light | | headerArrowBackVisible | Displaying the "Back" arrow. | true | | headerTitleVisible | Displaying the "Title" field. | true | | headerPreheaderVisible | Displaying the "Preheader" field. | true | | pathEnabled | Bread crumbs | true | | ... | ... | ... |

Events

Events can be sent to configurations or added to them later while working with the instance of the plugin. All event subscribers can be asynchronous features.

Example

useblocks.init({
	....,
	// Subscription to events in the initialization.
	handleReadEmail: (e) => {},
	handleSaveEmail: async (e) => {}
}).then((instance) => {
	// Subscription to events after the initialization.
	const dispose = instance.handleReadEmail(e => {});
	const dispose = instance.handleSaveEmail(async (e) => {});
});

By sending the asynchronous feature you can implement the asynchronous data load.

Example

useblocks.init({
	element: "#test",
	content: {
		id: "1"
	}
	handleReadEmail: async (id) => {
		return await  fetchData(id); // Your data fetch feature.
	}
}).then((instance) => { 
	setTimeout(() => instance.show({ id: "2" }), 1000)
});

Events

| Name | Description | | ------------------------- | -------------------------------------------- | | handleReadEmail | read email handler | | handleSaveEmail | fires when email saved | | handleReadEmailAutoSaves | read autosaves handler | | handleEmailAutosave | fires when email autosave | | handleRemoveEmailAutoSave | fires when email autosave delete | | handleReadBlocks | read blocks handler | | handleSaveBlock | fires when block save | | handleRemoveBlock | fires when block delete | | handleReadComments | read comments handler | | handleSaveComment | fires when comment save | | handleRemoveComment | fires when comment delete | | handleSaveButtonClick | fires when user clicked on 'save' button | | handleNextButtonClick | fires when user clicked on 'next' button | | handlePreviousButtonClick | fires when user clicked on 'previous' button | | handleEmailInit | fires when email iframe inited | | handleEmailChanged | fires when email changed | | handleHtmlChanged | fires when email Html changed | | handleDestroy | fires when app destroyed | | handleLoad | fires when app loaded | | handleLoadImage | fires when image loading |

Methods

| Method name | Description | | ------------------------- | -------------------------------------------- | | init | Initialization (async) | | show | Altering the content after the initialization| | destroy | Destruction of the instance of the plugin | | reset | Resetting the whole configuration | | getEmail | Getting the current email | | getConfig | Getting the configuration | | getBlocks | Getting the blocks from the project | | getComments | Getting the commentaries for the email | | getEmailRevisions | Getting the list of the email revisions | | setConfig | Setting new config parameters | | updateConfig | Updating config parameters | | notify | Notifications display | | getElement | Getting an element of initialization | | save | Saving an email | | compileEmail | Get compiled email |

Keywords

none