// @flow
import React from 'react';
import styled from 'styled-components';
import Code from './components/Code';
import InlineCode from './components/InlineCode';
import Image from './components/Image';
import Link from './components/Link';
import ListItem from './components/ListItem';
import {
Heading1,
Heading2,
Heading3,
Heading4,
Heading5,
Heading6,
} from './components/Heading';
import Paragraph from './components/Paragraph';
import type { Props, Node, Transform } from './types';
const TodoList = styled.ul`
list-style: none;
padding-left: 0;
ul {
padding-left: 1em;
}
`;
const createSchema = () => {
return {
marks: {
bold: (props: Props) => {props.children},
code: (props: Props) => {props.children},
italic: (props: Props) => {props.children},
underlined: (props: Props) => {props.children},
deleted: (props: Props) => {props.children},
added: (props: Props) => {props.children},
},
nodes: {
paragraph: (props: Props) => ,
'block-quote': (props: Props) => (
{props.children}
),
'horizontal-rule': (props: Props) =>
,
'bulleted-list': (props: Props) => ,
'ordered-list': (props: Props) => {props.children}
,
'todo-list': (props: Props) => {props.children},
table: (props: Props) => ,
'table-row': (props: Props) => {props.children}
,
'table-head': (props: Props) => {props.children} | ,
'table-cell': (props: Props) => {props.children} | ,
code: Code,
image: Image,
link: Link,
'list-item': ListItem,
heading1: (props: Props) => ,
heading2: (props: Props) => ,
heading3: (props: Props) => ,
heading4: (props: Props) => ,
heading5: (props: Props) => ,
heading6: (props: Props) => ,
},
rules: [
// ensure first node is a heading
{
match: (node: Node) => {
return node.kind === 'document';
},
validate: (document: Node) => {
const firstNode = document.nodes.first();
return firstNode && firstNode.type === 'heading1' ? null : firstNode;
},
normalize: (transform: Transform, document: Node, firstNode: Node) => {
transform.setBlock({ type: 'heading1' });
},
},
// remove any marks in first heading
{
match: (node: Node) => {
return node.kind === 'heading1';
},
validate: (heading: Node) => {
const hasMarks = heading.getMarks().isEmpty();
const hasInlines = heading.getInlines().isEmpty();
return !(hasMarks && hasInlines);
},
normalize: (transform: Transform, heading: Node) => {
transform.unwrapInlineByKey(heading.key);
heading.getMarks().forEach(mark => {
heading.nodes.forEach(textNode => {
if (textNode.kind === 'text') {
transform.removeMarkByKey(
textNode.key,
0,
textNode.text.length,
mark
);
}
});
});
return transform;
},
},
],
};
};
export default createSchema;