feat(richtext-lexical)!: change link fields handling (#6162)

**BREAKING:**
- Drawer fields are no longer wrapped in a `fields` group. This might be breaking if you depend on them being in a field group in any way - potentially if you use custom link fields. This does not change how the data is saved
- If you pass in an array of custom fields to the link feature, those were previously added to the base fields. Now, they completely replace the base fields for consistency. If you want to ADD fields to the base fields now, you will have to pass in a function and spread `defaultFields` - similar to how adding your own features to lexical works

**Example Migration for ADDING fields to the link base fields:**

**Previous:**
```ts
 LinkFeature({
    fields: [
      {
        name: 'rel',
        label: 'Rel Attribute',
        type: 'select',
        hasMany: true,
        options: ['noopener', 'noreferrer', 'nofollow'],
        admin: {
          description:
            'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
        },
      },
    ],
  }),
```

**Now:**
```ts
 LinkFeature({
    fields: ({ defaultFields }) => [
      ...defaultFields,
      {
        name: 'rel',
        label: 'Rel Attribute',
        type: 'select',
        hasMany: true,
        options: ['noopener', 'noreferrer', 'nofollow'],
        admin: {
          description:
            'The rel attribute defines the relationship between a linked resource and the current document. This is a custom link field.',
        },
      },
    ],
  }),
This commit is contained in:
Alessio Gravili
2024-04-30 23:01:08 -04:00
committed by GitHub
parent d9bb51fdc7
commit 5a82f34801
11 changed files with 112 additions and 124 deletions

View File

@@ -520,7 +520,7 @@ describe('lexical', () => {
const drawerContent = page.locator('.drawer__content').first()
await expect(drawerContent).toBeVisible()
const urlField = drawerContent.locator('input#field-fields__url').first()
const urlField = drawerContent.locator('input#field-url').first()
await expect(urlField).toBeVisible()
// Fill with https://www.payloadcms.com
await urlField.fill('https://www.payloadcms.com')

View File

@@ -72,7 +72,8 @@ export const LexicalFields: CollectionConfig = {
TreeViewFeature(),
//HTMLConverterFeature(),
LinkFeature({
fields: [
fields: ({ defaultFields }) => [
...defaultFields,
{
name: 'rel',
label: 'Rel Attribute',

View File

@@ -39,7 +39,8 @@ export const LexicalMigrateFields: CollectionConfig = {
TreeViewFeature(),
HTMLConverterFeature(),
LinkFeature({
fields: [
fields: ({ defaultFields }) => [
...defaultFields,
{
name: 'rel',
label: 'Rel Attribute',
@@ -79,7 +80,8 @@ export const LexicalMigrateFields: CollectionConfig = {
TreeViewFeature(),
HTMLConverterFeature(),
LinkFeature({
fields: [
fields: ({ defaultFields }) => [
...defaultFields,
{
name: 'rel',
label: 'Rel Attribute',

View File

@@ -38,7 +38,8 @@ const RichTextFields: CollectionConfig = {
TreeViewFeature(),
HTMLConverterFeature({}),
LinkFeature({
fields: [
fields: ({ defaultFields }) => [
...defaultFields,
{
name: 'rel',
label: 'Rel Attribute',