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

altos-text-editor

v0.3.2

Published

[![npm](https://img.shields.io/npm/v/altos-text-editor)](https://www.npmjs.com/package/altos-text-editor)

Downloads

10

Readme

npm

Overview

This project is a Markdown editor library. Thanks to it, it is possible to use Markdown in a simple and pleasant way. It is written using React, styled-components. React-hook-form was used to render forms alogn with yup. It's basically a Milkdown wrapper, but by using it you don't have to configure and install all the plugins you need because this library does everything for you, no configuration required.

The newest test version should be released there -> example page

Using library

Simply run:

yarn add altos-text-editor

and then import TextEditor

Note that this library has its own state and cannot be overwritten! If you don't want to create another state, you may always use useRef and pass ref to the TextEditor. There is getValue function that will return actual text of the text editor.

import 'altos-text-editor/dist/style.css';

import { TextEditor } from 'altos-text-editor';

type AltosTextEditorProps = {
    text: string
    onSave: (text: string) => void
}

const AltosTextEditor: React.FC<AltosTextEditorProps> = ({ text, onSave }) => {
  const [editorText, setEditorText] = useState(text);

  const onDataChange = useCallback((value: string) => {
      setEditorText(value);
  }, [])
  
  const onSaveButtonClick = () => {
    onSave(editorText)
  }  
  
  return (
    <div>
        <TextEditor data={text} mode="active" onDataChange={onDataChange} />
        <button onClick={onSaveButtonClick}>Save</button>
    </div>
  )
}

Server Side Rendering

This library cannot be rendered on the server! That's why it's important to render it only on the client side.

So basically.. the library will never and should not be rendered on the server.

How to use it with Next.js? It's not the best solution. We shouldn't use lazy loading components in this case, but it's a "now" solution. In the future, this must be changed and a better solution must be found

  • yarn add altos-text-editor
  • Create a new component
import 'altos-text-editor/dist/style.css';

import { TextEditor } from 'altos-text-editor';

const AltosTextEditor: React.FC = () => {
  const onDataChange = useCallback(() => {}, [])

  return (
    <TextEditor data="" mode="active" onDataChange={onDataChange} />
  )
}

export default AltosTextEditor;
import dynamic from 'next/dynamic'

const AltosTextEditorDynamic = dynamic(() => 
  import('<--path_to_the_component->'), {
    loading: () => <p>Loading...</p>,
    ssr: false,
  }
)

export default function MyComponent() {
  return (
    <div>
      Hello!
      <AltosTextEditorDynamic />
    </div>
  )
}

https://github.com/Milkdown/milkdown/issues/389#issuecomment-1050468759

Preparation and starting the application

For consistency and to ensure that each developer uses the same version of Node.js, we used nvm (How to install nvm on macos).

Installation

  1. cd /your_path
  2. git clone [email protected]:DareData/notion-style-editor.git
  3. cd notion-style-editor
  4. nvm use
  5. yarn
  6. yarn prepare
  7. yarn start

Deploying to Github Pages

If you want to share the current state of the library with external people, you can use Github Pages where a test version is placed for testing by testers.

To add a new version, you just need to run the following commands:

  1. yarn build:pages
  2. git commit -m"<--any_commit_message-->"
  3. git push origin <--your_branch-->

Just remember that the changes you upload should be visible on github pages, your changes should be in the same branch on which github pages is currently "listening". Here you can check on which branch github is currently listening for changes.

Buling library

If you want to build a library to be used by external applications, you need to run the following commands:

  • yarn build

Your library has been created in the dist folder.

Troubleshoots

The editor keeps re-rendering

Check, whether onDataChange and data do not change their reference. When one of them changes, the old editor is "unmounted" and a new one is "mounted". https://blog.logrocket.com/understanding-react-exhaustive-deps-linting-warning/

The bundle size is quite large

Unfortunately after using https://github.com/btd/rollup-plugin-visualizer, I noticed that both of these plugins are around 4MB

  • https://milkdown.dev/docs/api/plugin-diagram
  • https://milkdown.dev/docs/api/plugin-math

In addition, fonts take up quite a lot of space.

Moreover.. the code is not minified yet, so 60% of the size will be reduced. Also remember about compression, which will also reduce the size of the package. https://github.com/Milkdown/milkdown/issues/389#issuecomment-1050468759

There is no documentation! How may I know, which props should I use?

Documentation is missing, however feel free to contribute and create that one :)