@payloadcms/ui 3.1.1-canary.9da0158 → 3.1.1

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.
Files changed (75) hide show
  1. package/dist/elements/DatePicker/DatePicker.d.ts.map +1 -1
  2. package/dist/elements/DatePicker/DatePicker.js +44 -27
  3. package/dist/elements/DatePicker/DatePicker.js.map +1 -1
  4. package/dist/elements/DatePicker/index.scss +1 -1
  5. package/dist/elements/ReactSelect/index.d.ts.map +1 -1
  6. package/dist/elements/ReactSelect/index.js +11 -0
  7. package/dist/elements/ReactSelect/index.js.map +1 -1
  8. package/dist/elements/ReactSelect/index.scss +0 -3
  9. package/dist/exports/client/{DatePicker-23XPGPYP.js → DatePicker-QST7QHAX.js} +2 -2
  10. package/dist/exports/client/{chunk-PELL3UMP.js → chunk-5LUHGAPX.js} +3 -3
  11. package/dist/exports/client/{chunk-PELL3UMP.js.map → chunk-5LUHGAPX.js.map} +3 -3
  12. package/dist/exports/client/index.js +9 -9
  13. package/dist/exports/client/index.js.map +3 -3
  14. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +1 -2
  15. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
  16. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +0 -10
  17. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
  18. package/dist/forms/fieldSchemasToFormState/index.d.ts +1 -7
  19. package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
  20. package/dist/forms/fieldSchemasToFormState/index.js +0 -5
  21. package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
  22. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +2 -3
  23. package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
  24. package/dist/forms/fieldSchemasToFormState/iterateFields.js +0 -2
  25. package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
  26. package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
  27. package/dist/forms/fieldSchemasToFormState/renderField.js +3 -4
  28. package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
  29. package/dist/forms/fieldSchemasToFormState/types.d.ts +1 -2
  30. package/dist/forms/fieldSchemasToFormState/types.d.ts.map +1 -1
  31. package/dist/forms/fieldSchemasToFormState/types.js.map +1 -1
  32. package/dist/providers/ListQuery/index.d.ts.map +1 -1
  33. package/dist/providers/ListQuery/index.js +1 -1
  34. package/dist/providers/ListQuery/index.js.map +1 -1
  35. package/dist/providers/Locale/index.js +29 -30
  36. package/dist/providers/Locale/index.js.map +1 -1
  37. package/dist/styles.css +1 -1
  38. package/dist/utilities/buildFieldSchemaMap/index.d.ts.map +1 -1
  39. package/dist/utilities/buildFieldSchemaMap/index.js +14 -13
  40. package/dist/utilities/buildFieldSchemaMap/index.js.map +1 -1
  41. package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
  42. package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
  43. package/dist/utilities/buildFormState.d.ts +8 -1
  44. package/dist/utilities/buildFormState.d.ts.map +1 -1
  45. package/dist/utilities/buildFormState.js +41 -19
  46. package/dist/utilities/buildFormState.js.map +1 -1
  47. package/dist/utilities/buildTableState.d.ts +7 -1
  48. package/dist/utilities/buildTableState.d.ts.map +1 -1
  49. package/dist/utilities/buildTableState.js +26 -8
  50. package/dist/utilities/buildTableState.js.map +1 -1
  51. package/dist/views/Edit/Auth/types.d.ts +2 -2
  52. package/dist/views/Edit/Auth/types.d.ts.map +1 -1
  53. package/dist/views/Edit/Auth/types.js.map +1 -1
  54. package/package.json +5 -5
  55. package/dist/utilities/buildClientFieldSchemaMap/index.d.ts +0 -16
  56. package/dist/utilities/buildClientFieldSchemaMap/index.d.ts.map +0 -1
  57. package/dist/utilities/buildClientFieldSchemaMap/index.js +0 -70
  58. package/dist/utilities/buildClientFieldSchemaMap/index.js.map +0 -1
  59. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts +0 -15
  60. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts.map +0 -1
  61. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js +0 -129
  62. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js.map +0 -1
  63. package/dist/utilities/getClientConfig.d.ts +0 -8
  64. package/dist/utilities/getClientConfig.d.ts.map +0 -1
  65. package/dist/utilities/getClientConfig.js +0 -25
  66. package/dist/utilities/getClientConfig.js.map +0 -1
  67. package/dist/utilities/getClientSchemaMap.d.ts +0 -11
  68. package/dist/utilities/getClientSchemaMap.d.ts.map +0 -1
  69. package/dist/utilities/getClientSchemaMap.js +0 -39
  70. package/dist/utilities/getClientSchemaMap.js.map +0 -1
  71. package/dist/utilities/getSchemaMap.d.ts +0 -9
  72. package/dist/utilities/getSchemaMap.d.ts.map +0 -1
  73. package/dist/utilities/getSchemaMap.js +0 -35
  74. package/dist/utilities/getSchemaMap.js.map +0 -1
  75. /package/dist/exports/client/{DatePicker-23XPGPYP.js.map → DatePicker-QST7QHAX.js.map} +0 -0
