File size: 986 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import { SlateReactPresentation } from 'slate-react-presentation';
import type { SlateProps } from '../types/component';
import { useRenderElement, useRenderLeave } from './renderHooks';

const ReadOnlySlate = (props: SlateProps) => {
  const { plugins, defaultPluginType } = props;

  const renderElement = useRenderElement(
    {
      plugins,
      defaultPluginType,
    },
    []
  );
  const renderLeaf = useRenderLeave({ plugins, readOnly: true }, []);
  // the div around is required to be consistent in styling with the default editor
  return (
    <div
      style={{
        position: 'relative',
        outline: 'none',
        whiteSpace: 'pre-wrap',
        overflowWrap: 'break-word',
      }}
    >
      <SlateReactPresentation
        renderElement={renderElement}
        renderLeaf={renderLeaf}
        value={props.data.slate}
        LeafWrapper={React.Fragment}
      />
    </div>
  );
};

export default React.memo(ReadOnlySlate);