You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
@@ -15,6 +17,173 @@ export type RichTextFieldProps<
15
17
path?: string
16
18
}
17
19
20
+
exporttypeAfterReadRichTextHookArgs<
21
+
TDataextendsTypeWithID=any,
22
+
TValue=any,
23
+
TSiblingData=any,
24
+
>={
25
+
currentDepth?: number
26
+
27
+
depth?: number
28
+
29
+
draft?: boolean
30
+
31
+
fallbackLocale?: string
32
+
33
+
fieldPromises?: Promise<void>[]
34
+
35
+
/** Boolean to denote if this hook is running against finding one, or finding many within the afterRead hook. */
36
+
findMany?: boolean
37
+
38
+
flattenLocales?: boolean
39
+
40
+
locale?: string
41
+
42
+
/** A string relating to which operation the field type is currently executing within. */
43
+
operation?: 'create'|'delete'|'read'|'update'
44
+
45
+
overrideAccess?: boolean
46
+
47
+
populationPromises?: Promise<void>[]
48
+
showHiddenFields?: boolean
49
+
triggerAccessControl?: boolean
50
+
triggerHooks?: boolean
51
+
}
52
+
53
+
exporttypeAfterChangeRichTextHookArgs<
54
+
TDataextendsTypeWithID=any,
55
+
TValue=any,
56
+
TSiblingData=any,
57
+
>={
58
+
/** A string relating to which operation the field type is currently executing within. */
59
+
operation: 'create'|'update'
60
+
/** The document before changes were applied. */
61
+
previousDoc?: TData
62
+
/** The sibling data of the document before changes being applied. */
63
+
previousSiblingDoc?: TData
64
+
/** The previous value of the field, before changes */
65
+
previousValue?: TValue
66
+
}
67
+
exporttypeBeforeValidateRichTextHookArgs<
68
+
TDataextendsTypeWithID=any,
69
+
TValue=any,
70
+
TSiblingData=any,
71
+
>={
72
+
/** A string relating to which operation the field type is currently executing within. */
73
+
operation: 'create'|'update'
74
+
overrideAccess?: boolean
75
+
/** The sibling data of the document before changes being applied. */
76
+
previousSiblingDoc?: TData
77
+
/** The previous value of the field, before changes */
78
+
previousValue?: TValue
79
+
}
80
+
81
+
exporttypeBeforeChangeRichTextHookArgs<
82
+
TDataextendsTypeWithID=any,
83
+
TValue=any,
84
+
TSiblingData=any,
85
+
>={
86
+
/**
87
+
* The original data with locales (not modified by any hooks). Only available in `beforeChange` and `beforeDuplicate` field hooks.
88
+
*/
89
+
docWithLocales?: Record<string,unknown>
90
+
91
+
duplicate?: boolean
92
+
93
+
errors?: {field: string;message: string}[]
94
+
/** Only available in `beforeChange` field hooks */
95
+
mergeLocaleActions?: (()=>Promise<void>)[]
96
+
/** A string relating to which operation the field type is currently executing within. */
97
+
operation?: 'create'|'delete'|'read'|'update'
98
+
/** The sibling data of the document before changes being applied. */
99
+
previousSiblingDoc?: TData
100
+
/** The previous value of the field, before changes */
101
+
previousValue?: TValue
102
+
/**
103
+
* The original siblingData with locales (not modified by any hooks).
104
+
*/
105
+
siblingDocWithLocales?: Record<string,unknown>
106
+
107
+
skipValidation?: boolean
108
+
}
109
+
110
+
exporttypeBaseRichTextHookArgs<
111
+
TDataextendsTypeWithID=any,
112
+
TValue=any,
113
+
TSiblingData=any,
114
+
>={
115
+
/** The collection which the field belongs to. If the field belongs to a global, this will be null. */
116
+
collection: SanitizedCollectionConfig|null
117
+
context: RequestContext
118
+
/** The data passed to update the document within create and update operations, and the full document itself in the afterRead hook. */
119
+
data?: Partial<TData>
120
+
/** The field which the hook is running against. */
121
+
field: FieldAffectingData
122
+
/** The global which the field belongs to. If the field belongs to a collection, this will be null. */
123
+
global: SanitizedGlobalConfig|null
124
+
125
+
/** The full original document in `update` operations. In the `afterChange` hook, this is the resulting document of the operation. */
126
+
originalDoc?: TData
127
+
/**
128
+
* The path of the field, e.g. ["group", "myArray", 1, "textField"]. The path is the schemaPath but with indexes and would be used in the context of field data, not field schemas.
129
+
*/
130
+
path: (number|string)[]
131
+
132
+
/** The Express request object. It is mocked for Local API operations. */
133
+
req: PayloadRequestWithData
134
+
/**
135
+
* The schemaPath of the field, e.g. ["group", "myArray", "textField"]. The schemaPath is the path but without indexes and would be used in the context of field schemas, not field data.
136
+
*/
137
+
schemaPath: string[]
138
+
/** The sibling data passed to a field that the hook is running against. */
* Allows you to define new top-level interfaces that can be re-used in the output schema.
49
-
*/
50
-
interfaceNameDefinitions: Map<string,JSONSchema4>
51
-
isRequired: boolean
52
-
})=>JSONSchema4
53
204
/**
54
-
* Like an afterRead hook, but runs for both afterRead AND in the GraphQL resolver. For populating data, this should be used.
205
+
* Like an afterRead hook, but runs only for the GraphQL resolver. For populating data, this should be used, as afterRead hooks do not have a depth in graphQL.
55
206
*
56
207
* To populate stuff / resolve field hooks, mutate the incoming populationPromises or fieldPromises array. They will then be awaited in the correct order within payload itself.
/** The full original document in `update` operations. In the `afterChange` hook, this is the resulting document of the operation. */
42
42
originalDoc?: TData
43
43
overrideAccess?: boolean
44
+
/**
45
+
* The path of the field, e.g. ["group", "myArray", 1, "textField"]. The path is the schemaPath but with indexes and would be used in the context of field data, not field schemas.
46
+
*/
47
+
path: (number|string)[]
44
48
/** The document before changes were applied, only in `afterChange` hooks. */
45
49
previousDoc?: TData
46
-
/** The sibling data of the document before changes being applied, only in `beforeChange`and `afterChange` hook. */
50
+
/** The sibling data of the document before changes being applied, only in `beforeChange`, `beforeValidate`, `beforeDuplicate` and `afterChange` field hooks. */
47
51
previousSiblingDoc?: TData
48
-
/** The previous value of the field, before changes, only in `beforeChange`, `afterChange`and `beforeValidate` hooks. */
52
+
/** The previous value of the field, before changes, only in `beforeChange`, `afterChange`, `beforeDuplicate` and `beforeValidate` field hooks. */
49
53
previousValue?: TValue
50
54
/** The Express request object. It is mocked for Local API operations. */
51
55
req: PayloadRequestWithData
56
+
/**
57
+
* The schemaPath of the field, e.g. ["group", "myArray", "textField"]. The schemaPath is the path but without indexes and would be used in the context of field schemas, not field data.
58
+
*/
59
+
schemaPath: string[]
52
60
/** The sibling data passed to a field that the hook is running against. */
53
61
siblingData: Partial<TSiblingData>
62
+
/**
63
+
* The original siblingData with locales (not modified by any hooks). Only available in `beforeChange` and `beforeDuplicate` field hooks.
0 commit comments