feat(richtext-lexical)!: sub-field hooks and localization support (#6591)

## BREAKING
- Our internal field hook methods now have new required `schemaPath` and
path `props`. This affects the following functions, if you are using
those: `afterChangeTraverseFields`, `afterReadTraverseFields`,
`beforeChangeTraverseFields`, `beforeValidateTraverseFields`,
`afterReadPromise`
- The afterChange field hook's `value` is now the value AFTER the
previous hooks were run. Previously, this was the original value, which
I believe is a bug
- Only relevant if you have built your own richText adapter: the
richText adapter `populationPromises` property has been renamed to
`graphQLPopulationPromises` and is now only run for graphQL. Previously,
it was run for graphQL AND the rest API. To migrate, use
`hooks.afterRead` to run population for the rest API
- Only relevant if you have built your own lexical features: The
`populationPromises` server feature property has been renamed to
`graphQLPopulationPromises` and is now only run for graphQL. Previously,
it was run for graphQL AND the rest API. To migrate, use
`hooks.afterRead` to run population for the rest API
- Serialized lexical link and upload nodes now have a new `id` property.
While not breaking, localization / hooks will not work for their fields
until you have migrated to that. Re-saving the old document on the new
version will automatically add the `id` property for you. You will also
get a bunch of console logs for every lexical node which is not migrated
This commit is contained in:
Alessio Gravili
2024-06-12 13:33:08 -04:00
committed by GitHub
parent 27510bb963
commit 4e127054ca
62 changed files with 1959 additions and 514 deletions

View File

@@ -7,6 +7,7 @@ import type { NestedAfterReadHook } from './payload-types.js'
import { devUser, regularUser } from '../credentials.js'
import { initPayloadInt } from '../helpers/initPayloadInt.js'
import { isMongoose } from '../helpers/isMongoose.js'
import { afterOperationSlug } from './collections/AfterOperation/index.js'
import { chainingHooksSlug } from './collections/ChainingHooks/index.js'
import { contextHooksSlug } from './collections/ContextHooks/index.js'
@@ -35,22 +36,23 @@ describe('Hooks', () => {
await payload.db.destroy()
}
})
if (isMongoose(payload)) {
describe('transform actions', () => {
it('should create and not throw an error', async () => {
// the collection has hooks that will cause an error if transform actions is not handled properly
const doc = await payload.create({
collection: transformSlug,
data: {
localizedTransform: [2, 8],
transform: [2, 8],
},
})
describe('transform actions', () => {
it('should create and not throw an error', async () => {
// the collection has hooks that will cause an error if transform actions is not handled properly
const doc = await payload.create({
collection: transformSlug,
data: {
localizedTransform: [2, 8],
transform: [2, 8],
},
expect(doc.transform).toBeDefined()
expect(doc.localizedTransform).toBeDefined()
})
expect(doc.transform).toBeDefined()
expect(doc.localizedTransform).toBeDefined()
})
})
}
describe('hook execution', () => {
let doc