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

compose-editor

v0.2.0

Published

Yet another rich text editor thing.

Downloads

12

Readme

Compose

Compose is a rich text editor for the web. It’s still under development — it’s fairly stable, but there are still a few major issues that need to be resolved before it’s production-ready.

Contributing

If you like what you see, and would like to contribute, please do! Claim an issue as your own by commenting on it — see below for the very basics of how Compose works, and, beyond that, I’d be happy to answer any questions you may have.

Node.js and npm are needed for development on Compose. Clone the repository, then run npm install -D wherever you cloned Compose to, and you should good to go. Some useful shortcuts for once you’re all set up:

npm run dev: watches files and rebuilds Compose when they change. You can play around with your changes by opening test/functional/test.html in a browser; hitting the tab key will initialize an empty editor and focus it.

npm test: unsurprisingly, this runs the test suite. By default, tests are run in Firefox; to run the tests in Chrome, just do:

$ npm install karma-chrome-launcher
$ BROWSER=chrome npm test

How it works (the basics)

At the heart of Compose are two modules: serialize-elem and choice. The user’s selection is saved using choice, and the coordinates of that selection can then be used to manipulate rich text using serialize-elem. For example, say an user has entered text like so (the | denote the endpoints of a left-to-right selection):

<article contenteditable="true">
  <p>Stuff |and| things</p>
</article>

Now let’s suppose the user wants to make the selected text italic. We can accomplish this by first saving the selection, using choice; it will look like:

/**
 * These are the start and end points of the selection; it starts in
 * paragraph 0, after the sixth character, and ends in paragraph 0
 * after the ninth character.
 */
{
  start: [0, 6],
  end: [0, 9]
}

Now, we convert the selected paragraph into an instance of serialize-elem, which will allow us to work with it much more easily. We can then make text italic by using some of the serialization’s methods. What we essentially end up doing is:

var paragraph = new Serialize(thatParagraph)

paragraph.addMarkups({
  type: Serialize.types.italic,
  start: 6,
  end: 9
})

thatParagraph.parentNode.replaceChild(paragraph.toElement(), thatParagraph)

All that’s left is to restore the user’s saved selection using choice, resulting in:

<article contenteditable="true">
  <p>Stuff <em>|and|</em> things</p>
</article>

That’s the basic idea behind Compose. If you’d like to dig deeper, here and here are good places to get a better understanding of how it works in practice. If you have any questions, feel free to ask them via GitHub’s issue tracker — I’ll try and get back to you as soon as possible. There’s also a relatively thorough test suite, so, if you would like to see what a particular piece of code does, try commenting it out and see which tests start failing.

License

MIT.