chore(richtext-*): lint & prettier
This commit is contained in:
@@ -18,11 +18,9 @@ import { buildConfig } from 'payload/config'
|
||||
import { slateEditor } from '@payloadcms/richtext-slate'
|
||||
|
||||
export default buildConfig({
|
||||
editor: slateEditor({})
|
||||
editor: slateEditor({}),
|
||||
// ...rest of config
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
More detailed usage can be found in the [Payload Docs](https://payloadcms.com/docs/configuration/overview).
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import toggleElement from './toggle'
|
||||
export const baseClass = 'rich-text__button'
|
||||
|
||||
const ElementButton: React.FC<ButtonProps> = (props) => {
|
||||
const { children, className, el = 'button', format, onClick, tooltip, type = 'type' } = props
|
||||
const { type = 'type', children, className, el = 'button', format, onClick, tooltip } = props
|
||||
|
||||
const editor = useSlate()
|
||||
const [showTooltip, setShowTooltip] = useState(false)
|
||||
|
||||
@@ -12,7 +12,7 @@ export const getCommonBlock = (editor: Editor, match?: NodeMatch<Node>): NodeEnt
|
||||
const [common, path] = Node.common(editor, range.anchor.path, range.focus.path)
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
if (isBlockElement(editor, common) || Editor.isEditor(common)) {
|
||||
return [common, path]
|
||||
}
|
||||
|
||||
@@ -164,8 +164,8 @@ export const IndentButton: React.FC = () => {
|
||||
Transforms.wrapNodes(
|
||||
editor,
|
||||
{
|
||||
children: [],
|
||||
type: isCurrentlyOL ? 'ol' : 'ul',
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
match: (node) => Element.isElement(node) && node.type === 'li',
|
||||
@@ -177,8 +177,8 @@ export const IndentButton: React.FC = () => {
|
||||
Transforms.wrapNodes(
|
||||
editor,
|
||||
{
|
||||
children: [{ children: [], type: 'li' }],
|
||||
type: isCurrentlyOL ? 'ol' : 'ul',
|
||||
children: [{ type: 'li', children: [] }],
|
||||
},
|
||||
{
|
||||
match: (node) => Element.isElement(node) && node.type === 'li',
|
||||
@@ -187,7 +187,7 @@ export const IndentButton: React.FC = () => {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Transforms.wrapNodes(editor, { children: [], type: indentType })
|
||||
Transforms.wrapNodes(editor, { type: indentType, children: [] })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
'use client'
|
||||
|
||||
import type { Element } from 'slate'
|
||||
|
||||
import React, { isValidElement } from 'react'
|
||||
|
||||
import { useElement } from '../../providers/ElementProvider'
|
||||
import listTypes from '../listTypes'
|
||||
import { Element } from 'slate'
|
||||
|
||||
export const ListItemElement: React.FC = () => {
|
||||
const { attributes, children, element } = useElement<Element>()
|
||||
|
||||
@@ -32,12 +32,12 @@ const insertLink = (editor, fields) => {
|
||||
const data = reduceFieldsToValues(fields, true)
|
||||
|
||||
const newLink = {
|
||||
type: 'link',
|
||||
children: [],
|
||||
doc: data.doc,
|
||||
fields: data.fields, // Any custom user-added fields are part of data.fields
|
||||
linkType: data.linkType,
|
||||
newTab: data.newTab,
|
||||
type: 'link',
|
||||
url: data.url,
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,13 @@ const translations = extractTranslations([
|
||||
export const getBaseFields = (config: Config): Field[] => [
|
||||
{
|
||||
name: 'text',
|
||||
type: 'text',
|
||||
label: translations['fields:textToDisplay'],
|
||||
required: true,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'linkType',
|
||||
type: 'radio',
|
||||
admin: {
|
||||
description: translations['fields:chooseBetweenCustomTextOrDocument'],
|
||||
},
|
||||
@@ -40,16 +41,15 @@ export const getBaseFields = (config: Config): Field[] => [
|
||||
},
|
||||
],
|
||||
required: true,
|
||||
type: 'radio',
|
||||
},
|
||||
{
|
||||
name: 'url',
|
||||
type: 'text',
|
||||
admin: {
|
||||
condition: ({ linkType }) => linkType !== 'internal',
|
||||
},
|
||||
label: translations['fields:enterURL'],
|
||||
required: true,
|
||||
type: 'text',
|
||||
},
|
||||
{
|
||||
name: 'doc',
|
||||
@@ -59,6 +59,7 @@ export const getBaseFields = (config: Config): Field[] => [
|
||||
},
|
||||
},
|
||||
// when admin.hidden is a function we need to dynamically call hidden with the user to know if the collection should be shown
|
||||
type: 'relationship',
|
||||
filterOptions: ({ relationTo, user }) => {
|
||||
const hidden = config.collections.find(({ slug }) => slug === relationTo).admin.hidden
|
||||
if (typeof hidden === 'function' && hidden({ user } as { user: User })) {
|
||||
@@ -75,11 +76,10 @@ export const getBaseFields = (config: Config): Field[] => [
|
||||
})
|
||||
.map(({ slug }) => slug),
|
||||
required: true,
|
||||
type: 'relationship',
|
||||
},
|
||||
{
|
||||
name: 'newTab',
|
||||
label: translations['fields:openInNewTab'],
|
||||
type: 'checkbox',
|
||||
label: translations['fields:openInNewTab'],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Element } from 'slate'
|
||||
import type { Element } from 'slate'
|
||||
|
||||
export type LinkElementType = Element & {
|
||||
doc: Record<string, unknown>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import React from 'react'
|
||||
|
||||
import { useElement } from '../../providers/ElementProvider'
|
||||
import './index.scss'
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ const insertRelationship = (editor, { relationTo, value }) => {
|
||||
const text = { text: ' ' }
|
||||
|
||||
const relationship = {
|
||||
type: 'relationship',
|
||||
children: [text],
|
||||
relationTo,
|
||||
type: 'relationship',
|
||||
value,
|
||||
}
|
||||
|
||||
|
||||
@@ -87,9 +87,9 @@ const Element: React.FC<Props> = () => {
|
||||
Transforms.setNodes(
|
||||
editor,
|
||||
{
|
||||
type: 'relationship',
|
||||
children: [{ text: ' ' }],
|
||||
relationTo: relatedCollection.slug,
|
||||
type: 'relationship',
|
||||
value: { id: doc.id },
|
||||
},
|
||||
{ at: elementPath },
|
||||
@@ -113,9 +113,9 @@ const Element: React.FC<Props> = () => {
|
||||
Transforms.setNodes(
|
||||
editor,
|
||||
{
|
||||
type: 'relationship',
|
||||
children: [{ text: ' ' }],
|
||||
relationTo: collectionSlug,
|
||||
type: 'relationship',
|
||||
value: { id: docID },
|
||||
},
|
||||
{ at: elementPath },
|
||||
|
||||
@@ -19,7 +19,7 @@ const toggleElement = (editor: Editor, format: string, blockType = 'type'): void
|
||||
}
|
||||
|
||||
if (!isActive && isWithinLI && blockType !== 'textAlign') {
|
||||
const block = { children: [], type: 'li' }
|
||||
const block = { type: 'li', children: [] }
|
||||
Transforms.wrapNodes(editor, block, {
|
||||
at: Editor.unhangRange(editor, editor.selection),
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ const toggleList = (editor: Editor, format: string): void => {
|
||||
)
|
||||
// Otherwise we can assume that we should just activate the list
|
||||
} else {
|
||||
Transforms.wrapNodes(editor, { children: [], type: format })
|
||||
Transforms.wrapNodes(editor, { type: format, children: [] })
|
||||
|
||||
const [, parentNodePath] = getCommonBlock(
|
||||
editor,
|
||||
@@ -90,7 +90,7 @@ const toggleList = (editor: Editor, format: string): void => {
|
||||
)
|
||||
|
||||
nodesToWrap.forEach(([, path]) => {
|
||||
Transforms.wrapNodes(editor, { children: [], type: 'li' }, { at: path })
|
||||
Transforms.wrapNodes(editor, { type: 'li', children: [] }, { at: path })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import React from 'react'
|
||||
|
||||
import { useElement } from '../../providers/ElementProvider'
|
||||
import './index.scss'
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@ const insertUpload = (editor, { relationTo, value }) => {
|
||||
const text = { text: ' ' }
|
||||
|
||||
const upload = {
|
||||
type: 'upload',
|
||||
children: [text],
|
||||
relationTo,
|
||||
type: 'upload',
|
||||
value,
|
||||
}
|
||||
|
||||
|
||||
@@ -118,9 +118,9 @@ const Element: React.FC<Props & { enabledCollectionSlugs?: string[] }> = ({
|
||||
const swapUpload = React.useCallback(
|
||||
({ collectionSlug, docID }) => {
|
||||
const newNode = {
|
||||
type: uploadName,
|
||||
children: [{ text: ' ' }],
|
||||
relationTo: collectionSlug,
|
||||
type: uploadName,
|
||||
value: { id: docID },
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import { jsx } from 'slate-hyperscript'
|
||||
|
||||
const ELEMENT_TAGS = {
|
||||
A: (el) => ({
|
||||
newTab: el.getAttribute('target') === '_blank',
|
||||
type: 'link',
|
||||
newTab: el.getAttribute('target') === '_blank',
|
||||
url: el.getAttribute('href'),
|
||||
}),
|
||||
BLOCKQUOTE: () => ({ type: 'blockquote' }),
|
||||
|
||||
Reference in New Issue
Block a user