Skip to content

Commit

Permalink
Rename isAllowedListDescendant to isConvertibleToListTextNode
Browse files Browse the repository at this point in the history
To better describe what it's needed for
  • Loading branch information
e1himself committed Apr 21, 2022
1 parent 19ee54f commit 7e77235
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { Editor } from 'slate';
import { createParagraph } from '#modules/editor-v4-paragraphs';

const SCHEMA: ListsSchema = {
isAllowedListDescendant(node): boolean {
isConvertibleToListTextNode(node) {
return isParagraphNode(node) || isHeadingNode(node) || isQuoteNode(node);
},
isDefaultTextNode: isParagraphNode,
Expand Down
28 changes: 14 additions & 14 deletions packages/slate-lists/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Live example: https://codesandbox.io/s/prezlyslate-lists-user-guide-1-define-opt
+import { type ListsSchema, ListType } from '@prezly/slate-lists';
+
+const schema: ListsSchema = {
+ isAllowedListDescendant(node) {
+ isConvertibleToListTextNode(node) {
+ return Element.isElementType(node, PARAGRAPH_TYPE);
+ },
+ isDefaultTextNode(node) {
Expand Down Expand Up @@ -211,7 +211,7 @@ Live example: https://codesandbox.io/s/prezlyslate-lists-user-guide-2-use-withli
+import { type ListsSchema, ListType, withLists } from '@prezly/slate-lists';

const schema: ListsSchema = {
isAllowedListDescendant(node) {
isConvertibleToListTextNode(node) {
return Element.isElementType(node, PARAGRAPH_TYPE);
},
isDefaultTextNode(node) {
Expand Down Expand Up @@ -289,7 +289,7 @@ Live example: https://codesandbox.io/s/prezlyslate-lists-user-guide-3-use-withli
+import { type ListsSchema, ListType, withLists, withListsReact } from '@prezly/slate-lists';

const schema: ListsSchema = {
isAllowedListDescendant(node) {
isConvertibleToListTextNode(node) {
return Element.isElementType(node, PARAGRAPH_TYPE);
},
isDefaultTextNode(node) {
Expand Down Expand Up @@ -373,17 +373,17 @@ Only core API is documented although all utility functions are exposed. Should y
Lists schema wires the Lists plugin to your project-level defined Slate model.
It is designed with 100% customization in mind, not depending on any specific node types, or non-core interfaces.

| Name | Description |
|---------------------------|------------------------------------------------------------------------------------------------------------------------|
| `isAllowedListDescendant` | Check if a node can be converted to a list item text node. |
| `isDefaultTextNode` | Check if a node is a plain default text node, that list item text node will become when it is unwrapped or normalized. |
| `isListNode` | Check if a node is representing a list. |
| `isListItemNode` | Check if a node is representing a list item. |
| `isListItemTextNode` | Check if a node is representing a list item text. |
| `createDefaultTextNode` | Create a plain default text node. List item text nodes become these when unwrapped or normalized. |
| `createListNode` | Create a new list node of the given type. |
| `createListItemNode` | Create a new list item node. |
| `createListItemTextNode` | Create a new list item text node. |
| Name | Description |
|-------------------------------|------------------------------------------------------------------------------------------------------------------------|
| `isConvertibleToListTextNode` | Check if a node can be converted to a list item text node. |
| `isDefaultTextNode` | Check if a node is a plain default text node, that list item text node will become when it is unwrapped or normalized. |
| `isListNode` | Check if a node is representing a list. |
| `isListItemNode` | Check if a node is representing a list item. |
| `isListItemTextNode` | Check if a node is representing a list item text. |
| `createDefaultTextNode` | Create a plain default text node. List item text nodes become these when unwrapped or normalized. |
| `createListNode` | Create a new list node of the given type. |
| `createListItemNode` | Create a new list item node. |
| `createListItemTextNode` | Create a new list item text node. |

### [`ListsEditor`](src/types.ts)

Expand Down
2 changes: 1 addition & 1 deletion packages/slate-lists/src/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const INLINE_ELEMENTS = [LINK_TYPE];
const VOID_ELEMENTS = [DIVIDER_TYPE];

const SCHEMA: ListsSchema = {
isAllowedListDescendant(node): boolean {
isConvertibleToListTextNode(node) {
return Element.isElementType(node, PARAGRAPH_TYPE);
},
isDefaultTextNode(node) {
Expand Down
6 changes: 3 additions & 3 deletions packages/slate-lists/src/lib/wrapInList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { ListsEditor } from '../types';
import type { ListType } from '../types';

/**
* All nodes matching `isAllowedListDescendant()` in the current selection
* All nodes matching `isConvertibleToListTextNode()` in the current selection
* will be converted to list items and then wrapped in lists.
*
* @see ListsEditor.isAllowedListDescendant()
* @see ListsEditor.isConvertibleToListTextNode()
*/
export function wrapInList(editor: ListsEditor, listType: ListType): void {
if (!editor.selection) {
Expand All @@ -24,7 +24,7 @@ export function wrapInList(editor: ListsEditor, listType: ListType): void {
!editor.isListNode(node) &&
!editor.isListItemNode(node) &&
!editor.isListItemTextNode(node) &&
editor.isAllowedListDescendant(node)
editor.isConvertibleToListTextNode(node)
);
},
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-lists/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum ListType {
}

export interface ListsSchema {
isAllowedListDescendant(node: Node): boolean;
isConvertibleToListTextNode(node: Node): boolean;

isDefaultTextNode(node: Node): boolean;

Expand Down
2 changes: 1 addition & 1 deletion packages/slate-lists/src/withLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const LIST_NORMALIZERS: Normalizer[] = [
export function withLists(schema: ListsSchema) {
return function <T extends Editor>(editor: T): T & ListsEditor {
const listsEditor: T & ListsEditor = Object.assign(editor, {
isAllowedListDescendant: schema.isAllowedListDescendant,
isConvertibleToListTextNode: schema.isConvertibleToListTextNode,
isDefaultTextNode: schema.isDefaultTextNode,
isListNode: schema.isListNode,
isListItemNode: schema.isListItemNode,
Expand Down

0 comments on commit 7e77235

Please sign in to comment.