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

smart-textarea-maa

v0.6.8

Published

react textarea component that supports cofigurable tagging/mentions

Downloads

44

Readme

Smart TextArea

A configurable markable react textarea component that supports multiple anchor types (people, things, places). And multiple part per anchor type for nested/dependant/parent,child/etc... senarios

Demo

e.g.

import 'smart-textarea-maa/lib/styles.css';
import { withSmartTextArea } from 'smart-textarea-maa';

const SmartTextArea = withSmartTextArea({
  version: 0, // the version for the markers will be set on all markers (helps managing old markers)
  anchors: [
    {
      anchorChar: '@',
      type: 'person',
      parts: [
        {
          key: 'person',
          endChar: ':',
          searchConfig: {
            // data: [...], you can send the data with an optional filter function
            // filterData: (data) => data.filter(...),
            loader: ({searchText}, signal) => personSearch(name, signal), // or provide a loader function.Note the first param is from getSearchData function if provided otherwise it defaults to {searchText, partsIds(the ids of the parts resolved so far)}, second param is signal to cancel seach
            ResultItemComponent: PersonSearchResultItem, // to display an item
            NoResultItemComponent,  // if none found, defaults to ResultItemComponent
            onItemSelect: ({selectedItem: person}) => ({  // very important to update marker/part on user selection/autoSelection
              text: person.name, // when an item is selected the text of it will change to what you specify by textValue
              id: person.id,
              // data: person, defaults to it anyways so no need to send if same
            }),
            debounceDuration: 350,
          },
          detailsConfig: {
            // findInSearchData, // if data is provided in search config this is needed
            loader: ({person: id}, signal) => personDetails(id, signal), // first param if from getLoadData if provided. defaults to partsIds. thats why the key is person same as current part id
            Component: PersonDetails,
            NotFoundComponent,
            getCacheKey: ({person: id}) => id, // defaults to JSON.stringify
            // shouldReloadData: (data) => data === undefined, // defaults to this anyways. use if not all needed fields are available from the search items
          },
        },
        // you can have multiple parts. see demo to get a feal for it
      ],
    },
    {
      anchorChar: '#',
      type: 'thing',
      parts: [
        {
          key: 'thing',
          searchConfig: {
            ResultsComponent: (
              {ResultListComponent, ...props} // gives flexibility to wrap ResultsList or get away with it completely
            ) => (
              <p>
                <h5>Found the following things:</h5>
                <ResultListComponent {...props} /> {/*will display a selectable list of the results using ResultItemComponent*/}
              </p>
            ),
            ResultItemComponent: ThingSearchResultItem,
            onItemSelect: ({selectedItem: thing}) => ({
              text: thing.name,
              id: thing.id,
            }),
            loader: ({searchText}, signal) => thingSearch(searchText, signal),
            getCacheKey: ({searchText}) => searchText?.trim().toLowerCase() || null,
            debounceDuration: 350,  // defaults to defaultDebounceDuration
          },
          detailsConfig: {
            Component: ThingDetails,
            loader: ({thing: id}, signal) => thingDetails(id, signal),
            getCacheKey: ({thing: id}) => id,
          },
        },
      ],
    },
  ],
  classNameGetters: {
    front: ({ isFirstLine, isLastLine, isTipVisible, isInEdit, marker }) => 'front-label-class',
    back: ({ isFirstLine, isLastLine, isTipVisible, isInEdit, marker }) => 'back-label-class',
    tip: ({ marker }) => 'marker-class',
  }
  ErrorComponent,     // default to "Loading..."
  LoaderComponent,    // defaults to displaying the error message or "Oops"
  hideTipOnEscape: true,  // defaults to true
  backgroundColor,    // default white
  lineHeight,         // default 135%
  width,              // defaults to not setting a width
  TextArea,           // base textarea to use
  tipsZIndex,         // tips z-index defaults to 99999999
  isAbortError: (error) => error.message.toLowerCase().includes('abort),
  debounceDuration: 500  // defaults to 300
});

... use it later

<SmartTextArea initValue={...} initMarkers={...} onChange={...} />