@@ -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,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
+ {"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,EAAE,MAAM,SAAS,CAAA;AAKrE;;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;CAoEnC,CAAA"}
@@ -1,16 +1,5 @@
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
- }];
14
3
  /**
15
4
  * Flattens the config fields into a map of field schemas
16
5
  */
@@ -26,8 +15,20 @@ export const buildFieldSchemaMap = args => {
26
15
  const matchedCollection = config.collections.find(collection => collection.slug === collectionSlug);
27
16
  if (matchedCollection) {
28
17
  if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
29
- baseAuthFields[0].label = i18n.t('general:password');
30
- baseAuthFields[1].label = i18n.t('authentication:confirmPassword');
18
+ // register schema with auth schemaPath
19
+ const baseAuthFields = [{
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
+ }];
31
32
  schemaMap.set(`_${matchedCollection.slug}.auth`, {
32
33
  fields: [...baseAuthFields, ...matchedCollection.fields]
33
34
  });
@@ -1 +1 @@
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: matchedGl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e;QACbS,MAAA;QACAe,MAAA,EAAQV,iBAAA,CAAkBU,MAAM;QAChCb,IAAA;QACAc,eAAA,EAAiB;QACjBC,gBAAA,EAAkBlB,cAAA;QAClBI;MACF;IACF;EACF,OAAO,IAAIF,UAAA,EAAY;IACrB,MAAMiB,aAAA,GAAgBlB,MAAA,CAAOmB,OAAO,CAACZ,IAAI,CAAEa,MAAA,IAAWA,MAAA,CAAOX,IAAI,KAAKR,UAAA;IAEtE,IAAIiB,aAAA,EAAe;MACjBf,SAAA,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
+ {"version":3,"file":"index.js","names":["confirmPassword","password","traverseFields","buildFieldSchemaMap","args","collectionSlug","config","globalSlug","i18n","schemaMap","Map","matchedCollection","collections","find","collection","slug","auth","disableLocalStrategy","baseAuthFields","name","type","label","t","required","validate","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 } from 'payload'\n\nimport { confirmPassword, password } from 'payload/shared'\n\nimport { traverseFields } from './traverseFields.js'\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 const baseAuthFields: Field[] = [\n {\n name: 'password',\n type: 'text',\n label: i18n.t('general:password'),\n required: true,\n validate: password,\n },\n {\n name: 'confirm-password',\n type: 'text',\n label: i18n.t('authentication:confirmPassword'),\n required: true,\n validate: confirmPassword,\n },\n ]\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;AAC/B;;;AAGA,OAAO,MAAMC,mBAAA,GAAuBC,IAAA;EAMlC,MAAM;IAAEC,cAAc;IAAEC,MAAM;IAAEC,UAAU;IAAEC;EAAI,CAAE,GAAGJ,IAAA;EAErD,MAAMK,SAAA,GAA4B,IAAIC,GAAA;EAEtC,IAAIL,cAAA,EAAgB;IAClB,MAAMM,iBAAA,GAAoBL,MAAA,CAAOM,WAAW,CAACC,IAAI,CAC9CC,UAAA,IAAeA,UAAA,CAAWC,IAAI,KAAKV,cAAA;IAGtC,IAAIM,iBAAA,EAAmB;MACrB,IAAIA,iBAAA,CAAkBK,IAAI,IAAI,CAACL,iBAAA,CAAkBK,IAAI,CAACC,o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":"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
+ {"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,SAyGN,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 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;UAClBL;QACF;QAEA;MAEF,KAAK;QACHE,KAAA,CAAMO,MAAM,CAACC,GAAG,CAAEC,KAAA;UAChB,MAAMC,eAAA,GAAkB,GAAGP,UAAA,IAAcM,KAAA,CAAME,IAAI,EAAE;UAErDb,SAAA,CAAUO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WyB,GAAA,IAAO,KAAKE,YAAA;YACxCrB,gBAAA,EAAkBN,UAAA,CAAWyB,GAAA,IAAOG,aAAA,GAAgBtB,gBAAA;YACpDC;UACF;QACF;QAEA;IACJ;EACF;AACF","ignoreList":[]}
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\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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AC3EU,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,4 +1,11 @@
1
- import type { BuildFormStateArgs, ClientConfig, ClientUser, ErrorResult, FormState } from 'payload';
1
+ import type { I18nClient } from '@payloadcms/translations';
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;
2
9
  type BuildFormStateSuccessResult = {
3
10
  clientConfig?: ClientConfig;
4
11
  errors?: never;
@@ -1 +1 @@
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,C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AAU,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,CAkHrC,CAAA"}
@@ -2,10 +2,45 @@ 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 { getClientConfig } from './getClientConfig.js';
6
- import { getClientSchemaMap } from './getClientSchemaMap.js';
7
- import { getSchemaMap } from './getSchemaMap.js';
5
+ import { buildFieldSchemaMap } from './buildFieldSchemaMap/index.js';
8
6
  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
+ };
9
44
  export const buildFormStateHandler = async args => {
10
45
  const {
11
46
  req
@@ -85,26 +120,14 @@ export const buildFormState = async args => {
85
120
  if (!collectionSlug && !globalSlug) {
86
121
  throw new Error('Either collectionSlug or globalSlug must be provided');
87
122
  }
88
- const schemaMap = getSchemaMap({
123
+ const fieldSchemaMap = getFieldSchemaMap({
89
124
  collectionSlug,
90
125
  config,
91
126
  globalSlug,
92
127
  i18n
93
128
  });
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
- });
106
129
  const id = collectionSlug ? idFromArgs : undefined;
107
- const fieldOrEntityConfig = schemaMap.get(schemaPath);
130
+ const fieldOrEntityConfig = fieldSchemaMap.get(schemaPath);
108
131
  if (!fieldOrEntityConfig) {
109
132
  throw new Error(`Could not find "${schemaPath}" in the fieldSchemaMap`);
110
133
  }
@@ -128,11 +151,10 @@ export const buildFormState = async args => {
128
151
  const fields = Array.isArray(fieldOrEntityConfig) ? fieldOrEntityConfig : 'fields' in fieldOrEntityConfig ? fieldOrEntityConfig.fields : [fieldOrEntityConfig];
129
152
  const formStateResult = await fieldSchemasToFormState({
130
153
  id,
131
- clientFieldSchemaMap: clientSchemaMap,
132
154
  collectionSlug,
133
155
  data,
134
156
  fields,
135
- fieldSchemaMap: schemaMap,
157
+ fieldSchemaMap,
136
158
  operation,
137
159
  permissions: docPermissions?.fields || {},
138
160
  preferences: docPreferences || {
@@ -1 +1 @@
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,QAA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,iBAAA;IACbE,KAAA,EAAOX;EACT;AACF","ignoreList":[]}
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,GAAiBC,MAAA,CAAOC,iBAAiB;AAC7C,IAAIC,kBAAA,GAAqBF,MAAA,CAAOG,qBAAqB;AAErD,IAAI,CAACJ,cAAA,EAAgB;EACnBA,cAAA,GAAiBC,MAAA,CAAOC,iBAAiB,GAAG;AAC9C;AAEA,IAAI,CAACC,kBAAA,EAAoB;EACvBA,kBAAA,GAAqBF,MAAA,CAAOG,qBAAqB,GAAG;AACtD;AAEA,OAAO,MAAMC,iBAAA,GAAqBC,IAAA;EAMhC,MAAM;IAAEC,cAAc;IAAEC,MAAM;IAAEC,UAAU;IAAEC;EAAI,CAAE,GAAGJ,IAAA;EAErD,IAAIK,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;IAC1C,IAAI,CAACb,cAAA,EAAgB;MACnBA,cAAA,GAAiB,IAAIc,GAAA;IACvB;IACA,MAAMC,oBAAA,GAAuBf,cAAA,CAAegB,GAAG,CAACT,cAAA,IAAkBE,UAAA;IAClE,IAAIM,oBAAA,EAAsB;MACxB,OAAOA,oBAAA;IACT;EACF;EAEA,MAAM;IAAEE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AAA,EAAaD,iBAAA;IACbE,KAAA,EAAOT;EACT;AACF","ignoreList":[]}
@@ -1,6 +1,12 @@
1
- import type { BuildTableStateArgs, ClientConfig, ErrorResult, PaginatedDocs } from 'payload';
1
+ import type { I18nClient } from '@payloadcms/translations';
2
+ import type { BuildTableStateArgs, ClientConfig, ErrorResult, ImportMap, PaginatedDocs, SanitizedConfig } from 'payload';
2
3
  import type { Column } from '../elements/Table/index.js';
3
4
  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;
4
10
  type BuildTableStateSuccessResult = {
5
11
  clientConfig?: ClientConfig;
6
12
  data: PaginatedDocs;
@@ -1 +1 @@
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,CA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ACV,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,7 +1,26 @@
1
- import { dequal } from 'dequal'; // TODO: Can we change this to dequal/lite ? If not, please add comment explaining why
2
- import { formatErrors } from 'payload';
3
- import { getClientConfig } from './getClientConfig.js';
1
+ import { dequal } from 'dequal/lite';
2
+ import { createClientConfig, formatErrors } from 'payload';
4
3
  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
+ };
5
24
  export const buildTableStateHandler = async args => {
6
25
  const {
7
26
  req
@@ -112,10 +131,6 @@ export const buildTableState = async args => {
112
131
  });
113
132
  let newPrefs = preferencesResult.value;
114
133
  if (!preferencesResult.id || !dequal(columns, preferencesResult?.columns)) {
115
- const mergedPrefs = {
116
- ...(preferencesResult || {}),
117
- columns
118
- };
119
134
  const preferencesArgs = {
120
135
  collection: 'payload-preferences',
121
136
  data: {
@@ -124,7 +139,10 @@ export const buildTableState = async args => {
124
139
  collection: user.collection,
125
140
  value: user.id
126
141
  },
127
- value: mergedPrefs
142
+ value: {
143
+ ...(preferencesResult?.value || {}),
144
+ columns
145
+ }
128
146
  },
129
147
  depth: 0,
130
148
  req
@@ -1 +1 @@
1
- {"version":3,"file":"buildTableState.js","names":["dequal","formatErrors","getClientConfig","renderFilters","renderTable","buildTableStateHandler","args","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","docs","docsFromArgs","enableRowSelections","query","renderRowTypes","i18n","config","user","tableAppearance","incomingUserSlug","collection","adminUserSlug","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","length","clientConfig","importMap","collectionConfig","clientCollectionConfig","slug","preferencesKey","preferencesResult","where","and","key","equals","id","then","value","newPrefs","mergedPrefs","preferencesArgs","data","update","create","fields","parseInt","undefined","page","sort","columnState","Table","columnPreferences","useAsTitle","renderedFilters","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n ErrorResult,\n PaginatedDocs,\n SanitizedCollectionConfig,\n} from 'payload'\n\nimport { dequal } from 'dequal' // TODO: Can we change this to dequal/lite ? If not, please add comment explaining why\nimport { formatErrors } from 'payload'\n\nimport type { Column } from '../elements/Table/index.js'\nimport type { ListPreferences } from '../elements/TableColumns/index.js'\n\nimport { getClientConfig } from './getClientConfig.js'\nimport { renderFilters, renderTable } from './renderTable.js'\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: ListPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateResult> => {\n const { req } = args\n\n try {\n const res = await buildTableState(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 buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns,\n docs: docsFromArgs,\n enableRowSelections,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n const incomingUserSlug = user?.collection\n\n const adminUserSlug = config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = 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 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 clientConfig = getClientConfig({\n config,\n i18n,\n importMap: payload.importMap,\n })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n\n // get prefs, then set update them using the columns that we just received\n const preferencesKey = `${collectionSlug}-list`\n\n const preferencesResult = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: preferencesKey,\n },\n },\n {\n 'user.relationTo': {\n equals: user.collection,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n ],\n },\n })\n .then((res) => res.docs[0] ?? { id: null, value: {} })\n\n let newPrefs = preferencesResult.value\n\n if (!preferencesResult.id || !dequal(columns, preferencesResult?.columns)) {\n const mergedPrefs = {\n ...(preferencesResult || {}),\n columns,\n }\n const preferencesArgs = {\n collection: 'payload-preferences',\n data: {\n key: preferencesKey,\n user: {\n collection: user.collection,\n value: user.id,\n },\n value: mergedPrefs,\n },\n depth: 0,\n req,\n }\n\n if (preferencesResult.id) {\n newPrefs = await payload\n .update({\n ...preferencesArgs,\n id: preferencesResult.id,\n })\n ?.then((res) => res.value as ListPreferences)\n } else {\n newPrefs = await payload.create(preferencesArgs)?.then((res) => res.value as ListPreferences)\n }\n }\n\n const fields = collectionConfig.fields\n\n let docs = docsFromArgs\n let data: PaginatedDocs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!docs || query) {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: query?.limit ? parseInt(query.limit, 10) : undefined,\n page: query?.page ? parseInt(query.page, 10) : undefined,\n sort: query?.sort,\n where: query?.where,\n })\n\n docs = data.docs\n }\n\n const { columnState, Table } = renderTable({\n collectionConfig: clientCollectionConfig,\n columnPreferences: undefined, // TODO, might not be needed\n columns,\n docs,\n enableRowSelections,\n fields,\n i18n: req.i18n,\n payload,\n renderRowTypes,\n tableAppearance,\n useAsTitle: collectionConfig.admin.useAsTitle,\n })\n\n const renderedFilters = renderFilters(fields, req.payload.importMap)\n\n return {\n data,\n preferences: newPrefs,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AASA,SAASA,MAAM,QAAQ,SAAQ,CAAC;AAChC,SAASC,YAAY,QAAQ;AAK7B,SAASC,eAAe,QAAQ;AAChC,SAASC,aAAa,EAAEC,WAAW,QAAQ;AA0B3C,OAAO,MAAMC,sBAAA,GAAy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,MAAMyB,SAAA;MAClDC,IAAA,EAAM5C,KAAA,EAAO4C,IAAA,GAAOF,QAAA,CAAS1C,KAAA,CAAM4C,IAAI,EAAE,MAAMD,SAAA;MAC/CE,IAAA,EAAM7C,KAAA,EAAO6C,IAAA;MACbjB,KAAA,EAAO5B,KAAA,EAAO4B;IAChB;IAEA/B,IAAA,GAAOyC,IAAA,CAAKzC,IAAI;EAClB;EAEA,MAAM;IAAEiD,WAAW;IAAEC;EAAK,CAAE,GAAGhE,WAAA,CAAY;IACzCwC,gBAAA,EAAkBC,sBAAA;IAClBwB,iBAAA,EAAmBL,SAAA;IACnB/C,OAAA;IACAC,IAAA;IACAE,mBAAA;IACA0C,MAAA;IACAvC,IAAA,EAAMhB,GAAA,CAAIgB,IAAI;IACdZ,OAAA;IACAW,cAAA;IACAI,eAAA;IACA4C,UAAA,EAAY1B,gBAAA,CAAiBd,KAAK,CAACwC;EACrC;EAEA,MAAMC,eAAA,GAAkBpE,aAAA,CAAc2D,MAAA,EAAQvD,GAAA,CAAII,OAAO,CAACgC,SAAS;EAEnE,OAAO;IACLgB,IAAA;IACAa,WAAA,EAAahB,QAAA;IACbe,eAAA;IACAE,KAAA,EAAON,WAAA;IACPC;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"buildTableState.js","names":["dequal","createClientConfig","formatErrors","renderFilters","renderTable","cachedClientConfig","global","_payload_clientConfig","getClientConfig","args","config","i18n","importMap","process","env","NODE_ENV","buildTableStateHandler","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","docs","docsFromArgs","enableRowSelections","query","renderRowTypes","user","tableAppearance","incomingUserSlug","collection","adminUserSlug","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","length","clientConfig","collectionConfig","clientCollectionConfig","slug","preferencesKey","preferencesResult","where","and","key","equals","id","then","value","newPrefs","preferencesArgs","data","update","create","fields","parseInt","undefined","page","sort","columnState","Table","columnPreferences","useAsTitle","renderedFilters","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n ErrorResult,\n ImportMap,\n PaginatedDocs,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { createClientConfig, formatErrors } from 'payload'\n\nimport type { Column } from '../elements/Table/index.js'\nimport type { ListPreferences } from '../elements/TableColumns/index.js'\n\nimport { renderFilters, renderTable } from './renderTable.js'\n\nlet cachedClientConfig = global._payload_clientConfig\n\nif (!cachedClientConfig) {\n cachedClientConfig = global._payload_clientConfig = null\n}\n\nexport const getClientConfig = (args: {\n config: SanitizedConfig\n i18n: I18nClient\n importMap: ImportMap\n}): ClientConfig => {\n const { config, i18n, importMap } = args\n\n if (cachedClientConfig && process.env.NODE_ENV !== 'development') {\n return cachedClientConfig\n }\n\n cachedClientConfig = createClientConfig({\n config,\n i18n,\n importMap,\n })\n\n return cachedClientConfig\n}\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: ListPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateResult> => {\n const { req } = args\n\n try {\n const res = await buildTableState(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 buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns,\n docs: docsFromArgs,\n enableRowSelections,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n const incomingUserSlug = user?.collection\n\n const adminUserSlug = config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = 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 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 clientConfig = getClientConfig({\n config,\n i18n,\n importMap: payload.importMap,\n })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n\n // get prefs, then set update them using the columns that we just received\n const preferencesKey = `${collectionSlug}-list`\n\n const preferencesResult = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: preferencesKey,\n },\n },\n {\n 'user.relationTo': {\n equals: user.collection,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n ],\n },\n })\n .then((res) => res.docs[0] ?? { id: null, value: {} })\n\n let newPrefs = preferencesResult.value\n\n if (!preferencesResult.id || !dequal(columns, preferencesResult?.columns)) {\n const preferencesArgs = {\n collection: 'payload-preferences',\n data: {\n key: preferencesKey,\n user: {\n collection: user.collection,\n value: user.id,\n },\n value: {\n ...(preferencesResult?.value || {}),\n columns,\n },\n },\n depth: 0,\n req,\n }\n\n if (preferencesResult.id) {\n newPrefs = await payload\n .update({\n ...preferencesArgs,\n id: preferencesResult.id,\n })\n ?.then((res) => res.value as ListPreferences)\n } else {\n newPrefs = await payload.create(preferencesArgs)?.then((res) => res.value as ListPreferences)\n }\n }\n\n const fields = collectionConfig.fields\n\n let docs = docsFromArgs\n let data: PaginatedDocs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!docs || query) {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: query?.limit ? parseInt(query.limit, 10) : undefined,\n page: query?.page ? parseInt(query.page, 10) : undefined,\n sort: query?.sort,\n where: query?.where,\n })\n\n docs = data.docs\n }\n\n const { columnState, Table } = renderTable({\n collectionConfig: clientCollectionConfig,\n columnPreferences: undefined, // TODO, might not be needed\n columns,\n docs,\n enableRowSelections,\n fields,\n i18n: req.i18n,\n payload,\n renderRowTypes,\n tableAppearance,\n useAsTitle: collectionConfig.admin.useAsTitle,\n })\n\n const renderedFilters = renderFilters(fields, req.payload.importMap)\n\n return {\n data,\n preferences: newPrefs,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AAYA,SAASA,MAAM,QAAQ;AACvB,SAASC,kBAAkB,EAAEC,YAAY,QAAQ;AAKjD,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAE3C,IAAIC,kBAAA,GAAqBC,MAAA,CAAOC,qBAAqB;AAErD,IAAI,CAACF,kBAAA,EAAoB;EACvBA,kBAAA,GAAqBC,MAAA,CAAOC,qBAAqB,GAAG;AACtD;AAEA,OAAO,MAAMC,eAAA,GAAmBC,IAAA;EAK9B,MAAM;IAAEC,MAAM;IAAEC,IAAI;IAAEC;EAAS,CAAE,GAAGH,IAAA;EAEpC,IAAIJ,kBAAA,IAAsBQ,OAAA,CAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;IAChE,OAAOV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MACxBT,UAAA,EAAYV,cAAA;MACZoB,KAAA,EAAO;MACPC,KAAA,EAAOhB,KAAA,EAAOgB,KAAA,GAAQsB,QAAA,CAAStC,KAAA,CAAMgB,KAAK,EAAE,MAAMuB,SAAA;MAClDC,IAAA,EAAMxC,KAAA,EAAOwC,IAAA,GAAOF,QAAA,CAAStC,KAAA,CAAMwC,IAAI,EAAE,MAAMD,SAAA;MAC/CE,IAAA,EAAMzC,KAAA,EAAOyC,IAAA;MACbhB,KAAA,EAAOzB,KAAA,EAAOyB;IAChB;IAEA5B,IAAA,GAAOqC,IAAA,CAAKrC,IAAI;EAClB;EAEA,MAAM;IAAE6C,WAAW;IAAEC;EAAK,CAAE,GAAGtE,WAAA,CAAY;IACzC+C,gBAAA,EAAkBC,sBAAA;IAClBuB,iBAAA,EAAmBL,SAAA;IACnB3C,OAAA;IACAC,IAAA;IACAE,mBAAA;IACAsC,MAAA;IACAzD,IAAA,EAAMM,GAAA,CAAIN,IAAI;IACdU,OAAA;IACAW,cAAA;IACAE,eAAA;IACA0C,UAAA,EAAYzB,gBAAA,CAAiBb,KAAK,CAACsC;EACrC;EAEA,MAAMC,eAAA,GAAkB1E,aAAA,CAAciE,MAAA,EAAQnD,GAAA,CAAII,OAAO,CAACT,SAAS;EAEnE,OAAO;IACLqD,IAAA;IACAa,WAAA,EAAaf,QAAA;IACbc,eAAA;IACAE,KAAA,EAAON,WAAA;IACPC;EACF;AACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { SanitizedCollectionConfig } from 'payload';
1
+ import type { SanitizedCollectionConfig, VerifyConfig } from 'payload';
2
2
  export type Props = {
3
3
  className?: string;
4
4
  collectionSlug: SanitizedCollectionConfig['slug'];
@@ -12,6 +12,6 @@ export type Props = {
12
12
  setValidateBeforeSubmit: (validate: boolean) => void;
13
13
  useAPIKey?: boolean;
14
14
  username: string;
15
- verify?: boolean;
15
+ verify?: boolean | VerifyConfig;
16
16
  };
17
17
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/views/Edit/Auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAExD,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACjD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAA;IACzE,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC/C,uBAAuB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IACpD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/views/Edit/Auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAEtE,MAAM,MAAM,KAAK,GAAG;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IACjD,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,iBAAiB,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAC,mBAAmB,CAAC,CAAA;IACzE,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,QAAQ,EAAE,OAAO,CAAA;IACjB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IAC/C,uBAAuB,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAA;IACpD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAA;CAChC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Edit/Auth/types.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from 'payload'\n\nexport type Props = {\n className?: string\n collectionSlug: SanitizedCollectionConfig['slug']\n disableLocalStrategy?: boolean\n email: string\n loginWithUsername: SanitizedCollectionConfig['auth']['loginWithUsername']\n operation: 'create' | 'update'\n readOnly: boolean\n requirePassword?: boolean\n setSchemaPathSegments: (path: string[]) => void\n setValidateBeforeSubmit: (validate: boolean) => void\n useAPIKey?: boolean\n username: string\n verify?: boolean\n}\n"],"mappings":"AAEA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../src/views/Edit/Auth/types.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, VerifyConfig } from 'payload'\n\nexport type Props = {\n className?: string\n collectionSlug: SanitizedCollectionConfig['slug']\n disableLocalStrategy?: boolean\n email: string\n loginWithUsername: SanitizedCollectionConfig['auth']['loginWithUsername']\n operation: 'create' | 'update'\n readOnly: boolean\n requirePassword?: boolean\n setSchemaPathSegments: (path: string[]) => void\n setValidateBeforeSubmit: (validate: boolean) => void\n useAPIKey?: boolean\n username: string\n verify?: boolean | VerifyConfig\n}\n"],"mappings":"AAEA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/ui",
3
- "version": "3.1.1-canary.9da0158",
3
+ "version": "3.1.1",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -133,7 +133,7 @@
133
133
  "ts-essentials": "10.0.3",
134
134
  "use-context-selector": "2.0.0",
135
135
  "uuid": "10.0.0",
136
- "@payloadcms/translations": "3.1.1-canary.9da0158"
136
+ "@payloadcms/translations": "3.1.1"
137
137
  },
138
138
  "devDependencies": {
139
139
  "@babel/cli": "^7.24.5",
@@ -151,14 +151,14 @@
151
151
  "esbuild": "0.23.1",
152
152
  "esbuild-sass-plugin": "3.3.1",
153
153
  "eslint-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
154
- "payload": "3.1.1-canary.9da0158",
155
- "@payloadcms/eslint-config": "3.0.0"
154
+ "@payloadcms/eslint-config": "3.0.0",
155
+ "payload": "3.1.1"
156
156
  },
157
157
  "peerDependencies": {
158
158
  "next": "^15.0.0",
159
159
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
160
160
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
161
- "payload": "3.1.1-canary.9da0158"
161
+ "payload": "3.1.1"
162
162
  },
163
163
  "engines": {
164
164
  "node": "^18.20.2 || >=20.9.0"
@@ -1,16 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,70 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}
@@ -1,15 +0,0 @@
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
@@ -1 +0,0 @@
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"}