More and more fixes
This commit is contained in:
@ -1,133 +1,82 @@
|
||||
// // @flow
|
||||
// import React from 'react';
|
||||
// import Code from './components/Code';
|
||||
// import HorizontalRule from './components/HorizontalRule';
|
||||
// import InlineCode from './components/InlineCode';
|
||||
// import Image from './components/Image';
|
||||
// import Link from './components/Link';
|
||||
// import ListItem from './components/ListItem';
|
||||
// import TodoList from './components/TodoList';
|
||||
// import {
|
||||
// Heading1,
|
||||
// Heading2,
|
||||
// Heading3,
|
||||
// Heading4,
|
||||
// Heading5,
|
||||
// Heading6,
|
||||
// } from './components/Heading';
|
||||
// import Paragraph from './components/Paragraph';
|
||||
// import BlockToolbar from './components/Toolbar/BlockToolbar';
|
||||
// import type { Props, Node, Transform } from './types';
|
||||
//
|
||||
// type Options = {
|
||||
// onInsertImage: Function,
|
||||
// onChange: Function,
|
||||
// };
|
||||
//
|
||||
// const createSchema = ({ onInsertImage, onChange }: Options) => {
|
||||
// return {
|
||||
// marks: {
|
||||
// bold: (props: Props) => <strong>{props.children}</strong>,
|
||||
// code: (props: Props) => <InlineCode>{props.children}</InlineCode>,
|
||||
// italic: (props: Props) => <em>{props.children}</em>,
|
||||
// underlined: (props: Props) => <u>{props.children}</u>,
|
||||
// deleted: (props: Props) => <del>{props.children}</del>,
|
||||
// added: (props: Props) => <mark>{props.children}</mark>,
|
||||
// },
|
||||
//
|
||||
// nodes: {
|
||||
// 'block-toolbar': (props: Props) => (
|
||||
// <BlockToolbar
|
||||
// onChange={onChange}
|
||||
// onInsertImage={onInsertImage}
|
||||
// {...props}
|
||||
// />
|
||||
// ),
|
||||
// paragraph: (props: Props) => <Paragraph {...props} />,
|
||||
// 'block-quote': (props: Props) => (
|
||||
// <blockquote {...props.attributes}>{props.children}</blockquote>
|
||||
// ),
|
||||
// 'horizontal-rule': HorizontalRule,
|
||||
// 'bulleted-list': (props: Props) => (
|
||||
// <ul {...props.attributes}>{props.children}</ul>
|
||||
// ),
|
||||
// 'ordered-list': (props: Props) => (
|
||||
// <ol {...props.attributes}>{props.children}</ol>
|
||||
// ),
|
||||
// 'todo-list': (props: Props) => (
|
||||
// <TodoList {...props.attributes}>{props.children}</TodoList>
|
||||
// ),
|
||||
// table: (props: Props) => (
|
||||
// <table {...props.attributes}>{props.children}</table>
|
||||
// ),
|
||||
// 'table-row': (props: Props) => (
|
||||
// <tr {...props.attributes}>{props.children}</tr>
|
||||
// ),
|
||||
// 'table-head': (props: Props) => (
|
||||
// <th {...props.attributes}>{props.children}</th>
|
||||
// ),
|
||||
// 'table-cell': (props: Props) => (
|
||||
// <td {...props.attributes}>{props.children}</td>
|
||||
// ),
|
||||
// code: Code,
|
||||
// image: Image,
|
||||
// link: Link,
|
||||
// 'list-item': ListItem,
|
||||
// heading1: (props: Props) => <Heading1 placeholder {...props} />,
|
||||
// heading2: (props: Props) => <Heading2 {...props} />,
|
||||
// heading3: (props: Props) => <Heading3 {...props} />,
|
||||
// heading4: (props: Props) => <Heading4 {...props} />,
|
||||
// heading5: (props: Props) => <Heading5 {...props} />,
|
||||
// heading6: (props: Props) => <Heading6 {...props} />,
|
||||
// },
|
||||
//
|
||||
// rules: [
|
||||
// // ensure first node is always 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' });
|
||||
// },
|
||||
// },
|
||||
//
|
||||
// // automatically removes 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;
|
||||
// @flow
|
||||
import { Block, Change, Node, Mark } from 'slate';
|
||||
|
||||
const schema = {
|
||||
blocks: {
|
||||
heading1: { marks: [''] },
|
||||
heading2: { marks: [''] },
|
||||
heading3: { marks: [''] },
|
||||
heading4: { marks: [''] },
|
||||
heading5: { marks: [''] },
|
||||
heading6: { marks: [''] },
|
||||
'ordered-list': {
|
||||
nodes: [{ types: ['list-item'] }],
|
||||
},
|
||||
'bulleted-list': {
|
||||
nodes: [{ types: ['list-item'] }],
|
||||
},
|
||||
table: {
|
||||
nodes: [{ types: ['table-row', 'table-head', 'table-cell'] }],
|
||||
},
|
||||
image: {
|
||||
isVoid: true,
|
||||
},
|
||||
'horizontal-rule': {
|
||||
isVoid: true,
|
||||
},
|
||||
'block-toolbar': {
|
||||
isVoid: true,
|
||||
},
|
||||
},
|
||||
document: {
|
||||
nodes: [
|
||||
{ types: ['heading1'], min: 1, max: 1 },
|
||||
{
|
||||
types: [
|
||||
'paragraph',
|
||||
'heading1',
|
||||
'heading2',
|
||||
'heading3',
|
||||
'heading4',
|
||||
'heading5',
|
||||
'heading6',
|
||||
'code',
|
||||
'horizontal-rule',
|
||||
'image',
|
||||
'bulleted-list',
|
||||
'ordered-list',
|
||||
'todo-list',
|
||||
'block-toolbar',
|
||||
'table',
|
||||
],
|
||||
min: 1,
|
||||
},
|
||||
],
|
||||
normalize: (
|
||||
change: Change,
|
||||
reason: string,
|
||||
{
|
||||
node,
|
||||
child,
|
||||
mark,
|
||||
index,
|
||||
}: { node: Node, mark?: Mark, child: Node, index: number }
|
||||
) => {
|
||||
switch (reason) {
|
||||
case 'child_type_invalid': {
|
||||
return change.setNodeByKey(
|
||||
child.key,
|
||||
index === 0 ? 'heading1' : 'paragraph'
|
||||
);
|
||||
}
|
||||
case 'child_required': {
|
||||
const block = Block.create(index === 0 ? 'heading1' : 'paragraph');
|
||||
return change.insertNodeByKey(node.key, index, block);
|
||||
}
|
||||
default:
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default schema;
|
||||
|
Reference in New Issue
Block a user