Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@djsp/core

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@djsp/core

djsp Core Components

  • 0.1.4
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@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

PropertyTyperequired?Description
editorStateEditorStaterequiredThe state of the editor. Identical to the draft js editorState prop
onChange(EditorState) => voidrequiredFired when content changes. Identical to the draft js onChange prop
textAlignment"left" or "center" or "right"optionalOverrides props set via plugin
textDirectionality"LTR" or "RTL"optionalOverrides props set via plugin
placeholderstringoptionalOverrides props set via plugin
readOnlybooleanoptionalOverrides props set via plugin
spellCheckbooleanoptionalOverrides props set via plugin
stripPastedStylesbooleanoptionalOverrides props set via plugin
tabIndexnumberoptionalOverrides props set via plugin
autoCapitalizestringoptionalOverrides props set via plugin
autoCompletestringoptionalOverrides props set via plugin
autoCorrectstringoptionalOverrides props set via plugin
ariaActiveDescendantIDstringoptionalOverrides props set via plugin
ariaAutoCompletestringoptionalOverrides props set via plugin
ariaControlsstringoptionalOverrides props set via plugin
ariaDescribedBystringoptionalOverrides props set via plugin
ariaExpandedbooleanoptionalOverrides props set via plugin
ariaLabelstringoptionalOverrides props set via plugin
ariaLabelledBystringoptionalOverrides props set via plugin
ariaMultilinebooleanoptionalOverrides props set via plugin
webDriverTestIDstringoptionalOverrides 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

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

PropertyTypeDescription
editorStateEditorStateThe EditorState object
setEditorState(editorState: EditorState) => voidLets you update the editorState
editorPropsObjectContains props that can be set via setEditorProps, these are editorKey placeholder textAlignment textDirectionality readOnly spellCheck stripPastedStyles tabIndex autoCapitalize autoComplete autoCorrect ariaActiveDescendantID ariaAutoComplete ariaControls ariaDescribedBy ariaExpanded ariaLabel ariaLabelledBy ariaMultiline webDriverTestID
setEditorProps(editorProps: Object) => voidlets you set the above editorProps. Be aware that editor props set via Plugins are overridden by EditorContainer props
editorRefRef<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

FAQs

Package last updated on 29 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc