Skip to content

Commit

Permalink
Tweak ListsSchema to create proper list children structure by default
Browse files Browse the repository at this point in the history
  • Loading branch information
e1himself committed Apr 21, 2022
1 parent bc73aec commit 19ee54f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { ParagraphNode } from '@prezly/slate-types';
import { PARAGRAPH_NODE_TYPE } from '@prezly/slate-types';

export function createParagraph(
props: { children?: ParagraphNode['children'] } = {},
): ParagraphNode {
const { children = [{ text: '' }] } = props;
type Props = Partial<Pick<ParagraphNode, 'children'>>;

export function createParagraph({ children }: Props = {}): ParagraphNode {
return {
type: PARAGRAPH_NODE_TYPE,
children,
children: children ?? [{ text: '' }],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ const SCHEMA: ListsSchema = {
createDefaultTextNode(props = {}) {
return createParagraph(props);
},
createListNode(type: ListType = ListType.UNORDERED, props = {}) {
createListNode(type: ListType = ListType.UNORDERED, { children } = {}) {
return {
children: [{ text: '' }],
...props,
type: type === ListType.ORDERED ? NUMBERED_LIST_NODE_TYPE : BULLETED_LIST_NODE_TYPE,
children: children ?? [this.createListItemNode()],
};
},
createListItemNode(props = {}) {
return { children: [{ text: '' }], ...props, type: LIST_ITEM_NODE_TYPE };
createListItemNode({ children } = {}) {
return {
type: LIST_ITEM_NODE_TYPE,
children: children ?? [this.createListItemTextNode()],
};
},
createListItemTextNode(props = {}) {
return { children: [{ text: '' }], ...props, type: LIST_ITEM_TEXT_NODE_TYPE };
createListItemTextNode({ children } = {}) {
return {
type: LIST_ITEM_TEXT_NODE_TYPE,
children: children ?? [{ text: '' }],
};
},
};

Expand Down

0 comments on commit 19ee54f

Please sign in to comment.