@payloadcms/ui 3.1.0 → 3.1.1-canary.952fd26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/client/index.js +9 -9
- package/dist/exports/client/index.js.map +3 -3
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +2 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +10 -0
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.d.ts +7 -1
- package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.js +5 -0
- package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +3 -2
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js +2 -0
- package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +4 -3
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts +2 -1
- package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
- package/dist/providers/Locale/index.js +30 -29
- package/dist/providers/Locale/index.js.map +1 -1
- package/dist/utilities/buildClientFieldSchemaMap/index.d.ts +16 -0
- package/dist/utilities/buildClientFieldSchemaMap/index.d.ts.map +1 -0
- package/dist/utilities/buildClientFieldSchemaMap/index.js +72 -0
- package/dist/utilities/buildClientFieldSchemaMap/index.js.map +1 -0
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts +15 -0
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts.map +1 -0
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js +129 -0
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js.map +1 -0
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts +1 -8
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +19 -41
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/buildTableState.d.ts +1 -7
- package/dist/utilities/buildTableState.d.ts.map +1 -1
- package/dist/utilities/buildTableState.js +2 -21
- package/dist/utilities/buildTableState.js.map +1 -1
- package/dist/utilities/getClientConfig.d.ts +8 -0
- package/dist/utilities/getClientConfig.d.ts.map +1 -0
- package/dist/utilities/getClientConfig.js +25 -0
- package/dist/utilities/getClientConfig.js.map +1 -0
- package/dist/utilities/getClientSchemaMap.d.ts +11 -0
- package/dist/utilities/getClientSchemaMap.d.ts.map +1 -0
- package/dist/utilities/getClientSchemaMap.js +39 -0
- package/dist/utilities/getClientSchemaMap.js.map +1 -0
- package/dist/utilities/getSchemaMap.d.ts +9 -0
- package/dist/utilities/getSchemaMap.d.ts.map +1 -0
- package/dist/utilities/getSchemaMap.js +35 -0
- package/dist/utilities/getSchemaMap.js.map +1 -0
- package/dist/views/Edit/Auth/types.d.ts +2 -2
- package/dist/views/Edit/Auth/types.d.ts.map +1 -1
- package/dist/views/Edit/Auth/types.js.map +1 -1
- package/package.json +5 -5
|
@@ -18,8 +18,9 @@ export const LocaleProvider = t0 => {
|
|
|
18
18
|
config: t1
|
|
19
19
|
} = useConfig();
|
|
20
20
|
const {
|
|
21
|
-
localization
|
|
21
|
+
localization: t2
|
|
22
22
|
} = t1;
|
|
23
|
+
const localization = t2 === undefined ? false : t2;
|
|
23
24
|
const {
|
|
24
25
|
user
|
|
25
26
|
} = useAuth();
|
|
@@ -29,23 +30,23 @@ export const LocaleProvider = t0 => {
|
|
|
29
30
|
} = useSearchParams();
|
|
30
31
|
const localeFromParams = searchParams?.locale;
|
|
31
32
|
const [localeCode, setLocaleCode] = useState(localeFromParams || defaultLocale);
|
|
32
|
-
let
|
|
33
|
+
let t3;
|
|
33
34
|
if ($[0] !== localization || $[1] !== localeCode) {
|
|
34
|
-
|
|
35
|
+
t3 = localization && findLocaleFromCode(localization, localeCode);
|
|
35
36
|
$[0] = localization;
|
|
36
37
|
$[1] = localeCode;
|
|
37
|
-
$[2] =
|
|
38
|
+
$[2] = t3;
|
|
38
39
|
} else {
|
|
39
|
-
|
|
40
|
+
t3 = $[2];
|
|
40
41
|
}
|
|
41
|
-
const [locale, setLocale] = useState(
|
|
42
|
+
const [locale, setLocale] = useState(t3);
|
|
42
43
|
const {
|
|
43
44
|
getPreference,
|
|
44
45
|
setPreference
|
|
45
46
|
} = usePreferences();
|
|
46
|
-
let
|
|
47
|
+
let t4;
|
|
47
48
|
if ($[3] !== localization || $[4] !== defaultLocale || $[5] !== localeCode || $[6] !== user || $[7] !== setPreference) {
|
|
48
|
-
|
|
49
|
+
t4 = async newLocale => {
|
|
49
50
|
if (!localization) {
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
@@ -58,8 +59,8 @@ export const LocaleProvider = t0 => {
|
|
|
58
59
|
if (user) {
|
|
59
60
|
await setPreference("locale", localeToSet);
|
|
60
61
|
}
|
|
61
|
-
} catch (
|
|
62
|
-
const error =
|
|
62
|
+
} catch (t5) {
|
|
63
|
+
const error = t5;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
};
|
|
@@ -68,14 +69,14 @@ export const LocaleProvider = t0 => {
|
|
|
68
69
|
$[5] = localeCode;
|
|
69
70
|
$[6] = user;
|
|
70
71
|
$[7] = setPreference;
|
|
71
|
-
$[8] =
|
|
72
|
+
$[8] = t4;
|
|
72
73
|
} else {
|
|
73
|
-
|
|
74
|
+
t4 = $[8];
|
|
74
75
|
}
|
|
75
|
-
const switchLocale =
|
|
76
|
-
let
|
|
76
|
+
const switchLocale = t4;
|
|
77
|
+
let t5;
|
|
77
78
|
if ($[9] !== defaultLocale || $[10] !== localeFromParams || $[11] !== user || $[12] !== getPreference || $[13] !== switchLocale) {
|
|
78
|
-
|
|
79
|
+
t5 = () => {
|
|
79
80
|
const setInitialLocale = async function setInitialLocale() {
|
|
80
81
|
let localeToSet_0 = defaultLocale;
|
|
81
82
|
if (typeof localeFromParams === "string") {
|
|
@@ -85,8 +86,8 @@ export const LocaleProvider = t0 => {
|
|
|
85
86
|
;
|
|
86
87
|
try {
|
|
87
88
|
localeToSet_0 = await getPreference("locale");
|
|
88
|
-
} catch (
|
|
89
|
-
const error_0 =
|
|
89
|
+
} catch (t6) {
|
|
90
|
+
const error_0 = t6;
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -99,13 +100,13 @@ export const LocaleProvider = t0 => {
|
|
|
99
100
|
$[11] = user;
|
|
100
101
|
$[12] = getPreference;
|
|
101
102
|
$[13] = switchLocale;
|
|
102
|
-
$[14] =
|
|
103
|
+
$[14] = t5;
|
|
103
104
|
} else {
|
|
104
|
-
|
|
105
|
+
t5 = $[14];
|
|
105
106
|
}
|
|
106
|
-
let
|
|
107
|
+
let t6;
|
|
107
108
|
if ($[15] !== defaultLocale || $[16] !== getPreference || $[17] !== localization || $[18] !== localeFromParams || $[19] !== setPreference || $[20] !== user || $[21] !== switchLocale) {
|
|
108
|
-
|
|
109
|
+
t6 = [defaultLocale, getPreference, localization, localeFromParams, setPreference, user, switchLocale];
|
|
109
110
|
$[15] = defaultLocale;
|
|
110
111
|
$[16] = getPreference;
|
|
111
112
|
$[17] = localization;
|
|
@@ -113,24 +114,24 @@ export const LocaleProvider = t0 => {
|
|
|
113
114
|
$[19] = setPreference;
|
|
114
115
|
$[20] = user;
|
|
115
116
|
$[21] = switchLocale;
|
|
116
|
-
$[22] =
|
|
117
|
+
$[22] = t6;
|
|
117
118
|
} else {
|
|
118
|
-
|
|
119
|
+
t6 = $[22];
|
|
119
120
|
}
|
|
120
|
-
useEffect(
|
|
121
|
-
let
|
|
121
|
+
useEffect(t5, t6);
|
|
122
|
+
let t7;
|
|
122
123
|
if ($[23] !== locale || $[24] !== children) {
|
|
123
|
-
|
|
124
|
+
t7 = _jsx(LocaleContext.Provider, {
|
|
124
125
|
value: locale,
|
|
125
126
|
children
|
|
126
127
|
});
|
|
127
128
|
$[23] = locale;
|
|
128
129
|
$[24] = children;
|
|
129
|
-
$[25] =
|
|
130
|
+
$[25] = t7;
|
|
130
131
|
} else {
|
|
131
|
-
|
|
132
|
+
t7 = $[25];
|
|
132
133
|
}
|
|
133
|
-
return
|
|
134
|
+
return t7;
|
|
134
135
|
};
|
|
135
136
|
/**
|
|
136
137
|
* A hook that returns the current locale object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","createContext","useContext","useEffect","useState","findLocaleFromCode","useAuth","useConfig","usePreferences","useSearchParams","LocaleContext","LocaleProvider","t0","$","children","config","t1","localization","user","defaultLocale","searchParams","localeFromParams","locale","localeCode","setLocaleCode","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","createContext","useContext","useEffect","useState","findLocaleFromCode","useAuth","useConfig","usePreferences","useSearchParams","LocaleContext","LocaleProvider","t0","$","children","config","t1","localization","t2","undefined","user","defaultLocale","searchParams","localeFromParams","locale","localeCode","setLocaleCode","t3","setLocale","getPreference","setPreference","t4","newLocale","localeToSet","localeCodes","indexOf","t5","error","switchLocale","setInitialLocale","localeToSet_0","t6","t7","_jsx","Provider","value","useLocale"],"sources":["../../../src/providers/Locale/index.tsx"],"sourcesContent":["'use client'\n\nimport type { Locale } from 'payload'\n\nimport React, { createContext, useContext, useEffect, useState } from 'react'\n\nimport { findLocaleFromCode } from '../../utilities/findLocaleFromCode.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useSearchParams } from '../SearchParams/index.js'\n\nconst LocaleContext = createContext({} as Locale)\n\nexport const LocaleProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {\n const {\n config: { localization = false },\n } = useConfig()\n\n const { user } = useAuth()\n const defaultLocale =\n localization && localization.defaultLocale ? localization.defaultLocale : 'en'\n\n const { searchParams } = useSearchParams()\n const localeFromParams = searchParams?.locale\n\n const [localeCode, setLocaleCode] = useState<string>(\n (localeFromParams as string) || defaultLocale,\n )\n\n const [locale, setLocale] = useState<Locale | null>(\n localization && findLocaleFromCode(localization, localeCode),\n )\n\n const { getPreference, setPreference } = usePreferences()\n\n const switchLocale = React.useCallback(\n async (newLocale: string) => {\n if (!localization) {\n return\n }\n\n const localeToSet =\n localization.localeCodes.indexOf(newLocale) > -1 ? newLocale : defaultLocale\n\n if (localeToSet !== localeCode) {\n setLocaleCode(localeToSet)\n setLocale(findLocaleFromCode(localization, localeToSet))\n try {\n if (user) {\n await setPreference('locale', localeToSet)\n }\n } catch (error) {\n // swallow error\n }\n }\n },\n [localization, setPreference, user, defaultLocale, localeCode],\n )\n\n useEffect(() => {\n async function setInitialLocale() {\n let localeToSet = defaultLocale\n\n if (typeof localeFromParams === 'string') {\n localeToSet = localeFromParams\n } else if (user) {\n try {\n localeToSet = await getPreference<string>('locale')\n } catch (error) {\n // swallow error\n }\n }\n\n await switchLocale(localeToSet)\n }\n\n void setInitialLocale()\n }, [\n defaultLocale,\n getPreference,\n localization,\n localeFromParams,\n setPreference,\n user,\n switchLocale,\n ])\n\n return <LocaleContext.Provider value={locale}>{children}</LocaleContext.Provider>\n}\n\n/**\n * A hook that returns the current locale object.\n */\nexport const useLocale = (): Locale => useContext(LocaleContext)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,OAAOC,KAAA,IAASC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ;AAEtE,SAASC,kBAAkB,QAAQ;A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+1,16 @@
|
|
|
1
|
+
import type { I18n } from '@payloadcms/translations';
|
|
2
|
+
import type { ClientConfig, ClientFieldSchemaMap, FieldSchemaMap, Payload } from 'payload';
|
|
3
|
+
/**
|
|
4
|
+
* Flattens the config fields into a map of field schemas
|
|
5
|
+
*/
|
|
6
|
+
export declare const buildClientFieldSchemaMap: (args: {
|
|
7
|
+
collectionSlug?: string;
|
|
8
|
+
config: ClientConfig;
|
|
9
|
+
globalSlug?: string;
|
|
10
|
+
i18n: I18n;
|
|
11
|
+
payload: Payload;
|
|
12
|
+
schemaMap: FieldSchemaMap;
|
|
13
|
+
}) => {
|
|
14
|
+
clientFieldSchemaMap: ClientFieldSchemaMap;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildClientFieldSchemaMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EACV,YAAY,EAEZ,oBAAoB,EACpB,cAAc,EACd,OAAO,EACR,MAAM,SAAS,CAAA;AAGhB;;GAEG;AACH,eAAO,MAAM,yBAAyB,SAAU;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,YAAY,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,cAAc,CAAA;CAC1B,KAAG;IAAE,oBAAoB,EAAE,oBAAoB,CAAA;CAuE/C,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { traverseFields } from './traverseFields.js';
|
|
2
|
+
/**
|
|
3
|
+
* Flattens the config fields into a map of field schemas
|
|
4
|
+
*/
|
|
5
|
+
export const buildClientFieldSchemaMap = args => {
|
|
6
|
+
console.log('Creating client schemaMap');
|
|
7
|
+
const {
|
|
8
|
+
collectionSlug,
|
|
9
|
+
config,
|
|
10
|
+
globalSlug,
|
|
11
|
+
i18n,
|
|
12
|
+
payload,
|
|
13
|
+
schemaMap
|
|
14
|
+
} = args;
|
|
15
|
+
const clientSchemaMap = new Map();
|
|
16
|
+
if (collectionSlug) {
|
|
17
|
+
const matchedCollection = config.collections.find(collection => collection.slug === collectionSlug);
|
|
18
|
+
if (matchedCollection) {
|
|
19
|
+
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
|
|
20
|
+
// register schema with auth schemaPath
|
|
21
|
+
const baseAuthFields = [{
|
|
22
|
+
name: 'password',
|
|
23
|
+
type: 'text',
|
|
24
|
+
label: i18n.t('general:password'),
|
|
25
|
+
required: true
|
|
26
|
+
}, {
|
|
27
|
+
name: 'confirm-password',
|
|
28
|
+
type: 'text',
|
|
29
|
+
label: i18n.t('authentication:confirmPassword'),
|
|
30
|
+
required: true
|
|
31
|
+
}];
|
|
32
|
+
clientSchemaMap.set(`_${matchedCollection.slug}.auth`, {
|
|
33
|
+
fields: [...baseAuthFields, ...matchedCollection.fields]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
clientSchemaMap.set(collectionSlug, {
|
|
37
|
+
fields: matchedCollection.fields
|
|
38
|
+
});
|
|
39
|
+
traverseFields({
|
|
40
|
+
clientSchemaMap,
|
|
41
|
+
config,
|
|
42
|
+
fields: matchedCollection.fields,
|
|
43
|
+
i18n,
|
|
44
|
+
parentIndexPath: '',
|
|
45
|
+
parentSchemaPath: collectionSlug,
|
|
46
|
+
payload,
|
|
47
|
+
schemaMap
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
} else if (globalSlug) {
|
|
51
|
+
const matchedGlobal = config.globals.find(global => global.slug === globalSlug);
|
|
52
|
+
if (matchedGlobal) {
|
|
53
|
+
clientSchemaMap.set(globalSlug, {
|
|
54
|
+
fields: matchedGlobal.fields
|
|
55
|
+
});
|
|
56
|
+
traverseFields({
|
|
57
|
+
clientSchemaMap,
|
|
58
|
+
config,
|
|
59
|
+
fields: matchedGlobal.fields,
|
|
60
|
+
i18n,
|
|
61
|
+
parentIndexPath: '',
|
|
62
|
+
parentSchemaPath: globalSlug,
|
|
63
|
+
payload,
|
|
64
|
+
schemaMap
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
clientFieldSchemaMap: clientSchemaMap
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["traverseFields","buildClientFieldSchemaMap","args","console","log","collectionSlug","config","globalSlug","i18n","payload","schemaMap","clientSchemaMap","Map","matchedCollection","collections","find","collection","slug","auth","disableLocalStrategy","baseAuthFields","name","type","label","t","required","set","fields","parentIndexPath","parentSchemaPath","matchedGlobal","globals","global","clientFieldSchemaMap"],"sources":["../../../src/utilities/buildClientFieldSchemaMap/index.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type {\n ClientConfig,\n ClientField,\n ClientFieldSchemaMap,\n FieldSchemaMap,\n Payload,\n} from 'payload'\n\nimport { traverseFields } from './traverseFields.js'\n/**\n * Flattens the config fields into a map of field schemas\n */\nexport const buildClientFieldSchemaMap = (args: {\n collectionSlug?: string\n config: ClientConfig\n globalSlug?: string\n i18n: I18n\n payload: Payload\n schemaMap: FieldSchemaMap\n}): { clientFieldSchemaMap: ClientFieldSchemaMap } => {\n console.log('Creating client schemaMap')\n const { collectionSlug, config, globalSlug, i18n, payload, schemaMap } = args\n\n const clientSchemaMap: ClientFieldSchemaMap = new Map()\n\n if (collectionSlug) {\n const matchedCollection = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n if (matchedCollection) {\n if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {\n // register schema with auth schemaPath\n const baseAuthFields: ClientField[] = [\n {\n name: 'password',\n type: 'text',\n label: i18n.t('general:password'),\n required: true,\n },\n {\n name: 'confirm-password',\n type: 'text',\n label: i18n.t('authentication:confirmPassword'),\n required: true,\n },\n ]\n\n clientSchemaMap.set(`_${matchedCollection.slug}.auth`, {\n fields: [...baseAuthFields, ...matchedCollection.fields],\n })\n }\n\n clientSchemaMap.set(collectionSlug, {\n fields: matchedCollection.fields,\n })\n\n traverseFields({\n clientSchemaMap,\n config,\n fields: matchedCollection.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: collectionSlug,\n payload,\n schemaMap,\n })\n }\n } else if (globalSlug) {\n const matchedGlobal = config.globals.find((global) => global.slug === globalSlug)\n\n if (matchedGlobal) {\n clientSchemaMap.set(globalSlug, {\n fields: matchedGlobal.fields,\n })\n\n traverseFields({\n clientSchemaMap,\n config,\n fields: matchedGlobal.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: globalSlug,\n payload,\n schemaMap,\n })\n }\n }\n\n return { clientFieldSchemaMap: clientSchemaMap }\n}\n"],"mappings":"AASA,SAASA,cAAc,QAAQ;AAC/B;;;AAGA,OAAO,MAAMC,yBAAA,GAA6BC,IAAA;EAQxCC,OAAA,CAAQC,GAAG,CAAC;EACZ,MAAM;IAAEC,cAAc;IAAEC,MAAM;IAAEC,UAAU;IAAEC,IAAI;IAAEC,OAAO;IAAEC;EAAS,CAAE,GAAGR,IAAA;EAEzE,MAAMS,eAAA,GAAwC,IAAIC,GAAA;EAElD,IAAIP,cAAA,EAAgB;IAClB,MAAMQ,iBAAA,GAAoBP,MAAA,CAAOQ,WAAW,CAACC,IAAI,CAC9CC,UAAA,IAAeA,UAAA,CAAWC,IAAI,KAAKZ,cAAA;IAGtC,IAAIQ,iBAAA,EAAmB;MACrB,IAAIA,iBAAA,CAAkBK,IAAI,IAAI,CAACL,iBAAA,CAAkBK,IAAI,CAACC,oBAAoB,EAAE;QAC1E;QACA,MAAMC,cAAA,GAAgC,CACpC;UACEC,IAAA,EAAM;UACNC,IAAA,EAAM;UACNC,KAAA,EAAOf,IAAA,CAAKgB,CAAC,CAAC;UACdC,QAAA,EAAU;QACZ,GACA;UACEJ,IAAA,EAAM;UACNC,IAAA,EAAM;UACNC,KAAA,EAAOf,IAAA,CAAKgB,CAAC,CAAC;UACdC,QAAA,EAAU;QACZ,EACD;QAEDd,eAAA,CAAgBe,GAAG,CAAC,IAAIb,iBAAA,CAAkBI,IAAI,OAAO,EAAE;UACrDU,MAAA,EAAQ,C,GAAIP,cAAA,E,GAAmBP,iBAAA,CAAkBc,MAAM;QACzD;MACF;MAEAhB,eAAA,CAAgBe,GAAG,CAACrB,cAAA,EAAgB;QAClCsB,MAAA,EAAQd,iBAAA,CAAkBc;MAC5B;MAEA3B,cAAA,CAAe;QACbW,eAAA;QACAL,MAAA;QACAqB,MAAA,EAAQd,iBAAA,CAAkBc,MAAM;QAChCnB,IAAA;QACAoB,eAAA,EAAiB;QACjBC,gBAAA,EAAkBxB,cAAA;QAClBI,OAAA;QACAC;MACF;IACF;EACF,OAAO,IAAIH,UAAA,EAAY;IACrB,MAAMuB,aAAA,GAAgBxB,MAAA,CAAOyB,OAAO,CAAChB,IAAI,CAAEiB,MAAA,IAAWA,MAAA,CAAOf,IAAI,KAAKV,UAAA;IAEtE,IAAIuB,aAAA,EAAe;MACjBnB,eAAA,CAAgBe,GAAG,CAACnB,UAAA,EAAY;QAC9BoB,MAAA,EAAQG,aAAA,CAAcH;MACxB;MAEA3B,cAAA,CAAe;QACbW,eAAA;QACAL,MAAA;QACAqB,MAAA,EAAQG,aAAA,CAAcH,MAAM;QAC5BnB,IAAA;QACAoB,eAAA,EAAiB;QACjBC,gBAAA,EAAkBtB,UAAA;QAClBE,OAAA;QACAC;MACF;IACF;EACF;EAEA,OAAO;IAAEuB,oBAAA,EAAsBtB;EAAgB;AACjD","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { I18n } from '@payloadcms/translations';
|
|
2
|
+
import { type ClientConfig, type ClientField, type ClientFieldSchemaMap, type FieldSchemaMap, type Payload } from 'payload';
|
|
3
|
+
type Args = {
|
|
4
|
+
clientSchemaMap: ClientFieldSchemaMap;
|
|
5
|
+
config: ClientConfig;
|
|
6
|
+
fields: ClientField[];
|
|
7
|
+
i18n: I18n<any, any>;
|
|
8
|
+
parentIndexPath: string;
|
|
9
|
+
parentSchemaPath: string;
|
|
10
|
+
payload: Payload;
|
|
11
|
+
schemaMap: FieldSchemaMap;
|
|
12
|
+
};
|
|
13
|
+
export declare const traverseFields: ({ clientSchemaMap, config, fields, i18n, parentIndexPath, parentSchemaPath, payload, schemaMap, }: Args) => void;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=traverseFields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildClientFieldSchemaMap/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EAEzB,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,SAAS,CAAA;AAGhB,KAAK,IAAI,GAAG;IACV,eAAe,EAAE,oBAAoB,CAAA;IACrC,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,sGASxB,IAAI,SAyHN,CAAA"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createClientFields } from 'payload';
|
|
2
|
+
import { getFieldPaths, tabHasName } from 'payload/shared';
|
|
3
|
+
export const traverseFields = ({
|
|
4
|
+
clientSchemaMap,
|
|
5
|
+
config,
|
|
6
|
+
fields,
|
|
7
|
+
i18n,
|
|
8
|
+
parentIndexPath,
|
|
9
|
+
parentSchemaPath,
|
|
10
|
+
payload,
|
|
11
|
+
schemaMap
|
|
12
|
+
}) => {
|
|
13
|
+
for (const [index, field] of fields.entries()) {
|
|
14
|
+
const {
|
|
15
|
+
indexPath,
|
|
16
|
+
schemaPath
|
|
17
|
+
} = getFieldPaths({
|
|
18
|
+
field,
|
|
19
|
+
index,
|
|
20
|
+
parentIndexPath: 'name' in field ? '' : parentIndexPath,
|
|
21
|
+
parentPath: '',
|
|
22
|
+
parentSchemaPath
|
|
23
|
+
});
|
|
24
|
+
clientSchemaMap.set(schemaPath, field);
|
|
25
|
+
switch (field.type) {
|
|
26
|
+
case 'array':
|
|
27
|
+
case 'group':
|
|
28
|
+
traverseFields({
|
|
29
|
+
clientSchemaMap,
|
|
30
|
+
config,
|
|
31
|
+
fields: field.fields,
|
|
32
|
+
i18n,
|
|
33
|
+
parentIndexPath: '',
|
|
34
|
+
parentSchemaPath: schemaPath,
|
|
35
|
+
payload,
|
|
36
|
+
schemaMap
|
|
37
|
+
});
|
|
38
|
+
break;
|
|
39
|
+
case 'blocks':
|
|
40
|
+
field.blocks.map(block => {
|
|
41
|
+
const blockSchemaPath = `${schemaPath}.${block.slug}`;
|
|
42
|
+
clientSchemaMap.set(blockSchemaPath, block);
|
|
43
|
+
traverseFields({
|
|
44
|
+
clientSchemaMap,
|
|
45
|
+
config,
|
|
46
|
+
fields: block.fields,
|
|
47
|
+
i18n,
|
|
48
|
+
parentIndexPath: '',
|
|
49
|
+
parentSchemaPath: blockSchemaPath,
|
|
50
|
+
payload,
|
|
51
|
+
schemaMap
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
case 'collapsible':
|
|
56
|
+
case 'row':
|
|
57
|
+
traverseFields({
|
|
58
|
+
clientSchemaMap,
|
|
59
|
+
config,
|
|
60
|
+
fields: field.fields,
|
|
61
|
+
i18n,
|
|
62
|
+
parentIndexPath: indexPath,
|
|
63
|
+
parentSchemaPath,
|
|
64
|
+
payload,
|
|
65
|
+
schemaMap
|
|
66
|
+
});
|
|
67
|
+
break;
|
|
68
|
+
case 'richText':
|
|
69
|
+
{
|
|
70
|
+
// richText sub-fields are not part of the ClientConfig or the Config.
|
|
71
|
+
// They only exist in the field schema map.
|
|
72
|
+
// Thus, we need to
|
|
73
|
+
// 1. get them from the field schema map
|
|
74
|
+
// 2. convert them to client fields
|
|
75
|
+
// 3. add them to the client schema map
|
|
76
|
+
// So these would basically be all fields that are not part of the client config already
|
|
77
|
+
const richTextFieldSchemaMap = new Map();
|
|
78
|
+
for (const [path, subField] of schemaMap.entries()) {
|
|
79
|
+
if (path.startsWith(`${schemaPath}.`)) {
|
|
80
|
+
richTextFieldSchemaMap.set(path, subField);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Now loop through them, convert each entry to a client field and add it to the client schema map
|
|
84
|
+
for (const [path, subField] of richTextFieldSchemaMap.entries()) {
|
|
85
|
+
const clientFields = createClientFields({
|
|
86
|
+
defaultIDType: payload.config.db.defaultIDType,
|
|
87
|
+
disableAddingID: true,
|
|
88
|
+
fields: 'fields' in subField ? subField.fields : [subField],
|
|
89
|
+
i18n,
|
|
90
|
+
importMap: payload.importMap
|
|
91
|
+
});
|
|
92
|
+
clientSchemaMap.set(path, {
|
|
93
|
+
fields: clientFields
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'tabs':
|
|
99
|
+
field.tabs.map((tab, tabIndex) => {
|
|
100
|
+
const {
|
|
101
|
+
indexPath: tabIndexPath,
|
|
102
|
+
schemaPath: tabSchemaPath
|
|
103
|
+
} = getFieldPaths({
|
|
104
|
+
field: {
|
|
105
|
+
...tab,
|
|
106
|
+
type: 'tab'
|
|
107
|
+
},
|
|
108
|
+
index: tabIndex,
|
|
109
|
+
parentIndexPath: indexPath,
|
|
110
|
+
parentPath: '',
|
|
111
|
+
parentSchemaPath
|
|
112
|
+
});
|
|
113
|
+
clientSchemaMap.set(tabSchemaPath, tab);
|
|
114
|
+
traverseFields({
|
|
115
|
+
clientSchemaMap,
|
|
116
|
+
config,
|
|
117
|
+
fields: tab.fields,
|
|
118
|
+
i18n,
|
|
119
|
+
parentIndexPath: tabHasName(tab) ? '' : tabIndexPath,
|
|
120
|
+
parentSchemaPath: tabHasName(tab) ? tabSchemaPath : parentSchemaPath,
|
|
121
|
+
payload,
|
|
122
|
+
schemaMap
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=traverseFields.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverseFields.js","names":["createClientFields","getFieldPaths","tabHasName","traverseFields","clientSchemaMap","config","fields","i18n","parentIndexPath","parentSchemaPath","payload","schemaMap","index","field","entries","indexPath","schemaPath","parentPath","set","type","blocks","map","block","blockSchemaPath","slug","richTextFieldSchemaMap","Map","path","subField","startsWith","clientFields","defaultIDType","db","disableAddingID","importMap","tabs","tab","tabIndex","tabIndexPath","tabSchemaPath"],"sources":["../../../src/utilities/buildClientFieldSchemaMap/traverseFields.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\n\nimport {\n type ClientConfig,\n type ClientField,\n type ClientFieldSchemaMap,\n createClientFields,\n type FieldSchemaMap,\n type Payload,\n} from 'payload'\nimport { getFieldPaths, tabHasName } from 'payload/shared'\n\ntype Args = {\n clientSchemaMap: ClientFieldSchemaMap\n config: ClientConfig\n fields: ClientField[]\n i18n: I18n<any, any>\n parentIndexPath: string\n parentSchemaPath: string\n payload: Payload\n schemaMap: FieldSchemaMap\n}\n\nexport const traverseFields = ({\n clientSchemaMap,\n config,\n fields,\n i18n,\n parentIndexPath,\n parentSchemaPath,\n payload,\n schemaMap,\n}: Args) => {\n for (const [index, field] of fields.entries()) {\n const { indexPath, schemaPath } = getFieldPaths({\n field,\n index,\n parentIndexPath: 'name' in field ? '' : parentIndexPath,\n parentPath: '',\n parentSchemaPath,\n })\n\n clientSchemaMap.set(schemaPath, field)\n\n switch (field.type) {\n case 'array':\n case 'group':\n traverseFields({\n clientSchemaMap,\n config,\n fields: field.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: schemaPath,\n payload,\n schemaMap,\n })\n\n break\n\n case 'blocks':\n field.blocks.map((block) => {\n const blockSchemaPath = `${schemaPath}.${block.slug}`\n\n clientSchemaMap.set(blockSchemaPath, block)\n traverseFields({\n clientSchemaMap,\n config,\n fields: block.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: blockSchemaPath,\n payload,\n schemaMap,\n })\n })\n\n break\n case 'collapsible':\n case 'row':\n traverseFields({\n clientSchemaMap,\n config,\n fields: field.fields,\n i18n,\n parentIndexPath: indexPath,\n parentSchemaPath,\n payload,\n schemaMap,\n })\n break\n\n case 'richText': {\n // richText sub-fields are not part of the ClientConfig or the Config.\n // They only exist in the field schema map.\n // Thus, we need to\n // 1. get them from the field schema map\n // 2. convert them to client fields\n // 3. add them to the client schema map\n\n // So these would basically be all fields that are not part of the client config already\n const richTextFieldSchemaMap: FieldSchemaMap = new Map()\n for (const [path, subField] of schemaMap.entries()) {\n if (path.startsWith(`${schemaPath}.`)) {\n richTextFieldSchemaMap.set(path, subField)\n }\n }\n\n // Now loop through them, convert each entry to a client field and add it to the client schema map\n for (const [path, subField] of richTextFieldSchemaMap.entries()) {\n const clientFields = createClientFields({\n defaultIDType: payload.config.db.defaultIDType,\n disableAddingID: true,\n fields: 'fields' in subField ? subField.fields : [subField],\n i18n,\n importMap: payload.importMap,\n })\n clientSchemaMap.set(path, {\n fields: clientFields,\n })\n }\n break\n }\n case 'tabs':\n field.tabs.map((tab, tabIndex) => {\n const { indexPath: tabIndexPath, schemaPath: tabSchemaPath } = getFieldPaths({\n field: {\n ...tab,\n type: 'tab',\n },\n index: tabIndex,\n parentIndexPath: indexPath,\n parentPath: '',\n parentSchemaPath,\n })\n\n clientSchemaMap.set(tabSchemaPath, tab)\n\n traverseFields({\n clientSchemaMap,\n config,\n fields: tab.fields,\n i18n,\n parentIndexPath: tabHasName(tab) ? '' : tabIndexPath,\n parentSchemaPath: tabHasName(tab) ? tabSchemaPath : parentSchemaPath,\n payload,\n schemaMap,\n })\n })\n\n break\n }\n }\n}\n"],"mappings":"AAEA,SAIEA,kBAAkB,QAGb;AACP,SAASC,aAAa,EAAEC,UAAU,QAAQ;AAa1C,OAAO,MAAMC,cAAA,GAAiBA,CAAC;EAC7BC,eAAe;EACfC,MAAM;EACNC,MAAM;EACNC,IAAI;EACJC,eAAe;EACfC,gBAAgB;EAChBC,OAAO;EACPC;AAAS,CACJ;EACL,KAAK,MAAM,CAACC,KAAA,EAAOC,KAAA,CAAM,IAAIP,MAAA,CAAOQ,OAAO,IAAI;IAC7C,MAAM;MAAEC,SAAS;MAAEC;IAAU,CAAE,GAAGf,aAAA,CAAc;MAC9CY,KAAA;MACAD,KAAA;MACAJ,eAAA,EAAiB,UAAUK,KAAA,GAAQ,KAAKL,eAAA;MACxCS,UAAA,EAAY;MACZR;IACF;IAEAL,eAAA,CAAgBc,GAAG,CAACF,UAAA,EAAYH,KAAA;IAEhC,QAAQA,KAAA,CAAMM,IAAI;MAChB,KAAK;MACL,KAAK;QACHhB,cAAA,CAAe;UACbC,eAAA;UACAC,MAAA;UACAC,MAAA,EAAQO,KAAA,CAAMP,MAAM;UACpBC,IAAA;UACAC,eAAA,EAAiB;UACjBC,gBAAA,EAAkBO,UAAA;UAClBN,OAAA;UACAC;QACF;QAEA;MAEF,KAAK;QACHE,KAAA,CAAMO,MAAM,CAACC,GAAG,CAAEC,KAAA;UAChB,MAAMC,eAAA,GAAkB,GAAGP,UAAA,IAAcM,KAAA,CAAME,IAAI,EAAE;UAErDpB,eAAA,CAAgBc,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C,QAAA;UACnB,MAAM;YAAEtB,SAAA,EAAWuB,YAAY;YAAEtB,UAAA,EAAYuB;UAAa,CAAE,GAAGtC,aAAA,CAAc;YAC3EY,KAAA,EAAO;cACL,GAAGuB,GAAG;cACNjB,IAAA,EAAM;YACR;YACAP,KAAA,EAAOyB,QAAA;YACP7B,eAAA,EAAiBO,SAAA;YACjBE,UAAA,EAAY;YACZR;UACF;UAEAL,eAAA,CAAgBc,GAAG,CAACqB,aAAA,EAAeH,GAAA;UAEnCjC,cAAA,CAAe;YACbC,eAAA;YACAC,MAAA;YACAC,MAAA,EAAQ8B,GAAA,CAAI9B,MAAM;YAClBC,IAAA;YACAC,eAAA,EAAiBN,UAAA,CAAWkC,GAAA,IAAO,KAAKE,YAAA;YACxC7B,gBAAA,EAAkBP,UAAA,CAAWkC,GAAA,IAAOG,aAAA,GAAgB9B,gBAAA;YACpDC,OAAA;YACAC;UACF;QACF;QAEA;IACJ;EACF;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKrE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,4EAOxB,IAAI,
|
|
1
|
+
{"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAKrE,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,cAAc,CAAA;CAC1B,CAAA;AAED,eAAO,MAAM,cAAc,4EAOxB,IAAI,SAwGN,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverseFields.js","names":["MissingEditorProp","getFieldPaths","tabHasName","traverseFields","config","fields","i18n","parentIndexPath","parentSchemaPath","schemaMap","index","field","entries","indexPath","schemaPath","parentPath","set","type","blocks","map","block","blockSchemaPath","slug","editor","Error","generateSchemaMap","tabs","tab","tabIndex","tabIndexPath","tabSchemaPath"],"sources":["../../../src/utilities/buildFieldSchemaMap/traverseFields.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Field, FieldSchemaMap, SanitizedConfig } from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { getFieldPaths, tabHasName } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n i18n: I18n<any, any>\n parentIndexPath: string\n parentSchemaPath: string\n schemaMap: FieldSchemaMap\n}\n\nexport const traverseFields = ({\n config,\n fields,\n i18n,\n parentIndexPath,\n parentSchemaPath,\n schemaMap,\n}: Args) => {\n for (const [index, field] of fields.entries()) {\n const { indexPath, schemaPath } = getFieldPaths({\n field,\n index,\n parentIndexPath: 'name' in field ? '' : parentIndexPath,\n parentPath: '',\n parentSchemaPath,\n })\n\n schemaMap.set(schemaPath, field)\n\n switch (field.type) {\n case 'array':\n case 'group':\n traverseFields({\n config,\n fields: field.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: schemaPath,\n schemaMap,\n })\n\n break\n\n case 'blocks':\n field.blocks.map((block) => {\n const blockSchemaPath = `${schemaPath}.${block.slug}`\n\n schemaMap.set(blockSchemaPath, block)\n traverseFields({\n config,\n fields: block.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: blockSchemaPath,\n schemaMap,\n })\n })\n\n break\n case 'collapsible':\n
|
|
1
|
+
{"version":3,"file":"traverseFields.js","names":["MissingEditorProp","getFieldPaths","tabHasName","traverseFields","config","fields","i18n","parentIndexPath","parentSchemaPath","schemaMap","index","field","entries","indexPath","schemaPath","parentPath","set","type","blocks","map","block","blockSchemaPath","slug","editor","Error","generateSchemaMap","tabs","tab","tabIndex","tabIndexPath","tabSchemaPath"],"sources":["../../../src/utilities/buildFieldSchemaMap/traverseFields.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Field, FieldSchemaMap, SanitizedConfig } from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { getFieldPaths, tabHasName } from 'payload/shared'\n\ntype Args = {\n config: SanitizedConfig\n fields: Field[]\n i18n: I18n<any, any>\n parentIndexPath: string\n parentSchemaPath: string\n schemaMap: FieldSchemaMap\n}\n\nexport const traverseFields = ({\n config,\n fields,\n i18n,\n parentIndexPath,\n parentSchemaPath,\n schemaMap,\n}: Args) => {\n for (const [index, field] of fields.entries()) {\n const { indexPath, schemaPath } = getFieldPaths({\n field,\n index,\n parentIndexPath: 'name' in field ? '' : parentIndexPath,\n parentPath: '',\n parentSchemaPath,\n })\n\n schemaMap.set(schemaPath, field)\n\n switch (field.type) {\n case 'array':\n case 'group':\n traverseFields({\n config,\n fields: field.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: schemaPath,\n schemaMap,\n })\n\n break\n\n case 'blocks':\n field.blocks.map((block) => {\n const blockSchemaPath = `${schemaPath}.${block.slug}`\n\n schemaMap.set(blockSchemaPath, block)\n traverseFields({\n config,\n fields: block.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: blockSchemaPath,\n schemaMap,\n })\n })\n\n break\n case 'collapsible':\n case 'row':\n traverseFields({\n config,\n fields: field.fields,\n i18n,\n parentIndexPath: indexPath,\n parentSchemaPath,\n schemaMap,\n })\n\n break\n\n case 'richText':\n if (!field?.editor) {\n throw new MissingEditorProp(field) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof field.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (typeof field.editor.generateSchemaMap === 'function') {\n field.editor.generateSchemaMap({\n config,\n field,\n i18n,\n schemaMap,\n schemaPath,\n })\n }\n\n break\n\n case 'tabs':\n field.tabs.map((tab, tabIndex) => {\n const { indexPath: tabIndexPath, schemaPath: tabSchemaPath } = getFieldPaths({\n field: {\n ...tab,\n type: 'tab',\n },\n index: tabIndex,\n parentIndexPath: indexPath,\n parentPath: '',\n parentSchemaPath,\n })\n\n schemaMap.set(tabSchemaPath, tab)\n\n traverseFields({\n config,\n fields: tab.fields,\n i18n,\n parentIndexPath: tabHasName(tab) ? '' : tabIndexPath,\n parentSchemaPath: tabHasName(tab) ? tabSchemaPath : parentSchemaPath,\n schemaMap,\n })\n })\n\n break\n }\n }\n}\n"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,aAAa,EAAEC,UAAU,QAAQ;AAW1C,OAAO,MAAMC,cAAA,GAAiBA,CAAC;EAC7BC,MAAM;EACNC,MAAM;EACNC,IAAI;EACJC,eAAe;EACfC,gBAAgB;EAChBC;AAAS,CACJ;EACL,KAAK,MAAM,CAACC,KAAA,EAAOC,KAAA,CAAM,IAAIN,MAAA,CAAOO,OAAO,IAAI;IAC7C,MAAM;MAAEC,SAAS;MAAEC;IAAU,CAAE,GAAGb,aAAA,CAAc;MAC9CU,KAAA;MACAD,KAAA;MACAH,eAAA,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AK;QACHH,KAAA,CAAMe,IAAI,CAACP,GAAG,CAAC,CAACQ,GAAA,EAAKC,QAAA;UACnB,MAAM;YAAEf,SAAA,EAAWgB,YAAY;YAAEf,UAAA,EAAYgB;UAAa,CAAE,GAAG7B,aAAA,CAAc;YAC3EU,KAAA,EAAO;cACL,GAAGgB,GAAG;cACNV,IAAA,EAAM;YACR;YACAP,KAAA,EAAOkB,QAAA;YACPrB,eAAA,EAAiBM,SAAA;YACjBE,UAAA,EAAY;YACZP;UACF;UAEAC,SAAA,CAAUO,GAAG,CAACc,aAAA,EAAeH,GAAA;UAE7BxB,cAAA,CAAe;YACbC,MAAA;YACAC,MAAA,EAAQsB,GAAA,CAAItB,MAAM;YAClBC,IAAA;YACAC,eAAA,EAAiBL,UAAA,CAAWyB,GAAA,IAAO,KAAKE,YAAA;YACxCrB,gBAAA,EAAkBN,UAAA,CAAWyB,GAAA,IAAOG,aAAA,GAAgBtB,gBAAA;YACpDC;UACF;QACF;QAEA;IACJ;EACF;AACF","ignoreList":[]}
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FieldSchemaMap, FormState, SanitizedConfig } from 'payload';
|
|
3
|
-
export declare const getFieldSchemaMap: (args: {
|
|
4
|
-
collectionSlug?: string;
|
|
5
|
-
config: SanitizedConfig;
|
|
6
|
-
globalSlug?: string;
|
|
7
|
-
i18n: I18nClient;
|
|
8
|
-
}) => FieldSchemaMap;
|
|
1
|
+
import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload';
|
|
9
2
|
type BuildFormStateSuccessResult = {
|
|
10
3
|
clientConfig?: ClientConfig;
|
|
11
4
|
errors?: never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildFormState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAYnG,KAAK,2BAA2B,GAAG;IACjC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IAC7F,KAAK,EAAE,SAAS,CAAA;CACjB,CAAA;AAED,KAAK,yBAAyB,GAAG;IAC/B,WAAW,CAAC,EAAE,KAAK,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,yBAAyB,GAAG,2BAA2B,CAAA;AAE1F,eAAO,MAAM,qBAAqB,SAC1B,kBAAkB,KACvB,OAAO,CAAC,oBAAoB,CAqD9B,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,kBAAkB,KACvB,OAAO,CAAC,2BAA2B,CA4HrC,CAAA"}
|
|
@@ -2,45 +2,10 @@ import { formatErrors } from 'payload';
|
|
|
2
2
|
import { reduceFieldsToValues } from 'payload/shared';
|
|
3
3
|
import { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js';
|
|
4
4
|
import { renderField } from '../forms/fieldSchemasToFormState/renderField.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getClientConfig } from './getClientConfig.js';
|
|
6
|
+
import { getClientSchemaMap } from './getClientSchemaMap.js';
|
|
7
|
+
import { getSchemaMap } from './getSchemaMap.js';
|
|
6
8
|
import { handleFormStateLocking } from './handleFormStateLocking.js';
|
|
7
|
-
let cachedFieldMap = global._payload_fieldMap;
|
|
8
|
-
let cachedClientConfig = global._payload_clientConfig;
|
|
9
|
-
if (!cachedFieldMap) {
|
|
10
|
-
cachedFieldMap = global._payload_fieldMap = null;
|
|
11
|
-
}
|
|
12
|
-
if (!cachedClientConfig) {
|
|
13
|
-
cachedClientConfig = global._payload_clientConfig = null;
|
|
14
|
-
}
|
|
15
|
-
export const getFieldSchemaMap = args => {
|
|
16
|
-
const {
|
|
17
|
-
collectionSlug,
|
|
18
|
-
config,
|
|
19
|
-
globalSlug,
|
|
20
|
-
i18n
|
|
21
|
-
} = args;
|
|
22
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
23
|
-
if (!cachedFieldMap) {
|
|
24
|
-
cachedFieldMap = new Map();
|
|
25
|
-
}
|
|
26
|
-
const cachedEntityFieldMap = cachedFieldMap.get(collectionSlug || globalSlug);
|
|
27
|
-
if (cachedEntityFieldMap) {
|
|
28
|
-
return cachedEntityFieldMap;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const {
|
|
32
|
-
fieldSchemaMap: entityFieldMap
|
|
33
|
-
} = buildFieldSchemaMap({
|
|
34
|
-
collectionSlug,
|
|
35
|
-
config,
|
|
36
|
-
globalSlug,
|
|
37
|
-
i18n: i18n
|
|
38
|
-
});
|
|
39
|
-
if (process.env.NODE_ENV !== 'development') {
|
|
40
|
-
cachedFieldMap.set(collectionSlug || globalSlug, entityFieldMap);
|
|
41
|
-
}
|
|
42
|
-
return entityFieldMap;
|
|
43
|
-
};
|
|
44
9
|
export const buildFormStateHandler = async args => {
|
|
45
10
|
const {
|
|
46
11
|
req
|
|
@@ -120,14 +85,26 @@ export const buildFormState = async args => {
|
|
|
120
85
|
if (!collectionSlug && !globalSlug) {
|
|
121
86
|
throw new Error('Either collectionSlug or globalSlug must be provided');
|
|
122
87
|
}
|
|
123
|
-
const
|
|
88
|
+
const schemaMap = getSchemaMap({
|
|
124
89
|
collectionSlug,
|
|
125
90
|
config,
|
|
126
91
|
globalSlug,
|
|
127
92
|
i18n
|
|
128
93
|
});
|
|
94
|
+
const clientSchemaMap = getClientSchemaMap({
|
|
95
|
+
collectionSlug,
|
|
96
|
+
config: getClientConfig({
|
|
97
|
+
config,
|
|
98
|
+
i18n,
|
|
99
|
+
importMap: req.payload.importMap
|
|
100
|
+
}),
|
|
101
|
+
globalSlug,
|
|
102
|
+
i18n,
|
|
103
|
+
payload,
|
|
104
|
+
schemaMap
|
|
105
|
+
});
|
|
129
106
|
const id = collectionSlug ? idFromArgs : undefined;
|
|
130
|
-
const fieldOrEntityConfig =
|
|
107
|
+
const fieldOrEntityConfig = schemaMap.get(schemaPath);
|
|
131
108
|
if (!fieldOrEntityConfig) {
|
|
132
109
|
throw new Error(`Could not find "${schemaPath}" in the fieldSchemaMap`);
|
|
133
110
|
}
|
|
@@ -151,10 +128,11 @@ export const buildFormState = async args => {
|
|
|
151
128
|
const fields = Array.isArray(fieldOrEntityConfig) ? fieldOrEntityConfig : 'fields' in fieldOrEntityConfig ? fieldOrEntityConfig.fields : [fieldOrEntityConfig];
|
|
152
129
|
const formStateResult = await fieldSchemasToFormState({
|
|
153
130
|
id,
|
|
131
|
+
clientFieldSchemaMap: clientSchemaMap,
|
|
154
132
|
collectionSlug,
|
|
155
133
|
data,
|
|
156
134
|
fields,
|
|
157
|
-
fieldSchemaMap,
|
|
135
|
+
fieldSchemaMap: schemaMap,
|
|
158
136
|
operation,
|
|
159
137
|
permissions: docPermissions?.fields || {},
|
|
160
138
|
preferences: docPreferences || {
|