slate-data-filter-plugin

0.0.7 • Public • Published

Filter data on enter handler

Removes any data props which would otherwise be inherited for the enter onKeyDown event. This applies to all block-types.

Accepts a whitelist array parameter to allow defined values to be inherited.

usage

no whitelist

import React, { Component } from 'react'
import { Editor } from 'slate-react'
import FilterData from 'slate-data-filter-plugin';
 
const plugins = [FilterData()];
 
export default class App extends Component {
    state = {
        value: initialValue,
    };
    onChange = ({ value }) => {
        this.setState({ value });
    };
 
    render() {
        return (
            <Editor plugins={plugins} onKeyDown={this.onKeyDown} value={this.state.value} onChange={this.onChange} />
        )
    };
}

with whitelist

import React, { Component } from 'react'
import { Editor } from 'slate-react'
import FilterData from 'slate-data-filter-plugin';
 
const plugins = [FilterData(['foo', 'bar'])];
 
export default class App extends Component {
    state = {
        value: initialValue,
    };
    onChange = ({ value }) => {
        this.setState({ value });
    };
 
    render() {
        return (
            <Editor plugins={plugins} onKeyDown={this.onKeyDown} value={this.state.value} onChange={this.onChange} />
        )
    };
}

testing

npm run test

Package Sidebar

Install

npm i slate-data-filter-plugin

Weekly Downloads

0

Version

0.0.7

License

ISC

Unpacked Size

5.66 kB

Total Files

7

Last publish

Collaborators

  • phillipbarron