Skip to content

Commit 16c1d94

Browse files
authored
fix(richtext-lexical): avoid conflicts between internal component/schema map paths and field names (#7042)
1 parent 6a3386c commit 16c1d94

File tree

7 files changed

+25
-15
lines changed

7 files changed

+25
-15
lines changed

packages/richtext-lexical/src/cell/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const RichTextCell: React.FC<
6262

6363
Object.entries(clientFunctions).forEach(([key, plugin]) => {
6464
if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {
65-
if (!key.includes('.components.')) {
65+
if (!key.includes('.lexical_internal_components.')) {
6666
featureProvidersLocal.push(plugin)
6767
}
6868
featureProvidersAndComponentsLoaded++
@@ -167,7 +167,9 @@ export const RichTextCell: React.FC<
167167
featureProviderComponents.map((featureProvider) => {
168168
// get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}
169169
const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>
170-
key.startsWith(`feature.${featureProvider.key}.components.`),
170+
key.startsWith(
171+
`lexical_internal_feature.${featureProvider.key}.lexical_internal_components.`,
172+
),
171173
)
172174

173175
const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {

packages/richtext-lexical/src/features/blocks/component/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const BlockComponent: React.FC<Props> = (props) => {
5656
field: { richTextComponentMap },
5757
} = useEditorConfigContext()
5858

59-
const componentMapRenderedFieldsPath = `feature.blocks.fields.${formData?.blockType}`
60-
const schemaFieldsPath = `${schemaPath}.feature.blocks.${formData?.blockType}`
59+
const componentMapRenderedFieldsPath = `lexical_internal_feature.blocks.fields.${formData?.blockType}`
60+
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.${formData?.blockType}`
6161

6262
const reducedBlock: ReducedBlock = (
6363
editorConfig?.resolvedFeatureMap?.get('blocks')
@@ -145,7 +145,7 @@ export const BlockComponent: React.FC<Props> = (props) => {
145145
formData={formData}
146146
formSchema={Array.isArray(fieldMap) ? fieldMap : []}
147147
nodeKey={nodeKey}
148-
path={`${path}.feature.blocks.${formData.blockType}`}
148+
path={`${path}.lexical_internal_feature.blocks.${formData.blockType}`}
149149
reducedBlock={reducedBlock}
150150
schemaPath={schemaFieldsPath}
151151
/>

packages/richtext-lexical/src/features/createFeaturePropComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const useLexicalFeatureProp = <T,>(featureKey: string, componentKey: string, pro
1313
const schemaPath = schemaPathFromCellProps || schemaPathFromFieldProps // schemaPathFromCellProps needs to have priority, as there can be cells within fields (e.g. list drawers) and the cell schemaPath needs to be used there - not the parent field schemaPath. There cannot be fields within cells.
1414

1515
useAddClientFunction(
16-
`lexicalFeature.${schemaPath}.${featureKey}.components.${componentKey}`,
16+
`lexicalFeature.${schemaPath}.${featureKey}.lexical_internal_components.${componentKey}`,
1717
prop,
1818
)
1919
}

packages/richtext-lexical/src/field/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ export const RichTextField: React.FC<
4646
let featureProvidersAndComponentsToLoad = 0 // feature providers and components
4747
for (const featureProvider of featureProviderComponents) {
4848
const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>
49-
key.startsWith(`feature.${featureProvider.key}.components.`),
49+
key.startsWith(
50+
`lexical_internal_feature.${featureProvider.key}.lexical_internal_components.`,
51+
),
5052
)
5153

5254
featureProvidersAndComponentsToLoad += 1
@@ -60,9 +62,10 @@ export const RichTextField: React.FC<
6062

6163
Object.entries(clientFunctions).forEach(([key, plugin]) => {
6264
if (key.startsWith(`lexicalFeature.${schemaPath}.`)) {
63-
if (!key.includes('.components.')) {
65+
if (!key.includes('.lexical_internal_components.')) {
6466
featureProvidersLocal.push(plugin)
6567
}
68+
6669
featureProvidersAndComponentsLoaded++
6770
}
6871
})
@@ -112,7 +115,9 @@ export const RichTextField: React.FC<
112115
featureProviderComponents.map((featureProvider) => {
113116
// get all components starting with key feature.${FeatureProvider.key}.components.{featureComponentKey}
114117
const featureComponentKeys = Array.from(richTextComponentMap.keys()).filter((key) =>
115-
key.startsWith(`feature.${featureProvider.key}.components.`),
118+
key.startsWith(
119+
`lexical_internal_feature.${featureProvider.key}.lexical_internal_components.`,
120+
),
116121
)
117122
const featureComponents: React.ReactNode[] = featureComponentKeys.map((key) => {
118123
return richTextComponentMap.get(key)

packages/richtext-lexical/src/utilities/fieldsDrawer/DrawerContent.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const DrawerContent: React.FC<Omit<FieldsDrawerProps, 'drawerSlug' | 'dra
3434
field: { richTextComponentMap },
3535
} = useEditorConfigContext()
3636

37-
const componentMapRenderedFieldsPath = `feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`
38-
const schemaFieldsPath = `${schemaPath}.feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`
37+
const componentMapRenderedFieldsPath = `lexical_internal_feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`
38+
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.${featureKey}${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`
3939

4040
const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema
4141

packages/richtext-lexical/src/utilities/generateComponentMap.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const getGenerateComponentMap =
4444

4545
if (Component) {
4646
componentMap.set(
47-
`feature.${featureKey}.components.${componentKey}`,
47+
`lexical_internal_feature.${featureKey}.lexical_internal_components.${componentKey}`,
4848
<WithServerSideProps
4949
Component={Component}
5050
componentKey={componentKey}
@@ -79,11 +79,14 @@ export const getGenerateComponentMap =
7979
disableAddingID: true,
8080
fieldSchema: fields,
8181
i18n,
82-
parentPath: `${schemaPath}.feature.${featureKey}.fields.${schemaKey}`,
82+
parentPath: `${schemaPath}.lexical_internal_feature.${featureKey}.fields.${schemaKey}`,
8383
readOnly: false,
8484
})
8585

86-
componentMap.set(`feature.${featureKey}.fields.${schemaKey}`, mappedFields)
86+
componentMap.set(
87+
`lexical_internal_feature.${featureKey}.fields.${schemaKey}`,
88+
mappedFields,
89+
)
8790
}
8891
}
8992
}

packages/richtext-lexical/src/utilities/generateSchemaMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const getGenerateSchemaMap =
3333
schemaPath: schemaKey,
3434
})
3535

36-
schemaMap.set(`${schemaPath}.feature.${featureKey}.${schemaKey}`, fields)
36+
schemaMap.set(`${schemaPath}.lexical_internal_feature.${featureKey}.${schemaKey}`, fields)
3737
}
3838
}
3939
}

0 commit comments

Comments
 (0)