fix: i18nInit doesn't have to be async, richtext i18n types (#5176)
This commit is contained in:
@@ -69,7 +69,7 @@ export const createPayloadRequest = async ({
|
|||||||
headers: request.headers,
|
headers: request.headers,
|
||||||
})
|
})
|
||||||
|
|
||||||
const i18n = await initI18n({
|
const i18n = initI18n({
|
||||||
config: config.i18n,
|
config: config.i18n,
|
||||||
context: 'api',
|
context: 'api',
|
||||||
language,
|
language,
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export const getNextT = async ({
|
|||||||
config: SanitizedConfig
|
config: SanitizedConfig
|
||||||
language?: string
|
language?: string
|
||||||
}): Promise<TFunction> => {
|
}): Promise<TFunction> => {
|
||||||
const i18n = await initI18n({
|
const i18n = initI18n({
|
||||||
config: config.i18n,
|
config: config.i18n,
|
||||||
context: 'client',
|
context: 'client',
|
||||||
language: language || getRequestLanguage({ cookies: cookies(), headers: headers() }),
|
language: language || getRequestLanguage({ cookies: cookies(), headers: headers() }),
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export const initPage = async ({
|
|||||||
config,
|
config,
|
||||||
})
|
})
|
||||||
|
|
||||||
const i18n = await initI18n({
|
const i18n = initI18n({
|
||||||
config: config.i18n,
|
config: config.i18n,
|
||||||
context: 'client',
|
context: 'client',
|
||||||
language,
|
language,
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
"bson-objectid": "2.0.4",
|
"bson-objectid": "2.0.4",
|
||||||
"classnames": "^2.3.2",
|
"classnames": "^2.3.2",
|
||||||
"deep-equal": "2.2.3",
|
"deep-equal": "2.2.3",
|
||||||
"i18next": "22.5.1",
|
|
||||||
"json-schema": "^0.4.0",
|
"json-schema": "^0.4.0",
|
||||||
"lexical": "0.13.1",
|
"lexical": "0.13.1",
|
||||||
"lodash": "4.17.21",
|
"lodash": "4.17.21",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { i18n } from 'i18next'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { SanitizedConfig } from 'payload/config'
|
import type { SanitizedConfig } from 'payload/config'
|
||||||
import type { Field } from 'payload/types'
|
import type { Field } from 'payload/types'
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ export type LinkFeatureProps = ExclusiveLinkCollectionsProps & {
|
|||||||
* displayed in the link editor drawer.
|
* displayed in the link editor drawer.
|
||||||
*/
|
*/
|
||||||
fields?:
|
fields?:
|
||||||
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: i18n }) => Field[])
|
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: I18n }) => Field[])
|
||||||
| Field[]
|
| Field[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ export const LinkFeature = (props: LinkFeatureProps): FeatureProvider => {
|
|||||||
FeaturesSectionWithEntries([
|
FeaturesSectionWithEntries([
|
||||||
{
|
{
|
||||||
ChildComponent: () =>
|
ChildComponent: () =>
|
||||||
// @ts-ignore-next-line
|
// @ts-expect-error-next-line
|
||||||
import('../../lexical/ui/icons/Link').then((module) => module.LinkIcon),
|
import('../../lexical/ui/icons/Link').then((module) => module.LinkIcon),
|
||||||
isActive: ({ selection }) => {
|
isActive: ({ selection }) => {
|
||||||
if ($isRangeSelection(selection)) {
|
if ($isRangeSelection(selection)) {
|
||||||
@@ -99,6 +99,7 @@ export const LinkFeature = (props: LinkFeatureProps): FeatureProvider => {
|
|||||||
},
|
},
|
||||||
nodes: [
|
nodes: [
|
||||||
{
|
{
|
||||||
|
type: LinkNode.getType(),
|
||||||
converters: {
|
converters: {
|
||||||
html: {
|
html: {
|
||||||
converter: async ({ converters, node, parent }) => {
|
converter: async ({ converters, node, parent }) => {
|
||||||
@@ -125,10 +126,10 @@ export const LinkFeature = (props: LinkFeatureProps): FeatureProvider => {
|
|||||||
},
|
},
|
||||||
node: LinkNode,
|
node: LinkNode,
|
||||||
populationPromises: [linkPopulationPromiseHOC(props)],
|
populationPromises: [linkPopulationPromiseHOC(props)],
|
||||||
type: LinkNode.getType(),
|
|
||||||
// TODO: Add validation similar to upload for internal links and fields
|
// TODO: Add validation similar to upload for internal links and fields
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
type: AutoLinkNode.getType(),
|
||||||
converters: {
|
converters: {
|
||||||
html: {
|
html: {
|
||||||
converter: async ({ converters, node, parent }) => {
|
converter: async ({ converters, node, parent }) => {
|
||||||
@@ -158,31 +159,30 @@ export const LinkFeature = (props: LinkFeatureProps): FeatureProvider => {
|
|||||||
},
|
},
|
||||||
node: AutoLinkNode,
|
node: AutoLinkNode,
|
||||||
populationPromises: [linkPopulationPromiseHOC(props)],
|
populationPromises: [linkPopulationPromiseHOC(props)],
|
||||||
type: AutoLinkNode.getType(),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
{
|
{
|
||||||
Component: () =>
|
Component: () =>
|
||||||
// @ts-ignore-next-line
|
// @ts-expect-error-next-line
|
||||||
import('./plugins/link').then((module) => module.LinkPlugin),
|
import('./plugins/link').then((module) => module.LinkPlugin),
|
||||||
position: 'normal',
|
position: 'normal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Component: () =>
|
Component: () =>
|
||||||
// @ts-ignore-next-line
|
// @ts-expect-error-next-line
|
||||||
import('./plugins/autoLink').then((module) => module.AutoLinkPlugin),
|
import('./plugins/autoLink').then((module) => module.AutoLinkPlugin),
|
||||||
position: 'normal',
|
position: 'normal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Component: () =>
|
Component: () =>
|
||||||
// @ts-ignore-next-line
|
// @ts-expect-error-next-line
|
||||||
import('./plugins/clickableLink').then((module) => module.ClickableLinkPlugin),
|
import('./plugins/clickableLink').then((module) => module.ClickableLinkPlugin),
|
||||||
position: 'normal',
|
position: 'normal',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Component: () =>
|
Component: () =>
|
||||||
// @ts-ignore-next-line
|
// @ts-expect-error-next-line
|
||||||
import('./plugins/floatingLinkEditor').then((module) => {
|
import('./plugins/floatingLinkEditor').then((module) => {
|
||||||
const floatingLinkEditorPlugin = module.FloatingLinkEditorPlugin
|
const floatingLinkEditorPlugin = module.FloatingLinkEditorPlugin
|
||||||
return import('@payloadcms/ui').then((module) =>
|
return import('@payloadcms/ui').then((module) =>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { i18n } from 'i18next'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { SanitizedConfig } from 'payload/config'
|
import type { SanitizedConfig } from 'payload/config'
|
||||||
import type { Field, GroupField } from 'payload/types'
|
import type { Field, GroupField } from 'payload/types'
|
||||||
|
|
||||||
@@ -9,10 +9,10 @@ import { getBaseFields } from '../../drawer/baseFields'
|
|||||||
*/
|
*/
|
||||||
export function transformExtraFields(
|
export function transformExtraFields(
|
||||||
customFieldSchema:
|
customFieldSchema:
|
||||||
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: i18n }) => Field[])
|
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: I18n }) => Field[])
|
||||||
| Field[],
|
| Field[],
|
||||||
config: SanitizedConfig,
|
config: SanitizedConfig,
|
||||||
i18n: i18n,
|
i18n: I18n,
|
||||||
enabledCollections?: false | string[],
|
enabledCollections?: false | string[],
|
||||||
disabledCollections?: false | string[],
|
disabledCollections?: false | string[],
|
||||||
): Field[] {
|
): Field[] {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { i18n } from 'i18next'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { SanitizedConfig } from 'payload/config'
|
import type { SanitizedConfig } from 'payload/config'
|
||||||
import type { Field } from 'payload/types'
|
import type { Field } from 'payload/types'
|
||||||
import type { Editor } from 'slate'
|
import type { Editor } from 'slate'
|
||||||
@@ -16,9 +16,9 @@ export const wrapLink = (editor: Editor): void => {
|
|||||||
const isCollapsed = selection && Range.isCollapsed(selection)
|
const isCollapsed = selection && Range.isCollapsed(selection)
|
||||||
|
|
||||||
const link = {
|
const link = {
|
||||||
|
type: 'link',
|
||||||
children: isCollapsed ? [{ text: '' }] : [],
|
children: isCollapsed ? [{ text: '' }] : [],
|
||||||
newTab: false,
|
newTab: false,
|
||||||
type: 'link',
|
|
||||||
url: undefined,
|
url: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,10 +35,10 @@ export const wrapLink = (editor: Editor): void => {
|
|||||||
*/
|
*/
|
||||||
export function transformExtraFields(
|
export function transformExtraFields(
|
||||||
customFieldSchema:
|
customFieldSchema:
|
||||||
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: i18n }) => Field[])
|
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: I18n }) => Field[])
|
||||||
| Field[],
|
| Field[],
|
||||||
config: SanitizedConfig,
|
config: SanitizedConfig,
|
||||||
i18n: i18n,
|
i18n: I18n,
|
||||||
): Field[] {
|
): Field[] {
|
||||||
const baseFields: Field[] = getBaseFields(config)
|
const baseFields: Field[] = getBaseFields(config)
|
||||||
|
|
||||||
@@ -68,6 +68,7 @@ export function transformExtraFields(
|
|||||||
if (Array.isArray(customFieldSchema) || fields.length > 0) {
|
if (Array.isArray(customFieldSchema) || fields.length > 0) {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: 'fields',
|
name: 'fields',
|
||||||
|
type: 'group',
|
||||||
admin: {
|
admin: {
|
||||||
style: {
|
style: {
|
||||||
borderBottom: 0,
|
borderBottom: 0,
|
||||||
@@ -79,7 +80,6 @@ export function transformExtraFields(
|
|||||||
fields: Array.isArray(customFieldSchema)
|
fields: Array.isArray(customFieldSchema)
|
||||||
? customFieldSchema.concat(extraFields)
|
? customFieldSchema.concat(extraFields)
|
||||||
: extraFields,
|
: extraFields,
|
||||||
type: 'group',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return fields
|
return fields
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { i18n as Ii18n } from 'i18next'
|
import type { I18n } from '@payloadcms/translations'
|
||||||
import type { SanitizedConfig } from 'payload/config'
|
import type { SanitizedConfig } from 'payload/config'
|
||||||
import type { Field, RichTextFieldProps } from 'payload/types'
|
import type { Field, RichTextFieldProps } from 'payload/types'
|
||||||
import type { Editor } from 'slate'
|
import type { Editor } from 'slate'
|
||||||
@@ -59,7 +59,7 @@ export type AdapterArguments = {
|
|||||||
leaves?: RichTextLeaf[]
|
leaves?: RichTextLeaf[]
|
||||||
link?: {
|
link?: {
|
||||||
fields?:
|
fields?:
|
||||||
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: Ii18n }) => Field[])
|
| ((args: { config: SanitizedConfig; defaultFields: Field[]; i18n: I18n }) => Field[])
|
||||||
| Field[]
|
| Field[]
|
||||||
}
|
}
|
||||||
placeholder?: Record<string, string> | string
|
placeholder?: Record<string, string> | string
|
||||||
|
|||||||
@@ -48,4 +48,4 @@ export type InitI18n = (args: {
|
|||||||
language?: string
|
language?: string
|
||||||
translations: Translations
|
translations: Translations
|
||||||
context: 'api' | 'client'
|
context: 'api' | 'client'
|
||||||
}) => Promise<I18n>
|
}) => I18n
|
||||||
|
|||||||
@@ -207,11 +207,11 @@ const initTFunction: InitTFunction = (args) => (key, vars) => {
|
|||||||
function memoize<T>(fn: Function, keys: string[]): T {
|
function memoize<T>(fn: Function, keys: string[]): T {
|
||||||
const cacheMap = new Map()
|
const cacheMap = new Map()
|
||||||
|
|
||||||
return <T>async function (args) {
|
return <T>function (args) {
|
||||||
const cacheKey = keys.reduce((acc, key) => acc + args[key], '')
|
const cacheKey = keys.reduce((acc, key) => acc + args[key], '')
|
||||||
|
|
||||||
if (!cacheMap.has(cacheKey)) {
|
if (!cacheMap.has(cacheKey)) {
|
||||||
const result = await fn(args)
|
const result = fn(args)
|
||||||
cacheMap.set(cacheKey, result)
|
cacheMap.set(cacheKey, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +220,7 @@ function memoize<T>(fn: Function, keys: string[]): T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const initI18n: InitI18n = memoize(
|
export const initI18n: InitI18n = memoize(
|
||||||
<InitI18n>(async ({ config, language = 'en', translations, context }) => {
|
<InitI18n>(({ config, language = 'en', translations, context }) => {
|
||||||
const i18n = {
|
const i18n = {
|
||||||
fallbackLanguage: config.fallbackLanguage,
|
fallbackLanguage: config.fallbackLanguage,
|
||||||
language: language || config.fallbackLanguage,
|
language: language || config.fallbackLanguage,
|
||||||
|
|||||||
75
pnpm-lock.yaml
generated
75
pnpm-lock.yaml
generated
@@ -920,7 +920,7 @@ importers:
|
|||||||
version: 18.2.0
|
version: 18.2.0
|
||||||
ts-node:
|
ts-node:
|
||||||
specifier: 10.9.1
|
specifier: 10.9.1
|
||||||
version: 10.9.1(@swc/core@1.4.2)(@types/node@20.6.2)(typescript@5.2.2)
|
version: 10.9.1(@swc/core@1.4.2)(@types/node@16.18.83)(typescript@5.2.2)
|
||||||
|
|
||||||
packages/plugin-nested-docs:
|
packages/plugin-nested-docs:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
@@ -1141,9 +1141,6 @@ importers:
|
|||||||
deep-equal:
|
deep-equal:
|
||||||
specifier: 2.2.3
|
specifier: 2.2.3
|
||||||
version: 2.2.3
|
version: 2.2.3
|
||||||
i18next:
|
|
||||||
specifier: 22.5.1
|
|
||||||
version: 22.5.1
|
|
||||||
json-schema:
|
json-schema:
|
||||||
specifier: ^0.4.0
|
specifier: ^0.4.0
|
||||||
version: 0.4.0
|
version: 0.4.0
|
||||||
@@ -9971,12 +9968,6 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/i18next@22.5.1:
|
|
||||||
resolution: {integrity: sha512-8TGPgM3pAD+VRsMtUMNknRz3kzqwp/gPALrWMsDnmC1mKqJwpWyooQRLMcbTwq8z8YwSmuj+ZYvc+xCuEpkssA==}
|
|
||||||
dependencies:
|
|
||||||
'@babel/runtime': 7.23.9
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/iconv-lite@0.4.24:
|
/iconv-lite@0.4.24:
|
||||||
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
@@ -15299,6 +15290,38 @@ packages:
|
|||||||
yargs-parser: 21.1.1
|
yargs-parser: 21.1.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/ts-node@10.9.1(@swc/core@1.4.2)(@types/node@16.18.83)(typescript@5.2.2):
|
||||||
|
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
||||||
|
hasBin: true
|
||||||
|
peerDependencies:
|
||||||
|
'@swc/core': '>=1.2.50'
|
||||||
|
'@swc/wasm': '>=1.2.50'
|
||||||
|
'@types/node': '*'
|
||||||
|
typescript: '>=2.7'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
'@swc/core':
|
||||||
|
optional: true
|
||||||
|
'@swc/wasm':
|
||||||
|
optional: true
|
||||||
|
dependencies:
|
||||||
|
'@cspotcode/source-map-support': 0.8.1
|
||||||
|
'@swc/core': 1.4.2
|
||||||
|
'@tsconfig/node10': 1.0.9
|
||||||
|
'@tsconfig/node12': 1.0.11
|
||||||
|
'@tsconfig/node14': 1.0.3
|
||||||
|
'@tsconfig/node16': 1.0.4
|
||||||
|
'@types/node': 16.18.83
|
||||||
|
acorn: 8.11.3
|
||||||
|
acorn-walk: 8.3.2
|
||||||
|
arg: 4.1.3
|
||||||
|
create-require: 1.1.1
|
||||||
|
diff: 4.0.2
|
||||||
|
make-error: 1.3.6
|
||||||
|
typescript: 5.2.2
|
||||||
|
v8-compile-cache-lib: 3.0.1
|
||||||
|
yn: 3.1.1
|
||||||
|
dev: true
|
||||||
|
|
||||||
/ts-node@10.9.1(@swc/core@1.4.2)(@types/node@20.5.7)(typescript@5.2.2):
|
/ts-node@10.9.1(@swc/core@1.4.2)(@types/node@20.5.7)(typescript@5.2.2):
|
||||||
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -15330,38 +15353,6 @@ packages:
|
|||||||
v8-compile-cache-lib: 3.0.1
|
v8-compile-cache-lib: 3.0.1
|
||||||
yn: 3.1.1
|
yn: 3.1.1
|
||||||
|
|
||||||
/ts-node@10.9.1(@swc/core@1.4.2)(@types/node@20.6.2)(typescript@5.2.2):
|
|
||||||
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
|
|
||||||
hasBin: true
|
|
||||||
peerDependencies:
|
|
||||||
'@swc/core': '>=1.2.50'
|
|
||||||
'@swc/wasm': '>=1.2.50'
|
|
||||||
'@types/node': '*'
|
|
||||||
typescript: '>=2.7'
|
|
||||||
peerDependenciesMeta:
|
|
||||||
'@swc/core':
|
|
||||||
optional: true
|
|
||||||
'@swc/wasm':
|
|
||||||
optional: true
|
|
||||||
dependencies:
|
|
||||||
'@cspotcode/source-map-support': 0.8.1
|
|
||||||
'@swc/core': 1.4.2
|
|
||||||
'@tsconfig/node10': 1.0.9
|
|
||||||
'@tsconfig/node12': 1.0.11
|
|
||||||
'@tsconfig/node14': 1.0.3
|
|
||||||
'@tsconfig/node16': 1.0.4
|
|
||||||
'@types/node': 20.6.2
|
|
||||||
acorn: 8.11.3
|
|
||||||
acorn-walk: 8.3.2
|
|
||||||
arg: 4.1.3
|
|
||||||
create-require: 1.1.1
|
|
||||||
diff: 4.0.2
|
|
||||||
make-error: 1.3.6
|
|
||||||
typescript: 5.2.2
|
|
||||||
v8-compile-cache-lib: 3.0.1
|
|
||||||
yn: 3.1.1
|
|
||||||
dev: true
|
|
||||||
|
|
||||||
/ts-node@9.1.1(typescript@5.2.2):
|
/ts-node@9.1.1(typescript@5.2.2):
|
||||||
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
|
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
|
||||||
engines: {node: '>=10.0.0'}
|
engines: {node: '>=10.0.0'}
|
||||||
|
|||||||
Reference in New Issue
Block a user