All Projects → jensneuse → slate-react-dnd-plugin

jensneuse / slate-react-dnd-plugin

Licence: MIT license
No description or website provided.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to slate-react-dnd-plugin

slate-yjs-example
Minimal example project for slate-yjs
Stars: ✭ 43 (+22.86%)
Mutual labels:  slate, slatejs, slate-react
React Movable
🔀 Drag and drop for your React lists and tables. Accessible. Tiny.
Stars: ✭ 1,064 (+2940%)
Mutual labels:  dnd, drag-and-drop
Bcx Aurelia Dnd
Aurelia Drag and Drop.
Stars: ✭ 20 (-42.86%)
Mutual labels:  dnd, drag-and-drop
Angular Skyhook
An implementation of react-dnd for Angular.
Stars: ✭ 146 (+317.14%)
Mutual labels:  dnd, drag-and-drop
Vddl
🦄 Vue components for modifying lists with the HTML5 drag & drop API.
Stars: ✭ 407 (+1062.86%)
Mutual labels:  dnd, drag-and-drop
Smooth Dnd
drag and drop library for javascript
Stars: ✭ 408 (+1065.71%)
Mutual labels:  dnd, drag-and-drop
publikator-frontend
[DEPRECATED] moved to https://github.com/republik/plattform Our CMS frontend, including a rich text editor implemented with Slate.
Stars: ✭ 16 (-54.29%)
Mutual labels:  slate, slate-react
react-native-dnd-board
A drag and drop Kanban board for React Native.
Stars: ✭ 41 (+17.14%)
Mutual labels:  dnd, drag-and-drop
Easy Dnd
A drag and drop implementation for Vue.js 2 https://codesandbox.io/s/easy-dnd-demo-9mbij https://codesandbox.io/s/easy-dnd-demo-2-xnqbz
Stars: ✭ 202 (+477.14%)
Mutual labels:  dnd, drag-and-drop
React Dragtastic
A simple drag and drop library for React which uses the more stable mouseDown/mouseUp event pattern instead of the problematic HTML5 drag and drop API
Stars: ✭ 181 (+417.14%)
Mutual labels:  dnd, drag-and-drop
react-dnd-treeview
A draggable / droppable React-based treeview component. You can use render props to create each node freely.
Stars: ✭ 207 (+491.43%)
Mutual labels:  dnd, drag-and-drop
vue3-smooth-dnd
Vue3 wrapper components for smooth-dnd
Stars: ✭ 92 (+162.86%)
Mutual labels:  dnd, drag-and-drop
dflex
The sophisticated Drag and Drop library you've been waiting for 🥳
Stars: ✭ 806 (+2202.86%)
Mutual labels:  dnd, drag-and-drop
React Beautiful Dnd
Beautiful and accessible drag and drop for lists with React
Stars: ✭ 25,810 (+73642.86%)
Mutual labels:  dnd, drag-and-drop
H5 Dooring
H5 Page Maker, H5 Editor, LowCode. Make H5 as easy as building blocks. | 让H5制作像搭积木一样简单, 轻松搭建H5页面, H5网站, PC端网站,LowCode平台.
Stars: ✭ 5,832 (+16562.86%)
Mutual labels:  drag-and-drop, react-dnd
Muuri
Infinite responsive, sortable, filterable and draggable layouts
Stars: ✭ 9,797 (+27891.43%)
Mutual labels:  dnd, drag-and-drop
remark-slate-transformer
remark plugin to transform remark syntax tree (mdast) to Slate document tree, and vice versa. Made for WYSIWYG markdown editor.
Stars: ✭ 62 (+77.14%)
Mutual labels:  slate, slatejs
Ngx Smooth Dnd
angular wrapper for smooth-dnd
Stars: ✭ 152 (+334.29%)
Mutual labels:  dnd, drag-and-drop
svelte-slate
slate svelte view layer
Stars: ✭ 43 (+22.86%)
Mutual labels:  slate, slatejs
dnd
Beautiful and accessible drag and drop for lists with React.
Stars: ✭ 271 (+674.29%)
Mutual labels:  dnd, drag-and-drop

slate-react-dnd-plugin

Add react-dnd to slatejs.

TOS

Installation

npm install slate-react-dnd-plugin --save
yarn add slate-react-dnd-plugin
bower install slate-react-dnd-plugin --save

Usage

import * as React from 'react'
import {Editor} from 'slate-react'
import {Value} from 'slate'

import {inject} from "slate-react-dnd-plugin"
//import {inject} from "../../dist/index"

const initialValue = Value.fromJSON({
    document: {
        nodes: [
            {
                object: 'block',
                type: 'paragraph',
                nodes: [
                    {
                        object: 'text',
                        leaves: [
                            {
                                text: 'A line of text in a paragraph.'
                            }
                        ]
                    }
                ]
            }
        ]
    }
});

class ParagraphNode extends React.Component {
    render(){
        return (<p {...this.props.attributes} >{this.props.children}</p>)
    }
}

const blockStyle = {
    border: '1px dashed gray',
    padding: '0.5rem 1rem',
    marginBottom: '.5rem',
    backgroundColor: 'white',
    cursor: 'move'
};

const plugins = inject([
    {
        renderNode: (props) => {
            switch (props.node.type) {
                case 'paragraph':
                    return <ParagraphNode {...props} />;
                default:
                    return null;
            }
        }
    }
],{
    renderBlock: (isDragging,children) => {

        const opacity = isDragging? 0 : 1;

        return <div style={{
            ...blockStyle,
            opacity
        }}>{children}</div>
    }
});

class StoryEditor extends React.Component {

    state = {
        value: initialValue
    };

    onChange({value}){
        this.setState({value})
    }

    render(){
        return (
            <Editor
                value={this.state.value}
                plugins={plugins}
                onChange={this.onChange.bind(this)}/>
        )
    }
}

export default StoryEditor;
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

import StoryEditor from "./StoryEditor"

import {DragPreviewBlock} from "slate-react-dnd-plugin"
import {DragDropContainer} from "slate-react-dnd-plugin"
import {DropBlock} from "slate-react-dnd-plugin"
import {EditorProvider} from "slate-react-dnd-plugin"

/*import DragPreviewBlock from "../../dist/drag-preview-block"
import DragDropContainer from "../../dist/container"
import DropBlock from "../../dist/drop-block"
import EdititorProvider from "../../dist/editor-provider"*/

const insertBlockFn = (hoverIndex, item, parent, change) => {

  const result = change.insertNodeByKey(parent.key, hoverIndex, {
    object: 'block',
    type: 'paragraph',
    nodes: [
      {
        object: 'text',
        leaves: [
          {
            text: 'A new Block via drag&drop'
          }
        ]
      }
    ]
  });

  item.key = result.value.document.nodes._tail.array[hoverIndex].key;

}

const canDrop = (props, monitor) => {
  return true;
}

const onDrop = (item, parent, change) => {
  console.log('onDrop', item, parent, change);
  change.removeNodeByKey(item.key);
};

const previewBlockStyle = {
	backgroundColor: 'white',
	cursor: 'move',
}

const renderPreviewBlock = (isDragging,children) => {
  const opacity = isDragging ? 0.4 : 1
  return <div style={{ ...previewBlockStyle, opacity }}>{children}</div>
}

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <DragDropContainer>
          <EditorProvider>
            <div className="wrapper">
              <div className="editor">
                <StoryEditor/>
              </div>
              <div className="rightMenu">
                <DragPreviewBlock className="rightMenu" onHover={insertBlockFn} renderBlock={renderPreviewBlock} >
                  <div className="dragItem">
                    <p>Insert paragraph from here.</p>
                  </div>
                </DragPreviewBlock>
                <DropBlock canDrop={canDrop} onDrop={onDrop}>
                  <div className="dustbin">
                    <p>Drop paragraph here to delete it.</p>
                  </div>
                </DropBlock>
              </div>
            </div>
          </EditorProvider>
        </DragDropContainer>
      </div>
    );
  }
}

export default App;

Contributors

This plugin was initially developed and maintained by one single person: Jens Neuse.

These users are actively maintaining and/or developing this plugin as of today:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].