chore: rich text type declarations
This commit is contained in:
@@ -17,7 +17,7 @@ import enablePlugins from './enablePlugins';
|
||||
import defaultValue from '../../../../../fields/richText/defaultValue';
|
||||
import FieldDescription from '../../FieldDescription';
|
||||
import withHTML from './plugins/withHTML';
|
||||
import { Props } from './types';
|
||||
import { ElementNode, TextNode, Props } from './types';
|
||||
import { RichTextElement, RichTextLeaf } from '../../../../../fields/config/types';
|
||||
import listTypes from './elements/listTypes';
|
||||
import mergeCustomFunctions from './mergeCustomFunctions';
|
||||
@@ -30,15 +30,12 @@ const defaultElements: RichTextElement[] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
||||
const defaultLeaves: RichTextLeaf[] = ['bold', 'italic', 'underline', 'strikethrough', 'code'];
|
||||
|
||||
const baseClass = 'rich-text';
|
||||
type CustomText = { text: string;[x: string]: unknown }
|
||||
|
||||
type CustomElement = { type?: string; children: (CustomText | CustomElement)[] }
|
||||
|
||||
declare module 'slate' {
|
||||
interface CustomTypes {
|
||||
Editor: BaseEditor & ReactEditor & HistoryEditor
|
||||
Element: CustomElement
|
||||
Text: CustomText
|
||||
Element: ElementNode
|
||||
Text: TextNode
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ const indent = {
|
||||
],
|
||||
{
|
||||
at: previousNodePath,
|
||||
select: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Editor, Element } from 'slate';
|
||||
import { nodeIsTextNode } from '../types';
|
||||
|
||||
export const isLastSelectedElementEmpty = (editor: Editor): boolean => {
|
||||
const currentlySelectedNodes = Array.from(Editor.nodes(editor, {
|
||||
@@ -10,5 +11,6 @@ export const isLastSelectedElementEmpty = (editor: Editor): boolean => {
|
||||
|
||||
return lastSelectedNode && Element.isElement(lastSelectedNode[0])
|
||||
&& (!lastSelectedNode[0].type || lastSelectedNode[0].type === 'p')
|
||||
&& nodeIsTextNode(lastSelectedNode[0].children?.[0])
|
||||
&& lastSelectedNode[0].children?.[0].text === '';
|
||||
};
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { BaseEditor, Selection } from 'slate';
|
||||
import { RichTextField } from '../../../../../fields/config/types';
|
||||
|
||||
export type Props = Omit<RichTextField, 'type'> & {
|
||||
path?: string
|
||||
}
|
||||
|
||||
export type TextNode = { text: string;[x: string]: unknown }
|
||||
|
||||
export type ElementNode = { type?: string; children: (TextNode | ElementNode)[] }
|
||||
|
||||
export function nodeIsTextNode(node: TextNode | ElementNode): node is TextNode {
|
||||
return 'text' in node;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user