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

deepnotes-editor

v0.1.6

Published

`deepnotes-editor` is the editor used in [deepnotes.in](https://deepnotes.in). It's a clone of the [workflowy.com](https://workflowy.com) editor written in [draft-js](https://draftjs.org/). `deepnotes-editor` can be used as a react component.

Downloads

4

Readme

deepnotes-editor is the editor used in deepnotes.in. It's a clone of the workflowy.com editor written in draft-js. deepnotes-editor can be used as a react component.

Here's a codesandbox demo link - https://codesandbox.io/s/deepnotes-editor-demo-t4gnm

Here's a gif of how it works -

deepnotes editor demo

Why deepnotes-editor?

  • Supports infinitely nested lists
  • Every list item can be zoomed into. Therefore every list item can be thought of as a document in itself
  • Nested lists can be collapsed to reduce clutter
  • Powerful keyboard shortcuts so that you don't have to remove your hands from the keyboard when navigating the documents
  • Supports hashtags, automatic link detection and inline code block formatting
  • Bookmarking of any list item

Desktop only

deepnotes-editor doesn't work well on mobile browsers. That's because draft-js itself does not work well on mobile browsers.

Usage -

Install deepnoter-editor

npm install deepnotes-editor # or yarn add deepnotes-editor

Use anywhere in your react codebase

import Editor from 'deepnotes-editor';

// it will look like it's not working without the css
import 'deepnotes-editor/dist/deepnotes-editor.css';

// inside your dom heirarchy somewhere
<div>
  <Editor onChange={editorState => saveToDb(editorState)} />
</div>

How to save editor state?

You can use draft-js utilities to convert the EditorState returned from onChange prop. The prop returned is an immutable-js value.

import { convertToRaw } from 'draft-js'

function saveToDb(editorState) {
  const contentState = JSON.stringify(convertToRaw(contentState)),

  saveToDbOrLocalStorage(contentState);
}

How to get back editor state from the saved content state?

You can use convertFromRaw utility from draft-js to convert the content state json back to immutable-js EditorState. You have to use the createDecorators function which comes with deepnotes-editor so that the hashtags, links and code are highlighted properly.

import DeepnotesEditor, { createDecorators} from 'deepnotes-editor';
import 'deepnotes-editor/dist/deepnotes-editor.css';

const contentState = convertFromRaw(JSON.parse(backupContent));
const editorState = EditorState.createWithContent(
  contentState,
  createDecorators()
);

// inside your render function
return <div>
  <DeepnotesEditor
    initialEditorState={editorState}
    onChange={(changedEditorState) => saveToDb(changedEditorState)}}
  />
</div>

Customization or configuration

These are the props deepnotes-editor accepts

initialEditorState

This prop can be used to initialize the editor with some saved state. The state is of the type EditorState from draft-js. See draft-js documentation for more details - https://draftjs.org/docs/quickstart-api-basics#controlling-rich-text

P. S. - This component is not a controlled component. The state of the editor is maintained inside the component. If you change the zoomedInItemId, the editor will zoom into that item. But changing the initialEditorState between renders will not change the content of the editor to the new value of initialEditorState.

initialZoomedInItemId

If we want the editor to open zoomed in on some item. Very useful if you map the zoomedin items with urls and then if a user pastes or goes to a particular item directly, the editor can be also zoomed in to that item.

searchText

If you want to filter the items by some text

onChange

onChange is a function which is called with the new EditorState on every change. This can be used to save the new EditorState to local storage or to some persistent database.

onRootChange

This prop is called if the user zooms into a particular item. Please checkout workflowy.com to understand what zoom in means.

onBookmarkClick

If a user wants to bookmarks a particular zoomed in item. This can be used to build a bookmarking feature where the user can zoom to any of the bookmarked item.

withToolbar

If you don't want the menu/toolbar which shows up above the editor, you can set withToolbar to false.

Development

Install dependencies and start the build for the Editor component

npm install # or yarn install
npm start # or yarn start

This builds to /dist and runs the project in watch mode so any edits you save inside src causes a rebuild to /dist.

This does not start a server. It only watches your files and builds and puts them in dist folder when any file in src directory changes. To view the editor in action, you need to ru na server inside the example directory.

Then run the example inside another:

cd example
npm i # or yarn to install dependencies
npm start # or yarn start

The example is served on http://localhost:1234. If that port is busy, parcel might try starting the server on some other port.

The default example imports and live reloads whatever is in /dist, so if you are seeing an out of date component, make sure TSDX is running in watch mode like we recommend above. No symlinking required, we use Parcel's aliasing.

To do a one-off build, use npm run build or yarn build.

To run tests, use npm test or yarn test.