import type { GenericLanguages, I18n, I18nClient } from '@payloadcms/translations'; import type { JSONSchema4 } from 'json-schema'; import type { Klass, LexicalNode, LexicalNodeReplacement, SerializedEditorState, SerializedLexicalNode } from 'lexical'; import type { Config, Field, FieldSchemaMap, JsonObject, PayloadComponent, PayloadRequest, PopulateType, ReplaceAny, RequestContext, RichTextField, RichTextHooks, SanitizedConfig, ValidateOptions, ValidationFieldError } from 'payload'; import type { ServerEditorConfig } from '../lexical/config/types.js'; import type { Transformer } from '../packages/@lexical/markdown/index.js'; import type { AdapterProps } from '../types.js'; import type { HTMLConverter } from './converters/lexicalToHtml_deprecated/converter/types.js'; import type { BaseClientFeatureProps } from './typesClient.js'; export type PopulationPromise = (args: { context: RequestContext; currentDepth: number; depth: number; draft: boolean; /** * This maps all population promises to the node type */ editorPopulationPromises: Map>; field: RichTextField; /** * fieldPromises are used for things like field hooks. They will be awaited before awaiting populationPromises */ fieldPromises: Promise[]; findMany: boolean; flattenLocales: boolean; node: T; overrideAccess: boolean; parentIsLocalized: boolean; populationPromises: Promise[]; req: PayloadRequest; showHiddenFields: boolean; siblingDoc: JsonObject; }) => void; export type NodeValidation = ({ node, nodeValidations, validation, }: { node: T; nodeValidations: Map>; validation: { options: ValidateOptions; value: SerializedEditorState; }; }) => Promise | string | true; export type FeatureProviderProviderServer = (props?: UnSanitizedServerFeatureProps) => FeatureProviderServer; export type FeatureProviderServer = { /** Keys of dependencies needed for this feature. These dependencies do not have to be loaded first, but they have to exist, otherwise an error will be thrown. */ dependencies?: string[]; /** Keys of priority dependencies needed for this feature. These dependencies have to be loaded first AND have to exist, otherwise an error will be thrown. They will be available in the `feature` property. */ dependenciesPriority?: string[]; /** Keys of soft-dependencies needed for this feature. These are optional. Payload will attempt to load them before this feature, but doesn't throw an error if that's not possible. */ dependenciesSoft?: string[]; /** * This is being called during the payload sanitization process */ feature: ((props: { config: SanitizedConfig; /** unSanitizedEditorConfig.features, but mapped */ featureProviderMap: ServerFeatureProviderMap; isRoot?: boolean; parentIsLocalized: boolean; resolvedFeatures: ResolvedServerFeatureMap; unSanitizedEditorConfig: ServerEditorConfig; }) => Promise> | ServerFeature) | ServerFeature; key: string; /** Props which were passed into your feature will have to be passed here. This will allow them to be used / read in other places of the code, e.g. wherever you can use useEditorConfigContext */ serverFeatureProps: UnSanitizedServerFeatureProps; }; export type AfterReadNodeHookArgs = { /** * Only available in `afterRead` hooks. */ currentDepth: number; /** * Only available in `afterRead` hooks. */ depth: number; draft: boolean; fallbackLocale: string; /** * Only available in `afterRead` field hooks. */ fieldPromises: Promise[]; /** Boolean to denote if this hook is running against finding one, or finding many within the afterRead hook. */ findMany: boolean; flattenLocales: boolean; /** * The requested locale. */ locale: string; overrideAccess: boolean; /** * Only available in `afterRead` hooks. */ populateArg?: PopulateType; /** * Only available in `afterRead` field hooks. */ populationPromises: Promise[]; /** * Only available in `afterRead` hooks. */ showHiddenFields: boolean; /** * Only available in `afterRead` hooks. */ triggerAccessControl: boolean; /** * Only available in `afterRead` hooks. */ triggerHooks: boolean; }; export type AfterChangeNodeHookArgs = { /** A string relating to which operation the field type is currently executing within. Useful within beforeValidate, beforeChange, and afterChange hooks to differentiate between create and update operations. */ operation: 'create' | 'delete' | 'read' | 'update'; /** The value of the node before any changes. Not available in afterRead hooks */ originalNode: T; previousNode: T; }; export type BeforeValidateNodeHookArgs = { /** A string relating to which operation the field type is currently executing within. Useful within beforeValidate, beforeChange, and afterChange hooks to differentiate between create and update operations. */ operation: 'create' | 'delete' | 'read' | 'update'; /** The value of the node before any changes. Not available in afterRead hooks */ originalNode: T; overrideAccess: boolean; }; export type BeforeChangeNodeHookArgs = { /** * Only available in `beforeChange` hooks. */ errors: ValidationFieldError[]; mergeLocaleActions: (() => Promise | void)[]; /** A string relating to which operation the field type is currently executing within. Useful within beforeValidate, beforeChange, and afterChange hooks to differentiate between create and update operations. */ operation: 'create' | 'delete' | 'read' | 'update'; /** The value of the node before any changes. Not available in afterRead hooks */ originalNode: T; /** * The original node with locales (not modified by any hooks). */ originalNodeWithLocales?: T; previousNode: T; skipValidation: boolean; }; export type BaseNodeHookArgs = { context: RequestContext; /** The value of the node. */ node: T; parentRichTextFieldPath: (number | string)[]; parentRichTextFieldSchemaPath: string[]; /** The payload request object. It is mocked for Local API operations. */ req: PayloadRequest; }; export type AfterReadNodeHook = (args: AfterReadNodeHookArgs & BaseNodeHookArgs) => Promise | T; export type AfterChangeNodeHook = (args: AfterChangeNodeHookArgs & BaseNodeHookArgs) => Promise | T; export type BeforeChangeNodeHook = (args: BaseNodeHookArgs & BeforeChangeNodeHookArgs) => Promise | T; export type BeforeValidateNodeHook = (args: BaseNodeHookArgs & BeforeValidateNodeHookArgs) => Promise | T; export type NodeWithHooks = { /** * Allows you to define how a node can be serialized into different formats. Currently, only supports html. * Markdown converters are defined in `markdownTransformers` and not here. * * @deprecated - will be removed in 4.0 */ converters?: { /** * @deprecated - will be removed in 4.0 */ html?: HTMLConverter['exportJSON']>>; }; /** * If a node includes sub-fields (e.g. block and link nodes), passing those subFields here will make payload * automatically populate, run hooks, and generate component import maps for them */ getSubFields?: (args: { /** * Optional. If not provided, all possible sub-fields should be returned. */ node?: ReturnType['exportJSON']>; req?: PayloadRequest; }) => Field[] | null; /** * If a node includes sub-fields, the sub-fields data needs to be returned here, alongside `getSubFields` which returns their schema. */ getSubFieldsData?: (args: { node: ReturnType['exportJSON']>; req: PayloadRequest; }) => JsonObject; /** * Allows you to run population logic when a node's data was requested from graphQL. * While `getSubFields` and `getSubFieldsData` automatically handle populating sub-fields (since they run hooks on them), those are only populated in the Rest API. * This is because the Rest API hooks do not have access to the 'depth' property provided by graphQL. * In order for them to be populated correctly in graphQL, the population logic needs to be provided here. */ graphQLPopulationPromises?: Array['exportJSON']>>>; /** * Just like payload fields, you can provide hooks which are run for this specific node. These are called Node Hooks. */ hooks?: { afterChange?: Array['exportJSON']>>>; afterRead?: Array['exportJSON']>>>; beforeChange?: Array['exportJSON']>>>; beforeValidate?: Array['exportJSON']>>>; }; /** * The actual lexical node needs to be provided here. This also supports [lexical node replacements](https://lexical.dev/docs/concepts/node-replacement). */ node: Klass | LexicalNodeReplacement; /** * This allows you to provide node validations, which are run when your document is being validated, alongside other payload fields. * You can use it to throw a validation error for a specific node in case its data is incorrect. */ validations?: Array['exportJSON']>>>; }; export type ServerFeature = { ClientFeature?: PayloadComponent>; /** * This determines what props will be available on the Client. */ clientFeatureProps?: ClientFeatureProps; /** * Adds payload components to the importMap. * * If an object is provided, the imported components will automatically be made available to the client feature, keyed by the object's keys. */ componentImports?: { [key: string]: PayloadComponent; } | Config['admin']['importMap']['generators'][0] | PayloadComponent[]; generatedTypes?: { modifyOutputSchema: (args: { collectionIDFieldTypes: { [key: string]: 'number' | 'string'; }; config?: SanitizedConfig; /** * Current schema which will be modified by this function. */ currentSchema: JSONSchema4; field: RichTextField; i18n?: I18n; /** * Allows you to define new top-level interfaces that can be re-used in the output schema. */ interfaceNameDefinitions: Map; isRequired: boolean; }) => JSONSchema4; }; generateSchemaMap?: (args: { config: SanitizedConfig; field: RichTextField; i18n: I18nClient; props: ServerProps; schemaMap: FieldSchemaMap; schemaPath: string; }) => FieldSchemaMap | null; hooks?: RichTextHooks; /** * Here you can provide i18n translations for your feature. These will only be available on the server and client. * * Translations here are automatically scoped to `lexical.featureKey.yourKey` * * @Example * ```ts * i18n: { * en: { * label: 'Horizontal Rule', * }, * de: { * label: 'Trennlinie', * }, * } * ``` * In order to access these translations, you would use `i18n.t('lexical:horizontalRule:label')`. */ i18n?: Partial; markdownTransformers?: (((props: { allNodes: Array; allTransformers: Transformer[]; }) => Transformer) | Transformer)[]; nodes?: Array; /** Props which were passed into your feature will have to be passed here. This will allow them to be used / read in other places of the code, e.g. wherever you can use useEditorConfigContext */ sanitizedServerFeatureProps?: ServerProps; }; export type ResolvedServerFeature = { order: number; } & Required, 'dependencies' | 'dependenciesPriority' | 'dependenciesSoft' | 'key'>> & ServerFeature; export type ResolvedServerFeatureMap = Map>; export type ServerFeatureProviderMap = Map>; export type SanitizedServerFeatures = { /** The node types mapped to their converters */ converters: { html: HTMLConverter[]; }; /** The keys of all enabled features */ enabledFeatures: string[]; generatedTypes: { modifyOutputSchemas: Array<(args: { collectionIDFieldTypes: { [key: string]: 'number' | 'string'; }; config?: SanitizedConfig; /** * Current schema which will be modified by this function. */ currentSchema: JSONSchema4; field: RichTextField; i18n?: I18n; /** * Allows you to define new top-level interfaces that can be re-used in the output schema. */ interfaceNameDefinitions: Map; isRequired: boolean; }) => JSONSchema4>; }; /** The node types mapped to their hooks */ getSubFields?: Map Field[] | null>; getSubFieldsData?: Map JsonObject>; graphQLPopulationPromises: Map>; hooks: RichTextHooks; markdownTransformers: Transformer[]; nodeHooks?: { afterChange?: Map>>; afterRead?: Map>>; beforeChange?: Map>>; beforeValidate?: Map>>; }; /** The node types mapped to their populationPromises */ /** The node types mapped to their validations */ validations: Map>; } & Required, 'i18n' | 'nodes'>>; //# sourceMappingURL=typesServer.d.ts.map