@payloadcms/ui 3.1.1 → 3.1.2-canary.eb1a61e
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/elements/AnimateHeight/index.d.ts +10 -0
- package/dist/elements/AnimateHeight/index.d.ts.map +1 -0
- package/dist/elements/AnimateHeight/index.js +75 -0
- package/dist/elements/AnimateHeight/index.js.map +1 -0
- package/dist/elements/AnimateHeight/index.scss +8 -0
- package/dist/elements/AnimateHeight/usePatchAnimateHeight.d.ts +8 -0
- package/dist/elements/AnimateHeight/usePatchAnimateHeight.d.ts.map +1 -0
- package/dist/elements/AnimateHeight/usePatchAnimateHeight.js +49 -0
- package/dist/elements/AnimateHeight/usePatchAnimateHeight.js.map +1 -0
- package/dist/elements/AppHeader/index.scss +7 -8
- package/dist/elements/BulkUpload/FileSidebar/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FileSidebar/index.js +2 -4
- package/dist/elements/BulkUpload/FileSidebar/index.js.map +1 -1
- package/dist/elements/Collapsible/index.d.ts.map +1 -1
- package/dist/elements/Collapsible/index.js +1 -3
- package/dist/elements/Collapsible/index.js.map +1 -1
- package/dist/elements/ListControls/index.d.ts.map +1 -1
- package/dist/elements/ListControls/index.js +2 -3
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/NavGroup/index.d.ts.map +1 -1
- package/dist/elements/NavGroup/index.js +1 -2
- package/dist/elements/NavGroup/index.js.map +1 -1
- package/dist/elements/RelationshipTable/index.d.ts.map +1 -1
- package/dist/elements/RelationshipTable/index.js +3 -4
- package/dist/elements/RelationshipTable/index.js.map +1 -1
- package/dist/exports/client/index.js +21 -21
- package/dist/exports/client/index.js.map +4 -4
- 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/styles.css +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 +70 -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/index.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/index.js +13 -14
- package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
- 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 -6
|
@@ -0,0 +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,EAER,MAAM,SAAS,CAAA;AAiBhB;;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;CA0D/C,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { traverseFields } from './traverseFields.js';
|
|
2
|
+
const baseAuthFields = [{
|
|
3
|
+
name: 'password',
|
|
4
|
+
type: 'text',
|
|
5
|
+
required: true
|
|
6
|
+
}, {
|
|
7
|
+
name: 'confirm-password',
|
|
8
|
+
type: 'text',
|
|
9
|
+
required: true
|
|
10
|
+
}];
|
|
11
|
+
/**
|
|
12
|
+
* Flattens the config fields into a map of field schemas
|
|
13
|
+
*/
|
|
14
|
+
export const buildClientFieldSchemaMap = args => {
|
|
15
|
+
const {
|
|
16
|
+
collectionSlug,
|
|
17
|
+
config,
|
|
18
|
+
globalSlug,
|
|
19
|
+
i18n,
|
|
20
|
+
payload,
|
|
21
|
+
schemaMap
|
|
22
|
+
} = args;
|
|
23
|
+
const clientSchemaMap = new Map();
|
|
24
|
+
if (collectionSlug) {
|
|
25
|
+
const matchedCollection = config.collections.find(collection => collection.slug === collectionSlug);
|
|
26
|
+
if (matchedCollection) {
|
|
27
|
+
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
|
|
28
|
+
baseAuthFields[0].label = i18n.t('general:password');
|
|
29
|
+
baseAuthFields[1].label = i18n.t('authentication:confirmPassword');
|
|
30
|
+
clientSchemaMap.set(`_${matchedCollection.slug}.auth`, {
|
|
31
|
+
fields: [...baseAuthFields, ...matchedCollection.fields]
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
clientSchemaMap.set(collectionSlug, {
|
|
35
|
+
fields: matchedCollection.fields
|
|
36
|
+
});
|
|
37
|
+
traverseFields({
|
|
38
|
+
clientSchemaMap,
|
|
39
|
+
config,
|
|
40
|
+
fields: matchedCollection.fields,
|
|
41
|
+
i18n,
|
|
42
|
+
parentIndexPath: '',
|
|
43
|
+
parentSchemaPath: collectionSlug,
|
|
44
|
+
payload,
|
|
45
|
+
schemaMap
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
} else if (globalSlug) {
|
|
49
|
+
const matchedGlobal = config.globals.find(global => global.slug === globalSlug);
|
|
50
|
+
if (matchedGlobal) {
|
|
51
|
+
clientSchemaMap.set(globalSlug, {
|
|
52
|
+
fields: matchedGlobal.fields
|
|
53
|
+
});
|
|
54
|
+
traverseFields({
|
|
55
|
+
clientSchemaMap,
|
|
56
|
+
config,
|
|
57
|
+
fields: matchedGlobal.fields,
|
|
58
|
+
i18n,
|
|
59
|
+
parentIndexPath: '',
|
|
60
|
+
parentSchemaPath: globalSlug,
|
|
61
|
+
payload,
|
|
62
|
+
schemaMap
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
clientFieldSchemaMap: clientSchemaMap
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["traverseFields","baseAuthFields","name","type","required","buildClientFieldSchemaMap","args","collectionSlug","config","globalSlug","i18n","payload","schemaMap","clientSchemaMap","Map","matchedCollection","collections","find","collection","slug","auth","disableLocalStrategy","label","t","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 TextFieldClient,\n} from 'payload'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst baseAuthFields: ClientField[] = [\n {\n name: 'password',\n type: 'text',\n required: true,\n },\n {\n name: 'confirm-password',\n type: 'text',\n required: true,\n },\n]\n\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 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 ;(baseAuthFields[0] as TextFieldClient).label = i18n.t('general:password')\n ;(baseAuthFields[1] as TextFieldClient).label = i18n.t('authentication:confirmPassword')\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":"AAUA,SAASA,cAAc,QAAQ;AAE/B,MAAMC,cAAA,GAAgC,CACpC;EACEC,IAAA,EAAM;EACNC,IAAA,EAAM;EACNC,QAAA,EAAU;AACZ,GACA;EACEF,IAAA,EAAM;EACNC,IAAA,EAAM;EACNC,QAAA,EAAU;AACZ,EACD;AAED;;;AAGA,OAAO,MAAMC,yBAAA,GAA6BC,IAAA;EAQxC,MAAM;IAAEC,cAAc;IAAEC,MAAM;IAAEC,UAAU;IAAEC,IAAI;IAAEC,OAAO;IAAEC;EAAS,CAAE,GAAGN,IAAA;EAEzE,MAAMO,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;QAExEpB,cAAc,CAAC,EAAE,CAAqBqB,KAAK,GAAGZ,IAAA,CAAKa,CAAC,CAAC;QACrDtB,cAAc,CAAC,EAAE,CAAqBqB,KAAK,GAAGZ,IAAA,CAAKa,CAAC,CAAC;QAEvDV,eAAA,CAAgBW,GAAG,CAAC,IAAIT,iBAAA,CAAkBI,IAAI,OAAO,EAAE;UACrDM,MAAA,EAAQ,C,GAAIxB,cAAA,E,GAAmBc,iBAAA,CAAkBU,MAAM;QACzD;MACF;MAEAZ,eAAA,CAAgBW,GAAG,CAACjB,cAAA,EAAgB;QAClCkB,MAAA,EAAQV,iBAAA,CAAkBU;MAC5B;MAEAzB,cAAA,CAAe;QACba,eAAA;QACAL,MAAA;QACAiB,MAAA,EAAQV,iBAAA,CAAkBU,MAAM;QAChCf,IAAA;QACAgB,eAAA,EAAiB;QACjBC,gBAAA,EAAkBpB,cAAA;QAClBI,OAAA;QACAC;MACF;IACF;EACF,OAAO,IAAIH,UAAA,EAAY;IACrB,MAAMmB,aAAA,GAAgBpB,MAAA,CAAOqB,OAAO,CAACZ,IAAI,CAAEa,MAAA,IAAWA,MAAA,CAAOX,IAAI,KAAKV,UAAA;IAEtE,IAAImB,aAAA,EAAe;MACjBf,eAAA,CAAgBW,GAAG,CAACf,UAAA,EAAY;QAC9BgB,MAAA,EAAQG,aAAA,CAAcH;MACxB;MAEAzB,cAAA,CAAe;QACba,eAAA;QACAL,MAAA;QACAiB,MAAA,EAAQG,aAAA,CAAcH,MAAM;QAC5Bf,IAAA;QACAgB,eAAA,EAAiB;QACjBC,gBAAA,EAAkBlB,UAAA;QAClBE,OAAA;QACAC;MACF;IACF;EACF;EAEA,OAAO;IAAEmB,oBAAA,EAAsBlB;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,cAA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AC,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":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAS,cAAc,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,KAAK,EAAS,cAAc,EAAE,eAAe,EAAa,MAAM,SAAS,CAAA;AAqBhF;;GAEG;AACH,eAAO,MAAM,mBAAmB,SAAU;IACxC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;CACX,KAAG;IAAE,cAAc,EAAE,cAAc,CAAA;CAsDnC,CAAA"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import { confirmPassword, password } from 'payload/shared';
|
|
2
2
|
import { traverseFields } from './traverseFields.js';
|
|
3
|
+
const baseAuthFields = [{
|
|
4
|
+
name: 'password',
|
|
5
|
+
type: 'text',
|
|
6
|
+
required: true,
|
|
7
|
+
validate: password
|
|
8
|
+
}, {
|
|
9
|
+
name: 'confirm-password',
|
|
10
|
+
type: 'text',
|
|
11
|
+
required: true,
|
|
12
|
+
validate: confirmPassword
|
|
13
|
+
}];
|
|
3
14
|
/**
|
|
4
15
|
* Flattens the config fields into a map of field schemas
|
|
5
16
|
*/
|
|
@@ -15,20 +26,8 @@ export const buildFieldSchemaMap = args => {
|
|
|
15
26
|
const matchedCollection = config.collections.find(collection => collection.slug === collectionSlug);
|
|
16
27
|
if (matchedCollection) {
|
|
17
28
|
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
name: 'password',
|
|
21
|
-
type: 'text',
|
|
22
|
-
label: i18n.t('general:password'),
|
|
23
|
-
required: true,
|
|
24
|
-
validate: password
|
|
25
|
-
}, {
|
|
26
|
-
name: 'confirm-password',
|
|
27
|
-
type: 'text',
|
|
28
|
-
label: i18n.t('authentication:confirmPassword'),
|
|
29
|
-
required: true,
|
|
30
|
-
validate: confirmPassword
|
|
31
|
-
}];
|
|
29
|
+
baseAuthFields[0].label = i18n.t('general:password');
|
|
30
|
+
baseAuthFields[1].label = i18n.t('authentication:confirmPassword');
|
|
32
31
|
schemaMap.set(`_${matchedCollection.slug}.auth`, {
|
|
33
32
|
fields: [...baseAuthFields, ...matchedCollection.fields]
|
|
34
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["confirmPassword","password","traverseFields","buildFieldSchemaMap","args","collectionSlug","config","globalSlug","i18n","schemaMap","Map","matchedCollection","collections","find","collection","slug","auth","disableLocalStrategy","
|
|
1
|
+
{"version":3,"file":"index.js","names":["confirmPassword","password","traverseFields","baseAuthFields","name","type","required","validate","buildFieldSchemaMap","args","collectionSlug","config","globalSlug","i18n","schemaMap","Map","matchedCollection","collections","find","collection","slug","auth","disableLocalStrategy","label","t","set","fields","parentIndexPath","parentSchemaPath","matchedGlobal","globals","global","fieldSchemaMap"],"sources":["../../../src/utilities/buildFieldSchemaMap/index.ts"],"sourcesContent":["import type { I18n } from '@payloadcms/translations'\nimport type { Field, FieldSchemaMap, SanitizedConfig, TextField } from 'payload'\n\nimport { confirmPassword, password } from 'payload/shared'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst baseAuthFields: Field[] = [\n {\n name: 'password',\n type: 'text',\n required: true,\n validate: password,\n },\n {\n name: 'confirm-password',\n type: 'text',\n required: true,\n validate: confirmPassword,\n },\n]\n\n/**\n * Flattens the config fields into a map of field schemas\n */\nexport const buildFieldSchemaMap = (args: {\n collectionSlug?: string\n config: SanitizedConfig\n globalSlug?: string\n i18n: I18n\n}): { fieldSchemaMap: FieldSchemaMap } => {\n const { collectionSlug, config, globalSlug, i18n } = args\n\n const schemaMap: FieldSchemaMap = 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 ;(baseAuthFields[0] as TextField).label = i18n.t('general:password')\n ;(baseAuthFields[1] as TextField).label = i18n.t('authentication:confirmPassword')\n\n schemaMap.set(`_${matchedCollection.slug}.auth`, {\n fields: [...baseAuthFields, ...matchedCollection.fields],\n })\n }\n\n schemaMap.set(collectionSlug, {\n fields: matchedCollection.fields,\n })\n\n traverseFields({\n config,\n fields: matchedCollection.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: collectionSlug,\n schemaMap,\n })\n }\n } else if (globalSlug) {\n const matchedGlobal = config.globals.find((global) => global.slug === globalSlug)\n\n if (matchedGlobal) {\n schemaMap.set(globalSlug, {\n fields: matchedGlobal.fields,\n })\n\n traverseFields({\n config,\n fields: matchedGlobal.fields,\n i18n,\n parentIndexPath: '',\n parentSchemaPath: globalSlug,\n schemaMap,\n })\n }\n }\n\n return { fieldSchemaMap: schemaMap }\n}\n"],"mappings":"AAGA,SAASA,eAAe,EAAEC,QAAQ,QAAQ;AAE1C,SAASC,cAAc,QAAQ;AAE/B,MAAMC,cAAA,GAA0B,CAC9B;EACEC,IAAA,EAAM;EACNC,IAAA,EAAM;EACNC,QAAA,EAAU;EACVC,QAAA,EAAUN;AACZ,GACA;EACEG,IAAA,EAAM;EAC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AAA,CAAUW,GAAG,CAACb,UAAA,EAAY;QACxBc,MAAA,EAAQG,aAAA,CAAcH;MACxB;MAEAxB,cAAA,CAAe;QACbS,MAAA;QACAe,MAAA,EAAQG,aAAA,CAAcH,MAAM;QAC5Bb,IAAA;QACAc,eAAA,EAAiB;QACjBC,gBAAA,EAAkBhB,UAAA;QAClBE;MACF;IACF;EACF;EAEA,OAAO;IAAEkB,cAAA,EAAgBlB;EAAU;AACrC","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,EAAiB,UAAUI,KAAA,GAAQ,KAAKJ,eAAA;MACxCQ,UAAA,EAAY;MACZP;IACF;IAEAC,SAAA,CAAUO,GAAG,CAACF,UAAA,EAAYH,KAAA;IAE1B,QAAQA,KAAA,CAAMM,IAAI;MAChB,KAAK;MACL,KAAK;QACHd,cAAA,CAAe;UACbC,MAAA;UACAC,MAAA,EAAQM,KAAA,CAAMN,MAAM;UACpBC,IAAA;UACAC,eAAA,EAAiB;UACjBC,gBAAA,EAAkBM,UAAA;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F;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 || {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.js","names":["formatErrors","reduceFieldsToValues","fieldSchemasToFormState","renderField","buildFieldSchemaMap","handleFormStateLocking","cachedFieldMap","global","_payload_fieldMap","cachedClientConfig","_payload_clientConfig","getFieldSchemaMap","args","collectionSlug","config","globalSlug","i18n","process","env","NODE_ENV","Map","cachedEntityFieldMap","get","fieldSchemaMap","entityFieldMap","set","buildFormStateHandler","req","incomingUserSlug","user","collection","adminUserSlug","payload","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","docs","length","res","buildFormState","err","logger","error","msg","message","id","idFromArgs","data","incomingData","docPermissions","docPreferences","formState","operation","renderAllFields","returnLockStatus","schemaPath","updateLastEdited","undefined","fieldOrEntityConfig","fields","type","Array","isArray","formStateResult","permissions","preferences","previousFormState","renderFieldFn","upload","file","lockedStateResult","lockedState","state"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type { I18n, I18nClient } from '@payloadcms/translations'\nimport type {\n BuildFormStateArgs,\n ClientConfig,\n ClientUser,\n ErrorResult,\n FieldSchemaMap,\n FormState,\n SanitizedConfig,\n} from 'payload'\n\nimport { formatErrors } from 'payload'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { buildFieldSchemaMap } from './buildFieldSchemaMap/index.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\n\nlet cachedFieldMap = global._payload_fieldMap\nlet cachedClientConfig = global._payload_clientConfig\n\nif (!cachedFieldMap) {\n cachedFieldMap = global._payload_fieldMap = null\n}\n\nif (!cachedClientConfig) {\n cachedClientConfig = global._payload_clientConfig = null\n}\n\nexport const getFieldSchemaMap = (args: {\n collectionSlug?: string\n config: SanitizedConfig\n globalSlug?: string\n i18n: I18nClient\n}): FieldSchemaMap => {\n const { collectionSlug, config, globalSlug, i18n } = args\n\n if (process.env.NODE_ENV !== 'development') {\n if (!cachedFieldMap) {\n cachedFieldMap = new Map()\n }\n const cachedEntityFieldMap = cachedFieldMap.get(collectionSlug || globalSlug)\n if (cachedEntityFieldMap) {\n return cachedEntityFieldMap\n }\n }\n\n const { fieldSchemaMap: entityFieldMap } = buildFieldSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n: i18n as I18n,\n })\n\n if (process.env.NODE_ENV !== 'development') {\n cachedFieldMap.set(collectionSlug || globalSlug, entityFieldMap)\n }\n\n return entityFieldMap\n}\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n lockedState?: { isLocked: boolean; lastEditedAt: string; user: ClientUser | number | string }\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n lockedState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateResult> => {\n const { req } = args\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n try {\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const res = await buildFormState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n formState,\n globalSlug,\n operation,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLockStatus,\n schemaPath = collectionSlug || globalSlug,\n updateLastEdited,\n } = args\n\n let data = incomingData\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const fieldSchemaMap = getFieldSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = fieldSchemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) {\n data = reduceFieldsToValues(formState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n collectionSlug,\n data,\n fields,\n fieldSchemaMap,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n return {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n}\n"],"mappings":"AAWA,SAASA,YAAY,QAAQ;AAC7B,SAASC,oBAAoB,QAAQ;AAErC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AAEvC,IAAIC,cAAA,GAA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Y,MAAA;IACA5C,cAAA;IACAqC,SAAA;IACAY,WAAA,EAAaf,cAAA,EAAgBU,MAAA,IAAU,CAAC;IACxCM,WAAA,EAAaf,cAAA,IAAkB;MAAES,MAAA,EAAQ,CAAC;IAAE;IAC5CO,iBAAA,EAAmBf,SAAA;IACnBE,eAAA;IACAc,aAAA,EAAexE,WAAA;IACfwB,GAAA;IACAoC;EACF;EAEA;EACA,IAAIlD,cAAA,IAAkB8C,SAAA,EAAW;IAC/B,IAAI3B,OAAA,CAAQG,WAAW,CAACtB,cAAA,CAAe,EAAEC,MAAA,EAAQ8D,MAAA,IAAUjB,SAAA,CAAUkB,IAAI,EAAE;MACzEN,eAAA,CAAgBM,IAAI,GAAGlB,SAAA,CAAUkB,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAIhB,gBAAA,EAAkB;IACpBgB,iBAAA,GAAoB,MAAMzE,sBAAA,CAAuB;MAC/CgD,EAAA;MACAxC,cAAA;MACAE,UAAA;MACAY,GAAA;MACAqC;IACF;EACF;EAEA,OAAO;IACLe,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOT;EACT;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"buildFormState.js","names":["formatErrors","reduceFieldsToValues","fieldSchemasToFormState","renderField","getClientConfig","getClientSchemaMap","getSchemaMap","handleFormStateLocking","buildFormStateHandler","args","req","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","docs","length","res","buildFormState","err","logger","error","msg","message","id","idFromArgs","collectionSlug","data","incomingData","docPermissions","docPreferences","formState","globalSlug","operation","renderAllFields","i18n","returnLockStatus","schemaPath","updateLastEdited","schemaMap","clientSchemaMap","importMap","undefined","fieldOrEntityConfig","get","fields","type","Array","isArray","formStateResult","clientFieldSchemaMap","fieldSchemaMap","permissions","preferences","previousFormState","renderFieldFn","upload","file","lockedStateResult","lockedState","state"],"sources":["../../src/utilities/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload'\n\nimport { formatErrors } from 'payload'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nimport { fieldSchemasToFormState } from '../forms/fieldSchemasToFormState/index.js'\nimport { renderField } from '../forms/fieldSchemasToFormState/renderField.js'\nimport { getClientConfig } from './getClientConfig.js'\nimport { getClientSchemaMap } from './getClientSchemaMap.js'\nimport { getSchemaMap } from './getSchemaMap.js'\nimport { handleFormStateLocking } from './handleFormStateLocking.js'\n\ntype BuildFormStateSuccessResult = {\n clientConfig?: ClientConfig\n errors?: never\n indexPath?: string\n lockedState?: { isLocked: boolean; lastEditedAt: string; user: ClientUser | number | string }\n state: FormState\n}\n\ntype BuildFormStateErrorResult = {\n lockedState?: never\n state?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildFormStateResult = BuildFormStateErrorResult | BuildFormStateSuccessResult\n\nexport const buildFormStateHandler = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateResult> => {\n const { req } = args\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n try {\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await req.payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const res = await buildFormState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildFormState = async (\n args: BuildFormStateArgs,\n): Promise<BuildFormStateSuccessResult> => {\n const {\n id: idFromArgs,\n collectionSlug,\n data: incomingData,\n docPermissions,\n docPreferences,\n formState,\n globalSlug,\n operation,\n renderAllFields,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n },\n returnLockStatus,\n schemaPath = collectionSlug || globalSlug,\n updateLastEdited,\n } = args\n\n let data = incomingData\n\n if (!collectionSlug && !globalSlug) {\n throw new Error('Either collectionSlug or globalSlug must be provided')\n }\n\n const schemaMap = getSchemaMap({\n collectionSlug,\n config,\n globalSlug,\n i18n,\n })\n\n const clientSchemaMap = getClientSchemaMap({\n collectionSlug,\n config: getClientConfig({ config, i18n, importMap: req.payload.importMap }),\n globalSlug,\n i18n,\n payload,\n schemaMap,\n })\n\n const id = collectionSlug ? idFromArgs : undefined\n const fieldOrEntityConfig = schemaMap.get(schemaPath)\n\n if (!fieldOrEntityConfig) {\n throw new Error(`Could not find \"${schemaPath}\" in the fieldSchemaMap`)\n }\n\n if (\n (!('fields' in fieldOrEntityConfig) ||\n !fieldOrEntityConfig.fields ||\n !fieldOrEntityConfig.fields.length) &&\n 'type' in fieldOrEntityConfig &&\n fieldOrEntityConfig.type !== 'blocks'\n ) {\n throw new Error(\n `The field found in fieldSchemaMap for \"${schemaPath}\" does not contain any subfields.`,\n )\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) {\n data = reduceFieldsToValues(formState, true)\n }\n\n /**\n * When building state for sub schemas we need to adjust:\n * - `fields`\n * - `parentSchemaPath`\n * - `parentPath`\n *\n * Type assertion is fine because we wrap sub schemas in an array\n * so we can safely map over them within `fieldSchemasToFormState`\n */\n const fields = Array.isArray(fieldOrEntityConfig)\n ? fieldOrEntityConfig\n : 'fields' in fieldOrEntityConfig\n ? fieldOrEntityConfig.fields\n : [fieldOrEntityConfig]\n\n const formStateResult = await fieldSchemasToFormState({\n id,\n clientFieldSchemaMap: clientSchemaMap,\n collectionSlug,\n data,\n fields,\n fieldSchemaMap: schemaMap,\n operation,\n permissions: docPermissions?.fields || {},\n preferences: docPreferences || { fields: {} },\n previousFormState: formState,\n renderAllFields,\n renderFieldFn: renderField,\n req,\n schemaPath,\n })\n\n // Maintain form state of auth / upload fields\n if (collectionSlug && formState) {\n if (payload.collections[collectionSlug]?.config?.upload && formState.file) {\n formStateResult.file = formState.file\n }\n }\n\n let lockedStateResult\n\n if (returnLockStatus) {\n lockedStateResult = await handleFormStateLocking({\n id,\n collectionSlug,\n globalSlug,\n req,\n updateLastEdited,\n })\n }\n\n return {\n lockedState: lockedStateResult,\n state: formStateResult,\n }\n}\n"],"mappings":"AAEA,SAASA,YAAY,QAAQ;AAC7B,SAASC,oBAAoB,QAAQ;AAErC,SAASC,uBAAuB,QAAQ;AACxC,SAASC,WAAW,QAAQ;AAC5B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,YAAY,QAAQ;AAC7B,SAASC,sBAAsB,QAAQ;AAsBvC,OAAO,MAAMC,qBAAA,GAAwB,MACnCC,IAAA;EAEA,MAAM;IAAEC;EAAG,CAAE,GAAGD,IAAA;EAEhB,MAAME,gBAAA,GAAmBD,GAAA,CAAIE,IAAI,EAAEC,UAAA;EACnC,MAAMC,aAAA,GAAgBJ,GAAA,CAAIK,OAAO,CAACC,MAAM,CAACC,KAAK,CAACL,IAAI;EAEnD,IAAI;IACF;IACA,IAAID,gBAAA,EAAkB;MACpB,MAAMO,mBAAA,GAAsBR,GAAA,CAAIK,OAAO,CAACI,WAAW,CAACR,gBAAA,CAAiB,CAACK,MAAM,CAACI,MAAM,EAAEH,KAAA;MAErF;MACA,IAAIC,mBAAA,EAAqB;QACvB,MAAMG,cAAA,GAAiB,MAAMH,mBAAA,CAAoB;UAAER;QAAI;QAEvD,IAAI,CAACW,cAAA,EAAgB;UAC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AA;IACAkB,MAAA;IACAM,cAAA,EAAgBZ,SAAA;IAChBN,SAAA;IACAmB,WAAA,EAAavB,cAAA,EAAgBgB,MAAA,IAAU,CAAC;IACxCQ,WAAA,EAAavB,cAAA,IAAkB;MAAEe,MAAA,EAAQ,CAAC;IAAE;IAC5CS,iBAAA,EAAmBvB,SAAA;IACnBG,eAAA;IACAqB,aAAA,EAAejE,WAAA;IACfO,GAAA;IACAwC;EACF;EAEA;EACA,IAAIX,cAAA,IAAkBK,SAAA,EAAW;IAC/B,IAAI7B,OAAA,CAAQI,WAAW,CAACoB,cAAA,CAAe,EAAEvB,MAAA,EAAQqD,MAAA,IAAUzB,SAAA,CAAU0B,IAAI,EAAE;MACzER,eAAA,CAAgBQ,IAAI,GAAG1B,SAAA,CAAU0B,IAAI;IACvC;EACF;EAEA,IAAIC,iBAAA;EAEJ,IAAItB,gBAAA,EAAkB;IACpBsB,iBAAA,GAAoB,MAAMhE,sBAAA,CAAuB;MAC/C8B,EAAA;MACAE,cAAA;MACAM,UAAA;MACAnC,GAAA;MACAyC;IACF;EACF;EAEA,OAAO;IACLqB,WAAA,EAAaD,iBAAA;IACbE,KAAA,EAAOX;EACT;AACF","ignoreList":[]}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BuildTableStateArgs, ClientConfig, ErrorResult, ImportMap, PaginatedDocs, SanitizedConfig } from 'payload';
|
|
1
|
+
import type { BuildTableStateArgs, ClientConfig, ErrorResult, PaginatedDocs } from 'payload';
|
|
3
2
|
import type { Column } from '../elements/Table/index.js';
|
|
4
3
|
import type { ListPreferences } from '../elements/TableColumns/index.js';
|
|
5
|
-
export declare const getClientConfig: (args: {
|
|
6
|
-
config: SanitizedConfig;
|
|
7
|
-
i18n: I18nClient;
|
|
8
|
-
importMap: ImportMap;
|
|
9
|
-
}) => ClientConfig;
|
|
10
4
|
type BuildTableStateSuccessResult = {
|
|
11
5
|
clientConfig?: ClientConfig;
|
|
12
6
|
data: PaginatedDocs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTableState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildTableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"buildTableState.d.ts","sourceRoot":"","sources":["../../src/utilities/buildTableState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,YAAY,EACZ,WAAW,EACX,aAAa,EAEd,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAKxE,KAAK,4BAA4B,GAAG;IAClC,YAAY,CAAC,EAAE,YAAY,CAAA;IAC3B,IAAI,EAAE,aAAa,CAAA;IACnB,MAAM,CAAC,EAAE,KAAK,CAAA;IACd,WAAW,EAAE,eAAe,CAAA;IAC5B,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;IAC7C,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,EAAE,KAAK,CAAC,SAAS,CAAA;CACvB,CAAA;AAED,KAAK,0BAA0B,GAAG;IAChC,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,eAAe,CAAC,EAAE,KAAK,CAAA;IACvB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,GAAG,CACA;IACE,OAAO,EAAE,MAAM,CAAA;CAChB,GACD,WAAW,CACd,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,0BAA0B,GAAG,4BAA4B,CAAA;AAE7F,eAAO,MAAM,sBAAsB,SAC3B,mBAAmB,KACxB,OAAO,CAAC,qBAAqB,CAqB/B,CAAA;AAED,eAAO,MAAM,eAAe,SACpB,mBAAmB,KACxB,OAAO,CAAC,4BAA4B,CA6KtC,CAAA"}
|
|
@@ -1,26 +1,7 @@
|
|
|
1
1
|
import { dequal } from 'dequal/lite';
|
|
2
|
-
import {
|
|
2
|
+
import { formatErrors } from 'payload';
|
|
3
|
+
import { getClientConfig } from './getClientConfig.js';
|
|
3
4
|
import { renderFilters, renderTable } from './renderTable.js';
|
|
4
|
-
let cachedClientConfig = global._payload_clientConfig;
|
|
5
|
-
if (!cachedClientConfig) {
|
|
6
|
-
cachedClientConfig = global._payload_clientConfig = null;
|
|
7
|
-
}
|
|
8
|
-
export const getClientConfig = args => {
|
|
9
|
-
const {
|
|
10
|
-
config,
|
|
11
|
-
i18n,
|
|
12
|
-
importMap
|
|
13
|
-
} = args;
|
|
14
|
-
if (cachedClientConfig && process.env.NODE_ENV !== 'development') {
|
|
15
|
-
return cachedClientConfig;
|
|
16
|
-
}
|
|
17
|
-
cachedClientConfig = createClientConfig({
|
|
18
|
-
config,
|
|
19
|
-
i18n,
|
|
20
|
-
importMap
|
|
21
|
-
});
|
|
22
|
-
return cachedClientConfig;
|
|
23
|
-
};
|
|
24
5
|
export const buildTableStateHandler = async args => {
|
|
25
6
|
const {
|
|
26
7
|
req
|