5.0.0-alpha.c75189d0 • Published 8 years ago

@slate-editor/link-plugin v5.0.0-alpha.c75189d0

Weekly downloads
236
License
MIT
Repository
github
Last release
8 years ago

SlateJS - Link Plugin

The goal of this plugin is to offers an easy handling of SlateJS link node content editable. Providing a simple API and easy usage, basing on concept of plugin-centric by SlateJS framework.

Usage

SlateJS Link Plugin

import React, { Component } from 'react'
import LinkPlugin from 'slate-link-plugin'

const plugins = [
  LinkPlugin()
]

class SlateEditor extends Component {
  onChange(state) {
    this.setState({ state })
  }
  render() {
    return (
      <Editor
        plugins={plugins}
        state={this.state.state}
        onChange={this.onChange.bind(this)}
      />
    )
  }
}

SlateJS Link Plugin Button

import React, { Component } from 'react'
import { LinkButton } from 'slate-link-plugin'

class SlateEditor extends Component {
  onChange(state) {
    this.setState({ state })
  }
  render() {
    return (
      <div className="editor--toolbar">
        <LinkButton
          state={this.state.state}
          onChange={this.onChange.bind(this)}
        />
      </div>
    )
  }
}

Keyboard Shortcut

PlatformShortcut
Apple Logo⌘ + k
Windows Logo^ + k

API

TargetDescription
LinkNodeComponent that holds the html that will wrap the content with link.
LinkKeyboardShortcutKeyboard shortcut file that manipulates onKeyDown event inside SlateJS.
LinkUtilsGeneric file that holds the util common functions.
LinkButtonButton component that have behaviour to wrap content with link.

TODO

  • Make keyboard shortcut accepts customization;
  • Add behaviour to catch onPaste command and identify if it is an url and ask if wants to link it;