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

react-article-composer

v1.3.2

Published

A simple UI component for article composition with simply text and image paragraphs.

Downloads

3

Readme

About react-article-composer

This is a very simple UI component for composing blog posts or articles like content for ReactJS app. It only supports simply texts and images at the moment but very easy to get started with.

This module mainly reuses Chakra UI for React and ReactImageUploadComponent.

Click here for live Demo.

enter image description here

Getting Started

Install the module to to your React project:

npm i react-article-composer

Import it to the module you are using it:

import ReactArticleComposer from 'react-article-composer'

Usage

Place a ReactArticleComposer tag in the position which shows the component for the usage:

<ReactArticleComposer 
  editor={editorRef} 
  defaultContent={
    {hasTitle: false,
    paragraphs:[
      {"type":1,"content":"", "placeholder":"Please enter texts"},
    ]}
}
  imageURL={'a URL for loading default images'} 
  onTitleUpdate={(originalValue, newValue)=>{}} 
  onTextParagraphUpdate={(previousParagraphs, newParagraphs, index)=>{}}
  onTextParagraphAdd={(previousParagraphs, newParagraphs, index)=>{}}
  onImageParagraphAdd={(previousParagraphs, newParagraphs, index)=>{}}
  onTextParagraphDelete={(previousParagraphs, newParagraphs, index)=>{}}
  onImageParagraphDelete={(previousParagraphs, newParagraphs, index)=>{}}
  onImageAdd={(previousParagraphs, newParagraphs, index)=>{}}
  onImageDelete={(previousParagraphs, newParagraphs, imageIndex, paragraphIndex)=>{}}
  isSingleFile={bool}
/>

Note: In strict mode, there is UNSAFE_componentWillReceiveProps warning showing in the browser's console which is about a soon-be unsupported functions in React being used in FlipMove and ReactImageUploadComponent modules. Under the current React version, it has no impacts on functioning and will have to be solved within the upcoming version of React. We are looking for the updates from these two modules.

Attributes

SmartyPants converts ASCII punctuation characters into "smart" typographic punctuation HTML entities. For example:

| |Description | |----------------|-------------------------------------------------------------| |editor |a reference to the component, initialized with React.createRef() |
|defaultContent |preset content object being loaded for initialization, for example, {hasTitle: true, paragraphs:[{"type":1,"content":"","placeholder":"Please enter texts"},{"type":2}]}, it initializes the component with 2 paragraphs, type 1 representing a text paragraph with a specific placeholder text by setting placeholder property and type 2 representing an image paragraph, also with the title input available by setting hasTitle to true. For an image paragraph, you can preset an image resource by setting an image property like this: {"type":2, image:"flower.png"}, the base path can be set in imageURL attribute below.| |imageURL |a URL for loading pre-defined images as specified in defaultConent attribute.| |isSingleFile|represents whether the file upload widget only supports single file selection.| |uploadIconURL|sets the URL of the upload icon in file upload widget.| |textParagraphPlaceHolder|sets default placeholder text for all text paragraphs.| |onTitleUpdate|an event handler for the title was updated, with format: (originalValue, newValue)=>{}.| |onTextParagraphUpdate|an event handler for a paragraph was updated, with format: (previousParagraphs, newParagraphs, index)=>{}, where index is the paragraph index concerning the update. For example, you can get the previous and current values of the paragraph by accessing previousParagraphs[index] and newParagraphs[index] respectively.| |onTextParagraphAdd|an event handler for a new text paragraph was added, with format: (previousParagraphs, newParagraphs, index)=>{}, where the new text paragraph is newParagraphs[index].| |onImageParagraphAdd|similar to onTextParagraphAdd, an event handler for a new image paragraph was added, with format: (previousParagraphs, newParagraphs, index)=>{}, where the new image paragraph is newParagraphs[index].| |onTextParagraphDelete|an event hander for a text paragraph was deleted, with format: (previousParagraphs, newParagraphs, index)=>{}, where the deleted text paragraph is previousParagraphs[index].| |onImageParagraphDelete|similar to onTextParagraphDelete, an event handler for an image paragraph was deleted, with format: (previousParagraphs, newParagraphs, index)=>{}, where the deleted image paragraph is previousParagraphs[index].| |onImageAdd|an event handler for an image was added in a file upload widget in a specific image paragraph, with format: (previousParagraphs, newParagraphs, index)=>{}, where the related paragraph containing the file upload widget is either newParagraphs[index].| |onImageDelete|an event handler for an image was removed from a file upload widget in a specific image paragraph, with format: (previousParagraphs, newParagraphs, imageIndex, paragraphIndex)=>{}, where the deleted image is the imageIndex th image of previousParagraphs[paragraphIndex].|

Functions

| | | |--|--| | getComposition | get the composition object of the component, the object structure much similar to defaultContent. Usually, it can be called like this: editorRef.current.getComposition(), where editorRef is React.createRef() initialized. For an image paragraph in the single file selection mode, if a file is selected, there will be file (standard web File object), base64 (a string for embedding an image) and defaultImages properties. While in the multiple file selection mode, there will be fileDataSet and base64DataSet properties which are the sets to hold multiple File objects and base64 strings, with file and base64 properties being null. Try out the live Demo.| | setEnabled | enable the component. | | setDisabled | disable the component. |