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

cedit

v1.1.0

Published

📝 A simple way to edit content in react.

Downloads

350

Readme

About

Cedit is a component for react that uses the Content Editable feature for free editing of content within an HTML element. It is light and minimalist and aims to make the most of this wonderful resource in a clean and performative way.

Motivation

The content editable is an excellent and super useful feature that I needed to implement many times but I always faced some basic usage problems such as caret positioning, etc. And even with some components in the community implementing this feature, the same issues still exist! The objective of this implementation is to skip this step and deliver a simple component, at the same time powerful and with the basic functioning expected.

Installation

Cedit is a lightweight package with 0 dependencies.

Using NPM

npm i cedit

Using Yarn

yarn add cedit

Use

The component has a simple interface, you can import the CeditProps interface for better specification.

All handlers return a value of type Maybe<HTMLDivElement> with keys text, html and event.

Cedit

You can check a practical example in Demo.

import { useState } from 'react'
import { Cedit, CeditProps, Maybe } from 'cedit'

const App: React.FC = () => {
  const [value, setValue] = useState('')

  return (
    <Cedit
      value={value}
      placeholder="Type here..."
      onChange={({ text, html, event }) => setValue(html)}
    />
  )
}

Provider

If you want to control more than one editor, you can use CeditProvider to wrap all components and take advantage of features like autofocus. For now the provider does not offer extra features, but it will be implemented in the future.

import { Cedit, CeditProps, CeditProvider, Maybe } from 'cedit'

const App: React.FC = () => {
  return (
    <CeditProvider>
      {/* Editors */}
    <CeditProvider>
  )
}

| Property | Type | Description | | ----------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | id | string | Specifies a unique id for an HTML element. | | value | string | Can be plain text or html. | | spellCheck | boolean | Spell check. | | editable | boolean | Enable editing when focusing on component | | multiLine | boolean | When true allows line wrapping. | | style | React.CSSProperties | Custom styles. | | className | string | CSS class for styling. By default no styles are defined for the component, only resets basic settings. | | placeholder | string | A small tip, phrase, word, which is intended to help the user understand how to fill out that form. | | autoFocus | boolean | If enabled, the element receives focus automatically when displayed. | | placement | string | Editable content centering, the accepted values are: topStart, topCenter, topEnd, middleStart, middleCenter,middleEnd,bottomStart,bottomCenter and bottomEnd. | | onKeyUp | Maybe[T] | The keyup event fires when a key is released. | | onKeyDown | Maybe[T] | The keydown event is fired when a key is pressed. | | onKeyPress | Maybe[T] | The onkeypress event occurs when the user presses a key. | | onBlur | Maybe[T] | The onblur event occurs when an object loses focus. | | onFocus | Maybe[T] | The onfocus event occurs when an element gets focus. | | onChange | Maybe[T] | The onchange event occurs when the value of an element has been changed. | | onPaste | Maybe[T] | The onpaste event occurs when the user pastes some content in an element. |

Style

The component has no predefined styling, but exposes two main classes that you can use to style.

/* Container */
.cedit {
}

/* Content */
.cedit__content {
}

Contributing

Cedit is in an initial version without many features yet, but you can feel free to send your suggestion or open a PR.