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

rn-reddit-editor

v0.1.9

Published

Rich text Reddit editor for React Native

Downloads

6

Readme

rn-reddit-editor

Rich text Reddit editor for React Native

Built on top of the excellent react-native-cn-quill package. ##NOTE: This is a work in progress!

Installation

npm install rn-reddit-editor

or

yarn add rn-reddit-editor

##Editor Props theme

Theme applied to the editor and toolbar

| Type | Required | |-----------------------|----------| | 'dark' or 'light' | Yes |


pickImage

Function invoked when user presses on the toolbar image icon. It is up to you to handle image selection.

| Type | Required | |--------------|----------| | () => void | No |


editorProps

react-native-cn-quill editor props

| Type | Required | |----------------------------------------------------------------------------------------------------------|----------| | EditorProps | No |


setHtml

Callback invoked when editor's HTML has changed

| Type | Required | |---------------------------|----------| | (html: string) => void | Yes |


accessToken

Reddit access token. Required if you want to allow embedded images. If this property is not specified, the toolbar will not include an image button.

| Type | Required | |----------|----------| | string | No |


##Editor Methods

addImage(url: string, caption?: string): Promise<any>

Embeds an image into the editor HTML. This should generally be invoked from within the pickImage callback.


focus()

Focuses the editor


blur()

Blurs the editor


getContents(): Promise<any>

Returns the inner Quill JSON content


dangerouslyPasteHTML(html: string): Promise<void>

Pastes the specified HTML into the editor


Usage

import { Editor, htmlToRichTextJSON, EditorHandle } from "rn-reddit-editor";

const App = () => {
  const editor = useRef<EditorHandle>();
  const [theme, setTheme] = useState('light');
  const [html, setHtml] = useState<string>();

  const _pickImage = async () => {
    // retrieve an image url
    const url = 'image.png',
        caption = 'My awesome caption!';
    // embed the image in the markup
    await editor?.current?.addImage(url, caption);
  }

  const _submit = async () => {
      // convert raw HTML to Reddit richtext JSON
      const richtextJSON = htmlToRichTextJSON(html);
      const formData = new FormData();
      // add richtext JSON to request body
      formData.append('richtext_json', JSON.stringify(richtextJSON));
      // ...
      await submitComment(formData);
  }

  const _toggleTheme = () =>
    setTheme(theme === 'light' ? 'dark' : 'light')

  return (
    <>
      <Editor
        theme={theme}
        ref={editor}
        pickImage={_pickImage}
        setHtml={setHtml}
        accessToken="<reddit_access_token>"
      />
      <Button onPress={_submit}>Submit</Button>
      <Button onPress={_toggleTheme}>Toggle Theme</Button>
    </>
  )
}

Attributions

Icons

Please adhere to the attribution rules according to www.flaticon.com and www.thenounproject.com.

  • Bold: https://www.flaticon.com/free-icon/bold_114304
  • Italic: https://www.flaticon.com/premium-icon/italics_2824288
  • Strikethrough: https://www.flaticon.com/premium-icon/strikethrough_2209539
  • Code block: https://www.flaticon.com/free-icon/code_984196
  • Code: https://www.flaticon.com/free-icon/coding_711284
  • Quote: https://www.flaticon.com/premium-icon/quote_4338295
  • Heading: https://www.flaticon.com/premium-icon/heading_4662543
  • Superscript: https://www.flaticon.com/premium-icon/superscript_4662634
  • Number list: https://thenounproject.com/icon/number-list-4161243/
  • Bullet list: https://thenounproject.com/icon/list-1247047/
  • Eraser: https://www.flaticon.com/premium-icon/eraser_2708461
  • Link: https://thenounproject.com/icon/link-2805275/
  • Clear format: https://thenounproject.com/icon/text-remove-format-120485/
  • Image: https://thenounproject.com/icon/image-777906/
  • Hide: https://www.flaticon.com/premium-icon/hidden_3287898
  • Close: https://www.flaticon.com/free-icon/close_2089733

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT