How to use megadraft - 10 common examples

To help you get started, we’ve selected a few megadraft examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github udacityalumni / udacity-alumni-fe / app / src / containers / CmsEditorContainer / index.js View on Github external
handleSubmit() {
    const {
      action,
      editorTitle,
      editorState,
      modal,
    } = this.props;
    const json = editorStateToJSON(editorState);
    const blockArray = convertFromRaw(JSON.parse(json));
    const content = stateToMarkdown(blockArray);
    const article = inputToArticle({
      json,
      content,
      title: editorTitle,
      status: modal.status,
      spotlighted: modal.spotlighted,
      tags: modal.selectedTags,
      feature_image: modal.featureImage || '',
    });
    if (action && action === 'edit') {
      this.handleUpdateArticleSubmission(article);
    } else {
      this.handleNewArticleSubmission(article);
    }
github udacityalumni / udacity-alumni-fe / app / src / components / CmsEditor / index.js View on Github external
render() {
    const {
      editorState,
      editorTitle,
      isValid,
      onChangeTitle,
      onSubmit,
      onChangeContent,
      onTapToPreview,
    } = this.props;
    const stateForEditor = editorState ? editorState : editorStateFromRaw(null);
    return (
      <div>
        <div>
          <input placeholder="Title" value="{editorTitle}" type="titleInput">
        </div>
        <div>
           onChangeContent(state)}</div></div>
github lokiuz / redraft / example / src / App / App.js View on Github external
import React, { Component } from 'react';
import { EditorState, convertToRaw, convertFromRaw } from 'draft-js';
import { MegadraftEditor, editorStateFromRaw } from 'megadraft';
import Button from '../Button/Button';
import LoadJSON from '../LoadJSON/LoadJSON';
import Preview from '../Preview/Preview';
import ForkRibbon from '../ForkRibbon/ForkRibbon';
import sample from '../sample';
import './App.css';
import '../../node_modules/megadraft/dist/css/megadraft.css';

const intialState = editorStateFromRaw(sample);

class App extends Component {
  state = {
    editorState: intialState,
    raw: convertToRaw(intialState.getCurrentContent()),
    paste: false,
  };

  handleUpdate = (editorState) => {
    this.setState({
      editorState,
      raw: convertToRaw(editorState.getCurrentContent()),
      paste: false,
    });
  };
github udacityalumni / udacity-alumni-fe / app / src / containers / CmsEditorContainer / reducer.js View on Github external
import * as types from './constants';
import update from 'react-addons-update';
import { editorStateFromRaw } from 'megadraft';

export const initialState = {
  article: {
    id: null,
    action: null,
  },
  editorState: editorStateFromRaw(null),
  editorTitle: null,
  preview: {
    isPreviewing: false,
    content: null,
    title: null,
  },
  isValid: false,
  isLoading: false,
  error: null,
  message: null,
  modal: {
    isShowing: false,
    status: 0,
    spotlighted: false,
    selectedTags: [],
    featureImage: null,
github udacityalumni / udacity-alumni-fe / app / src / containers / CmsEditorContainer / reducer.js View on Github external
$set: action.action,
            },
          },
        });
      case types.CMS_SET_FEATURE_IMAGE:
        return update(state, {
          modal: modalReducer(state.modal, action),
        });
      case types.CMS_SET_STATE_FROM_ARTICLE:
        const rawContent = JSON.parse(action.article.json);
        return update(state, {
          isValid: {
            $set: true,
          },
          editorState: {
            $set: editorStateFromRaw(rawContent),
          },
          editorTitle: {
            $set: action.article.title,
          },
          modal: {
            $set: modalReducer(state.modal, action),
          },
        });
      default:
        return state;
    }
  };
github globocom / megadraft-table-plugin / src / Block.js View on Github external
constructor(props) {
    super(props);

    this._handleEdit = ::this._handleEdit;
    this._onModalClose = ::this._onModalClose;
    this._onSave = ::this._onSave;

    this.state = {
      isEditing: false
    };

    this.actions = [
      {"key": "edit", "icon": MegadraftIcons.EditIcon, "action": this._handleEdit},
      {"key": "delete", "icon": MegadraftIcons.DeleteIcon, "action": this.props.container.remove}
    ];
  }
github globocom / megadraft-related-articles-plugin / src / Block.js View on Github external
constructor(props) {
    super(props);

    this._handleAddAnotherClick = ::this._handleAddAnotherClick;
    this.updateArticle = ::this.updateArticle;
    this.removeArticle = ::this.removeArticle;

    this.actions = [
      {"key": "delete", "icon": MegadraftIcons.DeleteIcon, "action": this.props.container.remove}
    ];
  }
github globocom / generator-megadraft-plugin / generators / app / templates / src / Block.js View on Github external
constructor(props) {
    super(props);

    this._handleCaptionChange = ::this._handleCaptionChange;
    this._handleEdit = ::this._handleEdit;

    this.actions = [
      { key: "edit", icon: MegadraftIcons.EditIcon, action: this._handleEdit },
      {
        key: "delete",
        icon: MegadraftIcons.DeleteIcon,
        action: this.props.container.remove,
      },
    ];
  }
github globocom / generator-megadraft-plugin / generators / app / templates / src / Button.js View on Github external
onClick(e) {
    const data = {
      type: constants.PLUGIN_TYPE,
      caption: "Initial plugin text",
    };

    this.props.onChange(insertDataBlock(this.props.editorState, data));
  }
github globocom / megadraft-table-plugin / src / Button.js View on Github external
onSave(tableConfig) {
    this.setState({isEditing: false});
    const data = {
      type: constants.PLUGIN_TYPE,
      ...tableConfig
    };

    this.props.onChange(insertDataBlock(this.props.editorState, data));
  }