From 7e77235ae3fedc5d8e5f5c8661dde9c745c9170d Mon Sep 17 00:00:00 2001 From: Ivan Voskoboinyk Date: Thu, 21 Apr 2022 16:21:44 +0300 Subject: [PATCH] Rename `isAllowedListDescendant` to `isConvertibleToListTextNode` To better describe what it's needed for --- .../withListsFormatting.ts | 2 +- packages/slate-lists/README.md | 28 +++++++++---------- packages/slate-lists/src/jsx.ts | 2 +- packages/slate-lists/src/lib/wrapInList.ts | 6 ++-- packages/slate-lists/src/types.ts | 2 +- packages/slate-lists/src/withLists.ts | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/slate-editor/src/modules/editor-v4-rich-formatting/withListsFormatting.ts b/packages/slate-editor/src/modules/editor-v4-rich-formatting/withListsFormatting.ts index a79dd6fce..63e2a2815 100644 --- a/packages/slate-editor/src/modules/editor-v4-rich-formatting/withListsFormatting.ts +++ b/packages/slate-editor/src/modules/editor-v4-rich-formatting/withListsFormatting.ts @@ -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, diff --git a/packages/slate-lists/README.md b/packages/slate-lists/README.md index 4dfbb6b9a..110c2b651 100644 --- a/packages/slate-lists/README.md +++ b/packages/slate-lists/README.md @@ -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) { @@ -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) { @@ -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) { @@ -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) diff --git a/packages/slate-lists/src/jsx.ts b/packages/slate-lists/src/jsx.ts index 535cc649d..29f2294bc 100644 --- a/packages/slate-lists/src/jsx.ts +++ b/packages/slate-lists/src/jsx.ts @@ -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) { diff --git a/packages/slate-lists/src/lib/wrapInList.ts b/packages/slate-lists/src/lib/wrapInList.ts index 15a954200..5dd9d9860 100644 --- a/packages/slate-lists/src/lib/wrapInList.ts +++ b/packages/slate-lists/src/lib/wrapInList.ts @@ -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) { @@ -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) ); }, }), diff --git a/packages/slate-lists/src/types.ts b/packages/slate-lists/src/types.ts index 89ddb38ec..df1d3a275 100644 --- a/packages/slate-lists/src/types.ts +++ b/packages/slate-lists/src/types.ts @@ -6,7 +6,7 @@ export enum ListType { } export interface ListsSchema { - isAllowedListDescendant(node: Node): boolean; + isConvertibleToListTextNode(node: Node): boolean; isDefaultTextNode(node: Node): boolean; diff --git a/packages/slate-lists/src/withLists.ts b/packages/slate-lists/src/withLists.ts index cdfca8cc9..1261918ff 100644 --- a/packages/slate-lists/src/withLists.ts +++ b/packages/slate-lists/src/withLists.ts @@ -31,7 +31,7 @@ const LIST_NORMALIZERS: Normalizer[] = [ export function withLists(schema: ListsSchema) { return function (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,