Skip to content
Snippets Groups Projects
OEN.js 1.69 KiB
Newer Older
chris's avatar
chris committed
import React, { useRef } from 'react';

import { Wax } from 'wax-prosemirror-core';

import { OenLayout } from './layout';
import { config } from './config';
import { debounce } from 'lodash';

const renderImage = file => {
  const reader = new FileReader();
  return new Promise((accept, fail) => {
    reader.onload = () => accept(reader.result);
    reader.onerror = () => fail(reader.error);
    // Some extra delay to make the asynchronicity visible
    setTimeout(() => reader.readAsDataURL(file), 150);
  });
};

const user = {
  userId: 'b3cfc28e-0f2e-45b5-b505-e66783d4f946',
  userColor: {
    addition: 'royalblue',
    deletion: 'indianred',
  },
  username: 'admin',
};

chris's avatar
chris committed
const val = `<p>first paragraph</p><section class=\"whatever\"><h2>Section 1 heading 2</h2><p class=\"paragraph\">normal text</p></section><section class=\"whatever\"><h2>Section 2 heading 2</h2><p class=\"paragraph\">normal text</p></section><section class=\"whatever\"><p class=\"paragraph\">some normal text</p><p class=\"paragraph\">more normal text</p></section><section class=\"whatever\"><h2>Section 4 heading 2</h2><p class=\"paragraph\">normal text</p></section><p class=\"paragraph\">some text</p><div class=\"outline\" data-type=\"content_structure_element\"><p class=\"paragraph\"></p></div>`;
chris's avatar
chris committed

chris's avatar
chris committed
const Oen = () => {
  const editorRef = useRef();

  return (
    <Wax
      ref={editorRef}
      config={config}
      autoFocus
      placeholder="Type Something..."
      fileUpload={file => renderImage(file)}
chris's avatar
chris committed
      value={val}
chris's avatar
chris committed
      // readonly
      layout={OenLayout}
chris's avatar
chris committed
      // onChange={debounce(source => {
      //   console.log(JSON.stringify(source));
      // }, 200)}
chris's avatar
chris committed
      user={user}
    />
  );
};

export default Oen;