Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(richtext-lexical): expose client config to client features #11054

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/richtext-lexical/src/features/typesClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
LexicalNodeReplacement,
TextFormatType,
} from 'lexical'
import type { RichTextFieldClient } from 'payload'
import type { ClientConfig, RichTextFieldClient } from 'payload'
import type React from 'react'
import type { JSX } from 'react'

Expand Down Expand Up @@ -33,6 +33,7 @@ export type FeatureProviderClient<
clientFeatureProps: BaseClientFeatureProps<UnSanitizedClientFeatureProps>
feature:
| ((props: {
config: ClientConfig
featureClientSchemaMap: FeatureClientSchemaMap
/** unSanitizedEditorConfig.features, but mapped */
featureProviderMap: ClientFeatureProviderMap
Expand Down
6 changes: 5 additions & 1 deletion packages/richtext-lexical/src/field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import type { RichTextFieldClient } from 'payload'

import { ShimmerEffect } from '@payloadcms/ui'
import { ShimmerEffect, useConfig } from '@payloadcms/ui'
import React, { lazy, Suspense, useEffect, useState } from 'react'

import type { FeatureProviderClient } from '../features/typesClient.js'
Expand All @@ -27,6 +27,8 @@ export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => {
schemaPath,
} = props

const { config } = useConfig()

const [finalSanitizedEditorConfig, setFinalSanitizedEditorConfig] =
useState<null | SanitizedClientEditorConfig>(null)

Expand All @@ -50,6 +52,7 @@ export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => {
: defaultEditorLexicalConfig

const resolvedClientFeatures = loadClientFeatures({
config,
featureClientSchemaMap,
field: field as RichTextFieldClient,
schemaPath: schemaPath ?? field.name,
Expand All @@ -69,6 +72,7 @@ export const RichTextField: React.FC<LexicalRichTextFieldProps> = (props) => {
clientFeatures,
featureClientSchemaMap,
field,
config,
schemaPath,
]) // TODO: Optimize this and use useMemo for this in the future. This might break sub-richtext-blocks from the blocks feature. Need to investigate

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import type { RichTextFieldClient } from 'payload'
import type { ClientConfig, RichTextFieldClient } from 'payload'

import type {
ClientFeatureProviderMap,
Expand All @@ -15,11 +15,13 @@ import type { ClientEditorConfig } from '../types.js'
* @param unSanitizedEditorConfig
*/
export function loadClientFeatures({
config,
featureClientSchemaMap,
field,
schemaPath,
unSanitizedEditorConfig,
}: {
config: ClientConfig
featureClientSchemaMap: FeatureClientSchemaMap
field?: RichTextFieldClient
schemaPath: string
Expand Down Expand Up @@ -55,6 +57,7 @@ export function loadClientFeatures({
const feature: Partial<ResolvedClientFeature<any>> =
typeof featureProvider.feature === 'function'
? featureProvider.feature({
config,
featureClientSchemaMap,
featureProviderMap,
field,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RichTextFieldClient } from 'payload'
import type { ClientConfig, RichTextFieldClient } from 'payload'

import type {
BaseClientFeatureProps,
Expand All @@ -13,6 +13,7 @@ import type { FeatureClientSchemaMap } from '../types.js'

export type CreateClientFeatureArgs<UnSanitizedClientProps, ClientProps> =
| ((props: {
config: ClientConfig
featureClientSchemaMap: FeatureClientSchemaMap
/** unSanitizedEditorConfig.features, but mapped */
featureProviderMap: ClientFeatureProviderMap
Expand All @@ -39,6 +40,7 @@ export const createClientFeature: <

if (typeof feature === 'function') {
featureProviderClient.feature = ({
config,
featureClientSchemaMap,
featureProviderMap,
field,
Expand All @@ -47,6 +49,7 @@ export const createClientFeature: <
unSanitizedEditorConfig,
}) => {
const toReturn = feature({
config,
featureClientSchemaMap,
featureProviderMap,
field,
Expand Down