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

@djsp/core

v0.1.5

Published

djsp Core Components

Downloads

46

Readme

@djsp/core

Draft Js Plugins Core components

file size NPM JavaScript Style Guide

@djsp/core is the heart of @djsp. It contains these exports:

import {
  EditorContainer,
  Editor,
  Plugin,
  withPluginContext,
} from '@djsp/core'

The <EditorContainer /> component

Usage

EditorContainer contains all props for the draft js Editor which it passes down to plugins and the Editor via the React context api.

import { EditorContainer } from '@djsp/core'

<EditorContainer onChange={this.onChange} editorState={this.state.editorState}>
  <Editor />
</EditorContainer>

Here are the props that EditorContainer accepts, all of the below props are inherted from the draft js editor component

Props

| Property | Type | required? | Description | | - | - | - | - | | editorState | EditorState | required | The state of the editor. Identical to the draft js editorState prop | | onChange | (EditorState) => void | required | Fired when content changes. Identical to the draft js onChange prop | | editorKey | string | optional | Overrides props set via plugin | | textAlignment | "left" or "center" or "right" | optional | Overrides props set via plugin | | textDirectionality | "LTR" or "RTL" | optional | Overrides props set via plugin | | placeholder | string | optional | Overrides props set via plugin | | readOnly | boolean | optional | Overrides props set via plugin | | spellCheck | boolean | optional | Overrides props set via plugin | | stripPastedStyles | boolean | optional | Overrides props set via plugin | | tabIndex | number | optional | Overrides props set via plugin | | autoCapitalize | string | optional | Overrides props set via plugin | | autoComplete | string | optional | Overrides props set via plugin | | autoCorrect | string | optional | Overrides props set via plugin | | ariaActiveDescendantID | string | optional | Overrides props set via plugin | | ariaAutoComplete | string | optional | Overrides props set via plugin | | ariaControls | string | optional | Overrides props set via plugin | | ariaDescribedBy | string | optional | Overrides props set via plugin | | ariaExpanded | boolean | optional | Overrides props set via plugin | | ariaLabel | string | optional | Overrides props set via plugin | | ariaLabelledBy | string | optional | Overrides props set via plugin | | ariaMultiline | boolean | optional | Overrides props set via plugin | | webDriverTestID | string | optional | Overrides props set via plugin |

The <Editor> Component

The Editor component does not accept any props, since it inherits all of it's props from EditorContainer. It must be rendered inside EditorContainer

To configure editor props, use EditorContainer and Plugin

Usage

<EditorContainer
  onChange={editorState => this.setState({ editorState })}
  editorState={this.state.editorState}
>
  <Editor />
</EditorContainer>

The <Plugin> Component

The Plugin can only be renderered inside EditorContainer. It's props will be plugged in to the editorState. This way you can compose and isolate editor functionality like decorators, blockRendererFn or any of the props listed below:

Props

| Property | Type | required? | Description | | - | - | - | - | | children | ({ setEditorState, editorState, setEditorProps, editorRef, editorProps }) => React.Node | optional | Render Prop, for usage see here | | customStyleMap | Object | optional | Identical to the draft js customStyleMap prop | | blockRenderMap | Immutable.Map<{\nelement: string, wrapper?: React.Node, aliasedElements?: Array<string> }> | optional | Identical to the draft js blockRenderMap prop | | blockRendererFn | (block: BlockNodeRecord) => { component: Component, props: Object, editable: boolean } | optional | Identical to the draft js blockRendererFn prop | | blockStyleFn | (block: BlockNodeRecord) => cssClassName: string | optional | Identical to the draft js blockStyleFn prop | | customStyleFn | (style: Immutable.OrderedSet<string>, block: BlockNodeRecord) => ?Object | optional | Identical to the draft js customStyleFn prop | | keyBindingFn | (e: SyntheticKeyboardEvent<>) => ?string | optional | Identical to the draft js keyBindingFn prop | | handleKeyCommand | (command: string, editorState: EditorState) => 'handled' or 'not-handled' | optional | Identical to the draft js handleKeyCommand prop | | handleBeforeInput | (chars: string, editorState: EditorState) => 'handled' or 'not-handled' | optional | Identical to the draft js handleBeforeInput prop | | handlePastedText | (text: string, html?: string, editorState: EditorState) => 'handled' or 'not-handled' | optional | Identical to the draft js handlePastedText prop | | handlePastedFiles | (files: Array<Blob>) => 'handled' or 'not-handled' | optional | Identical to the draft js handlePastedFiles prop | | handleDroppedFiles | (selection: SelectionState, files: Array<Blob>) => 'handled' or 'not-handled' | optional | Identical to the draft js handleDroppedFiles prop | | handleDrop | (selection: SelectionState, dataTransfer: Object, isInternal: 'internal' or 'external') => 'handled' or 'not-handled' | optional | Identical to the draft js handleDrop prop | | handleReturn | (e: SyntheticKeyboardEvent<>, editorState: EditorState) => 'handled' or 'not-handled' | optional | Identical to the draft js handleReturn prop | | onDownArrow | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onDownArrow prop | | onUpArrow | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onUpArrow prop | | onLeftArrow | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onLeftArrow prop | | onRightArrow | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onRightArrow prop | | onTab | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onTab prop | | onEscape | (e: SyntheticKeyboardEvent<>) => void | optional | Identical to the draft js onEscape prop | | onFocus | (e: SyntheticEvent<>) => void | optional | Identical to the draft js onFocus prop | | onBlur | (e: SyntheticEvent<>) => void | optional | Identical to the draft js onBlur prop |

Plugin render prop

The Plugin also accepts an optional render prop which exposes the plugin context.

<Plugin>
  {({
    setEditorState,
    editorProps,
    editorRef,
    editorState,
    setEditorProps
  }) => (
    <button
      onClick={() => (
        setEditorState(
          RichUtils.toggleBlockType(editorState, 'header-one')
        )
      )}
    >H1</button>
  )}
</Plugin>

<Plugin>(RenderProps)</Plugin>

| Property | Type | Description | | - | - | - | | editorState | EditorState | The EditorState object | | setEditorState | (editorState: EditorState) => void | Lets you update the editorState | | editorProps | Object | Contains the props for EditorContainer except editorState and onChange | | setEditorProps | (editorProps: Object) => void | lets you set the above editorProps. Be aware that editor props set via Plugins are overridden by EditorContainer props | | editorRef | Ref<DraftEditor> | A React reference to the draft js editor |

withPluginContext

Another way to create a plugin is with the withPluginContext HOC. This has the advantage of letting you handle plugin subscription.

License

MIT © juliankrispel